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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZDMxM2ZhNzU4NjJkNjE5OTNhOGE5OTU0MDlkYjUzYmYxNDJmNWZhZg==
4
+ NWJlMDE5ZmJjMDEyMGEzZjcwMWQ0OWEyMmVhMTQzYWI0NTVlNWFiNA==
5
5
  data.tar.gz: !binary |-
6
- OGFmNzJkMzEwNzA4ZjBjNDY2NWVhNDA3OTE0NDE1NjI0ZTM4ZjlmNw==
6
+ NzgxMDY0YzU0ODIxOTYzYjNiYTgwMjFlNzNmYzBlNTliOTAzZDViNA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MDYwZjg3MjMyNThjMmU0YTgyNmMxMTI2NmQ4OWZiZTdmZWNmZmZlY2E2NWEy
10
- MjE1OWU4YWEyOTc5YmFkZjQwOGE5NDdlMzgyNGRkYTAzZGQ2YTliMGZhYWY0
11
- MzZmNjk3NmYzNzQwOGEwYTNjNGUzYTM1NjEyMmYyOWRiZWIxOTc=
9
+ YWQ2MDY2OWIxMjUxODMwNjQ1ZGEzODc5N2Q3ZWRhODE1YThlYzk2ZTI4MTc3
10
+ ZjAxZGU0NjMyN2JlNzI1Y2I1NzNlMDViYjIxMzI0YjA1YzFhZDY4NzQwMTZh
11
+ MTZlYjhhMGMzOWE1ZWY2M2MzNTQ1YWJmYjQzN2RiOTU5YmYxY2E=
12
12
  data.tar.gz: !binary |-
13
- ZDU2MGNlMmFiNjQ5NjlkY2RiZTVhNTBjNGE1MTA4NDY4ZDYyZjNkYTUzOWIz
14
- MjJhZTlmNDVmMmVhN2JiY2RkZTNmODk1NDAxMTNjMjY4MjY1MjE5OTZmNjI3
15
- MmRkM2FmYmY3NTU1OTEyYmU5MDhjNTM2NTUxYTcyYTE2MTkzNTI=
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
- payload = (payload.is_a?(Hash) or payload.is_a?(Array)) ? payload.to_json : payload.to_s
9
- @iron_mq.queue(queue_id).post(payload)
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,5 +1,5 @@
1
1
  class Fanforce
2
2
  module Workers
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.0.pre'
4
4
  end
5
5
  end
@@ -1,19 +1,18 @@
1
1
  class Fanforce::Worker
2
2
 
3
- def self.run(init_params, &worker_code)
4
- self.new(init_params, &worker_code)
3
+ def self.run(worker_data, &code_block)
4
+ self.new(worker_data, &code_block)
5
5
  end
6
6
 
7
- def initialize(init_params, &worker_code)
7
+ def initialize(worker_data, &code_block)
8
8
  require_dependencies
9
9
  run_validations
10
10
 
11
- @init_params = init_params
12
- @worker_code = worker_code
11
+ @worker_data = worker_data
12
+ @code_block = code_block
13
13
 
14
- msg = iron_mq.queue(init_params['worker_id']).get #(timeout: 3600)
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, retries)
35
- params = Fanforce.decode_json(msg.body)
36
- @worker_code.call(params, retries)
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
- params = params.is_a?(Hash) ? {original_params: params} : {original_body: msg.body}
40
- params[:retries] = retries + 1
41
- params[:error_message] = e.message
42
- params[:error_backtrace] = e.backtrace
43
- Fanforce::Workers.iron.queue "#{@init_params['worker_id']}-ERRORS", params
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.1.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: '0'
88
+ version: 1.3.1
89
89
  requirements: []
90
90
  rubyforge_project:
91
91
  rubygems_version: 2.0.3