fanforce-workers 0.1.0 → 0.2.0.pre
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/iron.rb +4 -2
- data/lib/fanforce/workers/version.rb +1 -1
- data/lib/fanforce/workers/worker.rb +25 -16
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NWJlMDE5ZmJjMDEyMGEzZjcwMWQ0OWEyMmVhMTQzYWI0NTVlNWFiNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NzgxMDY0YzU0ODIxOTYzYjNiYTgwMjFlNzNmYzBlNTliOTAzZDViNA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YWQ2MDY2OWIxMjUxODMwNjQ1ZGEzODc5N2Q3ZWRhODE1YThlYzk2ZTI4MTc3
|
10
|
+
ZjAxZGU0NjMyN2JlNzI1Y2I1NzNlMDViYjIxMzI0YjA1YzFhZDY4NzQwMTZh
|
11
|
+
MTZlYjhhMGMzOWE1ZWY2M2MzNTQ1YWJmYjQzN2RiOTU5YmYxY2E=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NzRiZjlkZjhhZDVlNWNjMGYwNTZmMzU3NzUzNTk1NGM3ZWMwNDBhNDdlOTdj
|
14
|
+
YmYyNDU5NDk2OWM5YzBhODM2ODViZmJjZDAzZWVjYjVlMjMyZjNmMTIxMmM2
|
15
|
+
MWYxMTA2YmNhZmJkYWE1NTczOTBlMDllNjExODgwMzEyYTU3YTU=
|
@@ -5,8 +5,10 @@ class Fanforce::Workers::Iron
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def queue(queue_id, payload)
|
8
|
-
|
9
|
-
|
8
|
+
raise 'Payload being sent to the queue must be a Hash' if !payload.is_a?(Hash)
|
9
|
+
payload = {params: payload, retries: 0}
|
10
|
+
|
11
|
+
@iron_mq.queue(queue_id).post(payload.to_json)
|
10
12
|
end
|
11
13
|
|
12
14
|
end
|
@@ -1,19 +1,18 @@
|
|
1
1
|
class Fanforce::Worker
|
2
2
|
|
3
|
-
def self.run(
|
4
|
-
self.new(
|
3
|
+
def self.run(worker_data, &code_block)
|
4
|
+
self.new(worker_data, &code_block)
|
5
5
|
end
|
6
6
|
|
7
|
-
def initialize(
|
7
|
+
def initialize(worker_data, &code_block)
|
8
8
|
require_dependencies
|
9
9
|
run_validations
|
10
10
|
|
11
|
-
@
|
12
|
-
@
|
11
|
+
@worker_data = worker_data
|
12
|
+
@code_block = code_block
|
13
13
|
|
14
|
-
msg = iron_mq.queue(
|
15
|
-
|
16
|
-
(msg.nil?) ? (return) : run_worker(msg, 0)
|
14
|
+
msg = iron_mq.queue(worker_data['worker_id']).get(timeout: 3600)
|
15
|
+
(msg.nil?) ? (return) : run_worker(msg)
|
17
16
|
end
|
18
17
|
|
19
18
|
|
@@ -31,17 +30,27 @@ class Fanforce::Worker
|
|
31
30
|
@iron_mq ||= IronMQ::Client.new
|
32
31
|
end
|
33
32
|
|
34
|
-
def run_worker(msg
|
35
|
-
|
36
|
-
|
33
|
+
def run_worker(msg)
|
34
|
+
task_data = Fanforce.decode_json(msg.body)
|
35
|
+
puts task_data
|
36
|
+
|
37
|
+
set_env_vars(@worker_data['env_vars'])
|
38
|
+
|
39
|
+
@code_block.call(task_data[:params].clone, task_data[:retries].clone)
|
37
40
|
msg.delete
|
38
41
|
rescue => e
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
42
|
+
task_data[:last_error] = {
|
43
|
+
exception: e.class.name,
|
44
|
+
message: e.message,
|
45
|
+
backtrace: e.backtrace,
|
46
|
+
raised_at: Time.now
|
47
|
+
}
|
48
|
+
Fanforce::Workers.iron.queue "#{@worker_data['worker_id']}-ERRORS", task_data
|
44
49
|
msg.delete
|
45
50
|
end
|
46
51
|
|
52
|
+
def set_env_vars(vars)
|
53
|
+
vars.each {|k,v| ENV[k.to_s]=v }
|
54
|
+
end
|
55
|
+
|
47
56
|
end
|
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.
|
4
|
+
version: 0.2.0.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Caleb Clark
|
@@ -83,9 +83,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
83
83
|
version: '0'
|
84
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
|
-
- - ! '
|
86
|
+
- - ! '>'
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version:
|
88
|
+
version: 1.3.1
|
89
89
|
requirements: []
|
90
90
|
rubyforge_project:
|
91
91
|
rubygems_version: 2.0.3
|