fanforce-workers 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/fanforce/workers/version.rb +1 -1
- data/lib/fanforce/workers/workers.rb +53 -19
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MzE2YjI1YjljN2E4ZGQ0ZDA1YTY4ODlmZjZkNjMzZDM0MzQ3ODE2Mw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZjFmZTc3ZmIyMjM5YjM2MWIxNjg0ZjIyMTliNGQzNjg1YzdmMzI5ZQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NGE1MjA5YTg3Yjg2N2E4MTk2YTE5ZTgzM2JkMWMyMGJlYmIxMTc1MzA4ODI5
|
10
|
+
NjM5NmRlMWZhZTI1ZWI5M2QyNjU0ZWE4MTExNjg3MTBhMThhN2IzNGUxZDgy
|
11
|
+
NDMzYTM3MjJkM2NiNzhhM2U2YjM3NGUwNTNkZDYyMjVlYzMxZTE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZmQxNGQyYmZmOTJiODM5ZjVhMzBkZDJlNDczZDQzNjEyOWZiYWI4OTk4ZTYz
|
14
|
+
ODM3NTk2ZjJlYmY5MWFjYmM1M2EzOGI5YWU0YTljNDhhODRhM2IzNGI1M2Jh
|
15
|
+
YjI2YTVlMzhiMmZkZWEwN2JmYjM2NDcwY2RmY2NkODc1NmIxMzk=
|
@@ -14,9 +14,10 @@ class Fanforce::Workers
|
|
14
14
|
@iron_cache ||= IronCache::Client.new(:token => @opts[:token] || ENV['IRON_TOKEN'], :project_id => @opts[:project_id] || ENV['IRON_PROJECT_ID'])
|
15
15
|
end
|
16
16
|
|
17
|
-
def enqueue(queue_id, params,
|
17
|
+
def enqueue(queue_id, params, options={})
|
18
|
+
retries = (options[:retries].present?) ? options.delete(:retries) : 0
|
18
19
|
raise 'Params being sent to the queue must be a Hash' if !params.is_a?(Hash)
|
19
|
-
iron_mq.queue(queue_id).post({params: params, retries: retries}.to_json)
|
20
|
+
iron_mq.queue(queue_id).post({params: params, retries: retries}.to_json, options)
|
20
21
|
end
|
21
22
|
|
22
23
|
def add_error(queue_id, error)
|
@@ -35,8 +36,8 @@ class Fanforce::Workers
|
|
35
36
|
}.to_json)
|
36
37
|
end
|
37
38
|
|
38
|
-
def delete_error(queue_id,
|
39
|
-
iron_mq.queue("#{queue_id}-ERRORS").delete(
|
39
|
+
def delete_error(queue_id, job_id, details_id)
|
40
|
+
iron_mq.queue("#{queue_id}-ERRORS").delete(job_id)
|
40
41
|
iron_cache.cache("#{queue_id}-ERRORS").delete(details_id)
|
41
42
|
end
|
42
43
|
|
@@ -45,12 +46,12 @@ class Fanforce::Workers
|
|
45
46
|
MultiJson.load(cache.value, :symbolize_keys => true)
|
46
47
|
end
|
47
48
|
|
48
|
-
def retry_error(queue_id,
|
49
|
+
def retry_error(queue_id, job_id, details_id)
|
49
50
|
cache = iron_cache.cache("#{queue_id}-ERRORS").get(details_id)
|
50
51
|
cache_data = MultiJson.load(cache.value, :symbolize_keys => true)
|
51
|
-
enqueue(queue_id, cache_data[:params], cache_data[:retries] + 1)
|
52
|
+
enqueue(queue_id, cache_data[:params], :retries => cache_data[:retries] + 1)
|
52
53
|
|
53
|
-
cache.delete and iron_mq.queue("#{queue_id}-ERRORS").delete(
|
54
|
+
cache.delete and iron_mq.queue("#{queue_id}-ERRORS").delete(job_id)
|
54
55
|
end
|
55
56
|
|
56
57
|
def truncate(text, length=130, truncate_string="...")
|
@@ -63,8 +64,8 @@ class Fanforce::Workers
|
|
63
64
|
|
64
65
|
##########################################################################################
|
65
66
|
|
66
|
-
def self.enqueue(queue_id,
|
67
|
-
self.new.enqueue(queue_id,
|
67
|
+
def self.enqueue(queue_id, params, options={})
|
68
|
+
self.new.enqueue(queue_id, params, options)
|
68
69
|
end
|
69
70
|
|
70
71
|
def self.add_error(queue_id, error)
|
@@ -73,6 +74,30 @@ class Fanforce::Workers
|
|
73
74
|
|
74
75
|
##########################################################################################
|
75
76
|
|
77
|
+
def self.current_queue_id=(queue_id)
|
78
|
+
@current_queue_id = queue_id
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.current_queue_id
|
82
|
+
@current_queue_id
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.current_params=(params)
|
86
|
+
@current_params = params
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.current_params
|
90
|
+
@current_params
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.current_retries=(retries)
|
94
|
+
@current_retries = retries
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.current_retries
|
98
|
+
@current_retries
|
99
|
+
end
|
100
|
+
|
76
101
|
def self.run(worker_data, &code_block)
|
77
102
|
require '.pluginenv'
|
78
103
|
require 'iron_mq'
|
@@ -80,27 +105,36 @@ class Fanforce::Workers
|
|
80
105
|
require 'fanforce/api'
|
81
106
|
require 'active_support/all'
|
82
107
|
|
83
|
-
|
84
|
-
|
108
|
+
current_queue_id = worker_data['queue_id']
|
109
|
+
queue = IronMQ::Client.new.queue(current_queue_id)
|
110
|
+
|
85
111
|
job_num = 0
|
112
|
+
puts 'PROCESSING...'
|
86
113
|
while (job = queue.get(timeout: 3600)) do
|
87
114
|
puts "JOB #{job_num+=1}: #{job.body}"
|
88
|
-
|
115
|
+
run_job job, worker_data, &code_block
|
89
116
|
end
|
90
117
|
puts 'DONE'
|
91
118
|
end
|
92
119
|
|
93
|
-
def self.
|
120
|
+
def self.retry(options)
|
121
|
+
self.new.enqueue(current_queue_id, current_params, options.merge(retries: current_retries + 1))
|
122
|
+
end
|
123
|
+
|
124
|
+
def self.run_job(job, worker_data, &code_block)
|
94
125
|
puts '----------------------------------------------------------'
|
95
126
|
print 'PROCESSING MESSAGE: '
|
96
|
-
|
127
|
+
|
128
|
+
task_data = Fanforce.decode_json(current_job_body)
|
129
|
+
current_params = task_data[:params]
|
130
|
+
current_retries = task_data[:retries]
|
97
131
|
|
98
132
|
set_env_vars(worker_data['env_vars'])
|
99
|
-
code_block.call(task_data[:params].clone, task_data[:retries], worker_data['
|
100
|
-
|
133
|
+
code_block.call(task_data[:params].clone, task_data[:retries], worker_data['queue_id'])
|
134
|
+
job.delete
|
101
135
|
|
102
136
|
rescue Exception => e
|
103
|
-
if
|
137
|
+
if job.nil?
|
104
138
|
puts 'MESSAGE IS NIL'
|
105
139
|
return
|
106
140
|
end
|
@@ -114,10 +148,10 @@ class Fanforce::Workers
|
|
114
148
|
error[:curl_command] = e.curl_command if e.respond_to?(:curl_command)
|
115
149
|
|
116
150
|
puts "ADDING TO ERROR CACHE: #{error.to_json}"
|
117
|
-
|
151
|
+
job.delete
|
118
152
|
puts 'DELETED MESSAGE'
|
119
153
|
|
120
|
-
self.add_error worker_data['
|
154
|
+
self.add_error worker_data['queue_id'], error
|
121
155
|
end
|
122
156
|
|
123
157
|
def self.set_env_vars(vars)
|