fanforce-workers 0.7.4 → 0.7.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MGFjN2Q1NTkwMjZmMDRiYjFlMmMyYmY1YmI5MzQwMjM2ODg4MGVmZg==
4
+ ZTJkNTljODQ3MzYzY2ZlNGJlODQzZGQ4NmU3MWI0YmNlMGM2MWIyMw==
5
5
  data.tar.gz: !binary |-
6
- ZDNiMmI3MjIwNDY0NzJmZWQxODNhYTdkOGNmYTRiNTMwOTkzMTE3ZA==
6
+ ZWRlMGFiMjQ4MDBhMjVlYTUzMWIyM2UyYjE3MjliZWIzYTI4ZTk2ZA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NTgzZjhjYTdlYzU5YzQwZTBjMmEwYjljODA0MDQ1YjQwYTM3MGNiNWE5MDc0
10
- ZjExNDUxMmRkNDU4MzM1ZjhlM2EwMmQyZDcwY2IyZDcwZTkxMjJmY2E5ZTAx
11
- MDc2YmQ4MzYzYzRjN2JiZWM2OGMxOTRiMGMyN2IxYTE2MWNhYjg=
9
+ MzY1ZjlkOTE3YzRjYWE1MzY3MDc0ODc1MGNhY2ZiMjUyYTQ0MjJmNTMxMDg3
10
+ Y2ZkYTQ3OGQyNGMyODA5MWJjY2NmNTIyODc0MDI0MmFkYjQ5ZDRjZjg5MzQ4
11
+ ZTM4OWZjNzM1NDE4MGQ1MDkwN2U4MTIxZjMzNWRjYzZlMGMyMzE=
12
12
  data.tar.gz: !binary |-
13
- NmY2ZGI1MmExNzc0ZWE1NjM1OWEzNTM1YzgwZGEwYzk1ZTg5MDI5MGZkOWY0
14
- MjMzMWEyNzRhYTU0NjVmNDdhM2NjMTUxNGVlODI5YzU0MWZhODdkYjEzYzUx
15
- MjVhYzk2OGQ3N2I0MDRhNGJjYmQwZjIzMGIxZGI4Yjg2YTY3N2U=
13
+ NTY5YmNiZTI4ZTdiYTlhM2Q1YjYwNzY0MWY0MzYxNWM1MjBlYzAxNzg2MWY4
14
+ MjliZWU4MDg1NDVhYThhNzJkZmM1OWM2NjFiNDRkNThjZDkxMjAyZDMxYjQw
15
+ MmU4MGM1ZThjYTNhNGNiYmU2ZjQ4NDJmNThhOTllYTM3NzQ3NjM=
@@ -1,5 +1,5 @@
1
1
  class Fanforce
2
2
  class Workers
3
- VERSION = '0.7.4'
3
+ VERSION = '0.7.5'
4
4
  end
5
5
  end
@@ -82,6 +82,14 @@ class Fanforce::Workers
82
82
  @current_queue_id
83
83
  end
84
84
 
85
+ def self.current_worker_env=(env_vars)
86
+ @current_worker_env = env_vars
87
+ end
88
+
89
+ def self.current_worker_env
90
+ @current_worker_env
91
+ end
92
+
85
93
  def self.current_params=(params)
86
94
  @current_params = params
87
95
  end
@@ -105,14 +113,15 @@ class Fanforce::Workers
105
113
  require 'fanforce/api'
106
114
  require 'active_support/all'
107
115
 
108
- current_queue_id = worker_data['queue_id']
116
+ self.current_queue_id = worker_data['queue_id']
117
+ self.current_worker_env = worker_data['env_vars']
109
118
  queue = IronMQ::Client.new.queue(current_queue_id)
110
119
 
111
120
  job_num = 0
112
121
  puts 'PROCESSING...'
113
122
  while (job = queue.get(timeout: 3600)) do
114
123
  puts "JOB #{job_num+=1}: #{job.body}"
115
- run_job job, worker_data, &code_block
124
+ run_job job, &code_block
116
125
  end
117
126
  puts 'DONE'
118
127
  end
@@ -121,16 +130,16 @@ class Fanforce::Workers
121
130
  self.new.enqueue(current_queue_id, current_params, options.merge(retries: current_retries + 1))
122
131
  end
123
132
 
124
- def self.run_job(job, worker_data, &code_block)
133
+ def self.run_job(job, &code_block)
125
134
  puts '----------------------------------------------------------'
126
135
  print 'PROCESSING MESSAGE: '
127
136
 
128
137
  task_data = Fanforce.decode_json(job.body)
129
- current_params = task_data[:params]
130
- current_retries = task_data[:retries]
138
+ self.current_params = task_data[:params]
139
+ self.current_retries = task_data[:retries]
131
140
 
132
- set_env_vars(worker_data['env_vars'])
133
- code_block.call(task_data[:params].clone, task_data[:retries], worker_data['queue_id'])
141
+ set_env_vars(current_worker_env)
142
+ code_block.call(task_data[:params].clone, retries: task_data[:retries], queue_id: current_queue_id)
134
143
  job.delete
135
144
 
136
145
  rescue Exception => e
@@ -143,7 +152,7 @@ class Fanforce::Workers
143
152
  message: e.message,
144
153
  backtrace: e.backtrace,
145
154
  errored_at: Time.now,
146
- env_vars: worker_data['env_vars']
155
+ env_vars: current_worker_env
147
156
  )
148
157
  error[:curl_command] = e.curl_command if e.respond_to?(:curl_command)
149
158
 
@@ -151,7 +160,7 @@ class Fanforce::Workers
151
160
  job.delete
152
161
  puts 'DELETED MESSAGE'
153
162
 
154
- self.add_error worker_data['queue_id'], error
163
+ self.add_error current_queue_id, error
155
164
  end
156
165
 
157
166
  def self.set_env_vars(vars)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fanforce-workers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
4
+ version: 0.7.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Caleb Clark