fanforce-workers 0.4.7 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +1 -1
- data/fanforce-workers.gemspec +2 -2
- data/lib/fanforce/workers.rb +1 -1
- data/lib/fanforce/workers/iron.rb +2 -0
- data/lib/fanforce/workers/version.rb +1 -1
- data/lib/fanforce/workers/workers.rb +59 -10
- metadata +12 -13
- data/lib/fanforce/workers/worker.rb +0 -65
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NGY5NDAwMDQxNWJkNzk4Y2MzZTk5ZjdiNzM2MzZlMGFlMGZkMGI4MQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OTIyMDgwM2UzNWM5YjdkMjUwMWNlMzRkZTBkYWYyZmU5YWUxNGM3YQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OWQ2OGMwYWY1NTQ1ZGE1ZWU1YWQ1NGVjNmJhNjVkZGQwZmMxZjhmNjNiNmIw
|
10
|
+
M2I1MzVhZmMwNjE4N2Q2OGQ4ODI2Yjg5YTY1ZWU0NDRhZmMwNzkxYzMzZTk2
|
11
|
+
NDE4NjdlYWU3MzYzYTQ5MDY2NDYwNmQ4NWJiODY4ODVlMGYzYTI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MWFiZDI2YTI5NWExYmRlOTJkZjcwNTMyNDk5NWE2MGNkYTVkYmY1ZTY1NWRj
|
14
|
+
Y2YxNjU2MDZmM2ZhMGEyNDNkYjUxZmU3ZmI4YTllMjE3ZDlmMmUxMDM2MTBk
|
15
|
+
MDJhMjkzOTdlNjdhMWMyZjExMjk3ODI5M2QxM2VhYWEzZDVjMGQ=
|
data/README.md
CHANGED
data/fanforce-workers.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |gem|
|
|
7
7
|
gem.name = 'fanforce-workers'
|
8
8
|
gem.version = Fanforce::Workers::VERSION
|
9
9
|
gem.date = '2012-10-19'
|
10
|
-
gem.summary = %q{Fanforce workers
|
10
|
+
gem.summary = %q{Fanforce workers used by various Fanforce addons for background processing.}
|
11
11
|
gem.authors = ['Caleb Clark']
|
12
12
|
gem.email = ['cclark@fanforce.com']
|
13
13
|
gem.homepage = 'http://github.com/fanforce/fanforce-workers'
|
@@ -17,6 +17,6 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.require_paths = ['lib']
|
18
18
|
|
19
19
|
gem.add_runtime_dependency 'iron_mq', '~> 4'
|
20
|
-
gem.add_runtime_dependency 'fanforce-api', '~> 0.9'
|
21
20
|
gem.add_runtime_dependency 'typhoeus'
|
21
|
+
gem.add_runtime_dependency 'fanforce-api', '~> 0.9'
|
22
22
|
end
|
data/lib/fanforce/workers.rb
CHANGED
@@ -1,24 +1,14 @@
|
|
1
|
-
require 'iron_mq'
|
2
|
-
|
3
1
|
class Fanforce::Workers
|
4
2
|
|
5
3
|
def initialize(opts={})
|
6
4
|
@opts = opts
|
7
5
|
end
|
8
6
|
|
9
|
-
def self.add_error(queue_id, payload)
|
10
|
-
self.new.iron.enqueue("#{queue_id}-ERRORS", payload)
|
11
|
-
end
|
12
|
-
|
13
7
|
def iron
|
14
8
|
require_relative 'iron'
|
15
9
|
@iron ||= Fanforce::Workers::Iron.new(@opts)
|
16
10
|
end
|
17
11
|
|
18
|
-
def self.enqueue(queue_id, payload)
|
19
|
-
self.new.enqueue(queue_id, payload)
|
20
|
-
end
|
21
|
-
|
22
12
|
def enqueue(queue_id, payload)
|
23
13
|
raise 'Payload being sent to the queue must be a Hash' if !payload.is_a?(Hash)
|
24
14
|
iron.enqueue queue_id, params: payload, retries: 0
|
@@ -31,4 +21,63 @@ class Fanforce::Workers
|
|
31
21
|
msg.delete
|
32
22
|
end
|
33
23
|
|
24
|
+
##########################################################################################
|
25
|
+
|
26
|
+
def self.add_error(queue_id, payload)
|
27
|
+
self.new.iron.enqueue("#{queue_id}-ERRORS", payload)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.enqueue(queue_id, payload)
|
31
|
+
self.new.enqueue(queue_id, payload)
|
32
|
+
end
|
33
|
+
|
34
|
+
##########################################################################################
|
35
|
+
|
36
|
+
def self.run(worker_data, &code_block)
|
37
|
+
require '.pluginenv'
|
38
|
+
require 'iron_mq'
|
39
|
+
require 'fanforce/api'
|
40
|
+
|
41
|
+
run_validations
|
42
|
+
run_worker IronMQ::Client.new.queue(worker_data['worker_id']).get(timeout: 3600), worker_data, &code_block
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.run_validations
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
def run_worker(msg, worker_data, &code_block)
|
50
|
+
puts '----------------------------------------------------------'
|
51
|
+
print 'PROCESSING MESSAGE: '
|
52
|
+
task_data = Fanforce.decode_json(msg.body)
|
53
|
+
|
54
|
+
set_env_vars(worker_data['env_vars'])
|
55
|
+
code_block.call(task_data[:params].clone, task_data[:retries])
|
56
|
+
msg.delete
|
57
|
+
|
58
|
+
rescue Exception => e
|
59
|
+
if msg.nil?
|
60
|
+
puts 'MESSAGE IS NIL'
|
61
|
+
return
|
62
|
+
end
|
63
|
+
task_data[:last_error] = {
|
64
|
+
exception: e.class.name,
|
65
|
+
message: e.message,
|
66
|
+
backtrace: e.backtrace,
|
67
|
+
raised_at: Time.now
|
68
|
+
}
|
69
|
+
task_data[:last_error][:curl_command] = e.curl_command if e.respond_to?(:curl_command)
|
70
|
+
task_data[:env_vars] = worker_data['env_vars']
|
71
|
+
|
72
|
+
puts "ADDING TO ERROR QUEUE: #{task_data.to_json}"
|
73
|
+
self.add_error worker_data['worker_id'], task_data
|
74
|
+
msg.delete
|
75
|
+
puts 'DELETED MESSAGE'
|
76
|
+
end
|
77
|
+
|
78
|
+
def set_env_vars(vars)
|
79
|
+
vars.each {|k,v| ENV[k.to_s]=v }
|
80
|
+
load 'fanforce/api/ff_globals.rb'
|
81
|
+
end
|
82
|
+
|
34
83
|
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.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Caleb Clark
|
@@ -25,33 +25,33 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '4'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: typhoeus
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ! '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0
|
33
|
+
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ! '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: fanforce-api
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
47
|
+
version: '0.9'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
54
|
+
version: '0.9'
|
55
55
|
description:
|
56
56
|
email:
|
57
57
|
- cclark@fanforce.com
|
@@ -67,7 +67,6 @@ files:
|
|
67
67
|
- lib/fanforce/workers.rb
|
68
68
|
- lib/fanforce/workers/iron.rb
|
69
69
|
- lib/fanforce/workers/version.rb
|
70
|
-
- lib/fanforce/workers/worker.rb
|
71
70
|
- lib/fanforce/workers/workers.rb
|
72
71
|
homepage: http://github.com/fanforce/fanforce-workers
|
73
72
|
licenses: []
|
@@ -91,5 +90,5 @@ rubyforge_project:
|
|
91
90
|
rubygems_version: 2.0.3
|
92
91
|
signing_key:
|
93
92
|
specification_version: 4
|
94
|
-
summary: Fanforce workers
|
93
|
+
summary: Fanforce workers used by various Fanforce addons for background processing.
|
95
94
|
test_files: []
|
@@ -1,65 +0,0 @@
|
|
1
|
-
class Fanforce::Worker
|
2
|
-
|
3
|
-
def self.run(worker_data, &code_block)
|
4
|
-
self.new(worker_data, &code_block)
|
5
|
-
end
|
6
|
-
|
7
|
-
def initialize(worker_data, &code_block)
|
8
|
-
require_dependencies
|
9
|
-
run_validations
|
10
|
-
|
11
|
-
@worker_data = worker_data
|
12
|
-
@code_block = code_block
|
13
|
-
|
14
|
-
run_worker iron_mq.queue(worker_data['worker_id']).get(timeout: 3600)
|
15
|
-
end
|
16
|
-
|
17
|
-
def require_dependencies
|
18
|
-
require '.pluginenv'
|
19
|
-
require 'iron_mq'
|
20
|
-
require 'fanforce/api'
|
21
|
-
end
|
22
|
-
|
23
|
-
def run_validations
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
def iron_mq
|
28
|
-
@iron_mq ||= IronMQ::Client.new
|
29
|
-
end
|
30
|
-
|
31
|
-
def run_worker(msg)
|
32
|
-
puts '----------------------------------------------------------'
|
33
|
-
print 'PROCESSING MESSAGE: '
|
34
|
-
task_data = Fanforce.decode_json(msg.body)
|
35
|
-
|
36
|
-
set_env_vars(@worker_data['env_vars'])
|
37
|
-
@code_block.call(task_data[:params].clone, task_data[:retries])
|
38
|
-
msg.delete
|
39
|
-
|
40
|
-
rescue Exception => e
|
41
|
-
if msg.nil?
|
42
|
-
puts 'MESSAGE IS NIL'
|
43
|
-
return
|
44
|
-
end
|
45
|
-
task_data[:last_error] = {
|
46
|
-
exception: e.class.name,
|
47
|
-
message: e.message,
|
48
|
-
backtrace: e.backtrace,
|
49
|
-
raised_at: Time.now
|
50
|
-
}
|
51
|
-
task_data[:last_error][:curl_command] = e.curl_command if e.respond_to?(:curl_command)
|
52
|
-
task_data[:env_vars] = @worker_data['env_vars']
|
53
|
-
|
54
|
-
puts "ADDING TO ERROR QUEUE: #{task_data.to_json}"
|
55
|
-
Fanforce::Workers.add_error @worker_data['worker_id'], task_data
|
56
|
-
msg.delete
|
57
|
-
puts 'DELETED MESSAGE'
|
58
|
-
end
|
59
|
-
|
60
|
-
def set_env_vars(vars)
|
61
|
-
vars.each {|k,v| ENV[k.to_s]=v }
|
62
|
-
load 'fanforce/api/ff_globals.rb'
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|