daily pastebin goal
25%
SHARE
TWEET

Untitled

a guest Sep 14th, 2018 52 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
  1. import mercadoenvios.*
  2. import groovy.time.*
  3. import groovyx.gpars.GParsPool
  4. import java.util.concurrent.atomic.AtomicInteger
  5. import com.google.common.util.concurrent.RateLimiter
  6.  
  7.  
  8. restClient = ctx.restClient
  9.  
  10. def itemService = ctx.getBean('itemService')
  11. def addressesService = ctx.getBean('addressesService')
  12. def path = "/tmp/buyEqualShip/oferta/mla/users/"
  13.  
  14. def users = [93649727]
  15. //def users = new File(path+"18k_originales.csv").readLines()
  16.  
  17. logFile = new File(path+'result_file.log'); logFile.write('')
  18. log = { text -> logFile << text + "\n" }
  19.  
  20. errorFile = new File(path+'error_file.log'); errorFile.write('')
  21. logError = { text -> errorFile << text + "\n" }
  22.  
  23. logMonitorFile = new File(path+'monitor.log'); logMonitorFile.write('')
  24. logMonitor = { text -> logMonitorFile << text + "\n" }
  25.  
  26. def itemAttributes = [
  27.     'status'
  28. ]
  29.  
  30. def getItems(def id) {
  31.     def result
  32.     restClient.get(
  33.       uri : ("/internal/users/${id}/items/count?status=active,paused&caller.id=${id}").toString(),
  34.         success : {
  35.             result = it.data
  36.         },
  37.         failure : {
  38.             println it.dump()
  39.             if (it.exception){
  40.                 errorLog "${id}"
  41.             }
  42.         }
  43.     )
  44.     return result
  45. }
  46.  
  47. def getPreference(def user, def restClient) {
  48.     def uri = "/users/${user}/shipping_preferences?caller.scopes=admin".toString()
  49.     def data
  50.     try {
  51.         restClient.get(
  52.                 uri:uri,
  53.                 success: {
  54.                     data = it.data
  55.                 },
  56.                 failure: {
  57.                     data = null
  58.                 }
  59.         )      
  60.     }
  61.     catch(Exception e) {
  62.  
  63.     }
  64.     return data
  65. }
  66.  
  67. RateLimiter rateLimiter = RateLimiter.create(50.0d) // 50 x seg o 3k RPM
  68.  
  69. GParsPool.withPool(10) {
  70.     log "userId,dsaStatus,latitude,longitude,option,mandatoryStatus,lls"
  71.     users.eachParallel {user ->
  72.         try {
  73.             logMonitor "${user}"
  74.             def pref = getPreference(user, restClient)
  75.             def dsa = addressesService.getAddressDataByUser(user)
  76.             def isNextToMe2orMandatory = pref?.mandatory_settings?.activation_date != null
  77.             def option = pref?.option
  78.  
  79.             rateLimiter.acquire()
  80.             def r = getItems(user)
  81.            
  82.             if (dsa && dsa.normalized){
  83.                 if (isNextToMe2orMandatory) {
  84.                     log "${user},has_dsa,${dsa.latitude},${dsa.longitude},${option},mandatory,${r.total}"
  85.                 }
  86.                 else {
  87.                     log "${user},has_dsa,${dsa.latitude},${dsa.longitude},${option},not_mandatory,${r.total}"
  88.                 }
  89.             } else {
  90.                 if (isNextToMe2orMandatory) {
  91.                     log "${user},no_dsa,no_atitude,no_longitude,${option},mandatory,${r.total}"
  92.                 }
  93.                 else {
  94.                     log "${user},no_dsa,no_atitude,no_longitude,${option},not_mandatory,${r.total}"
  95.                 }
  96.             }
  97.         } catch (Exception e) {
  98.             logError "${e}"
  99.         }      
  100.     }
  101. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top