fanforce-plugin-worker 2.0.0.rc1 → 2.0.0.rc3
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 987bf4bde24044a417b786303f3969d7ae4508ba
|
4
|
+
data.tar.gz: 8124501188c1155ce897f87e8c71597a8e50568f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 582d3c4caab6618f49de0c88c0d06d3c8cb9b3101e66954928587e2f04d7cd5bca6c68f483666d59f116b350d8ec94d89d494e7c930ed5055ec3e41904ce8b35
|
7
|
+
data.tar.gz: f3cd3fe5510750077f41fcbb9c34986b7aac1c8febd5d32ee36d96e2e7599633072a017b00799186626dc42610ac136066f9c05bb9e68988e81a259f519f33ee
|
@@ -32,6 +32,7 @@ class Fanforce::PluginWorker::Runner
|
|
32
32
|
log.debug '------------------------------------------------------------------------------------'
|
33
33
|
job_num = 0
|
34
34
|
job_data = nil
|
35
|
+
|
35
36
|
while job_has_enough_time_to_run and (job = Fanforce::PluginWorker.iron_mq.queue(iron_queue_id(@queue_id)).get(timeout: 3600)) do
|
36
37
|
log.debug "- JOB #{job_num+=1}: #{job.body}"
|
37
38
|
timeout(worker_time_remaining, Timeout) do
|
@@ -98,9 +99,6 @@ class Fanforce::PluginWorker::Runner
|
|
98
99
|
end
|
99
100
|
|
100
101
|
def job_has_enough_time_to_run
|
101
|
-
time_since_load = Time.now - Fanforce::PluginWorker::LOADED_AT
|
102
|
-
return false if time_since_load > MAX_EXECUTION_TIME
|
103
|
-
return false if worker_time_remaining < @min_execution_time
|
104
102
|
return true
|
105
103
|
end
|
106
104
|
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'fanforce/api'
|
2
|
+
|
3
|
+
class Fanforce::PluginWorker::RunnerLocal
|
4
|
+
include Fanforce::PluginWorker::Utils
|
5
|
+
|
6
|
+
MAX_EXECUTION_TIME = 3300
|
7
|
+
class Timeout < RuntimeError; end
|
8
|
+
|
9
|
+
def initialize(worker_data, min_execution_time=300, &code_block)
|
10
|
+
raise "min_execution_time was set to #{min_execution_time}, which is #{min_execution_time - MAX_EXECUTION_TIME} seconds too long" if min_execution_time > MAX_EXECUTION_TIME
|
11
|
+
log.debug '------------------------------------------------------------------------------------'
|
12
|
+
log.debug 'LOADING WORKER ENV'
|
13
|
+
ENV.each {|k,v| log.debug "#{k} = #{v}" }
|
14
|
+
|
15
|
+
worker_data = worker_data.symbolize_keys
|
16
|
+
@queue_id = worker_data[:queue_id] || (raise 'worker_data must contain queue_id')
|
17
|
+
@current_params = MultiJson.load(worker_data[:params].to_json, symbolize_keys: true)
|
18
|
+
@current_retries = 0
|
19
|
+
|
20
|
+
run_job(&code_block)
|
21
|
+
end
|
22
|
+
|
23
|
+
def run_job(&code_block)
|
24
|
+
log.debug '------------------------------------------------------------------------------------'
|
25
|
+
log.debug 'PROCESSING JOB...'
|
26
|
+
log.debug '------------------------------------------------------------------------------------'
|
27
|
+
|
28
|
+
code_block.call(@current_params.clone, retries: @current_retries, queue_id: @queue_id)
|
29
|
+
|
30
|
+
log.debug 'WINDING DOWN WORKER!'
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -40,13 +40,31 @@ class Fanforce::PluginWorker
|
|
40
40
|
def self.enqueue(queue_id, params, options={})
|
41
41
|
raise 'Params being sent to the queue must be a Hash' if !params.is_a?(Hash)
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
if ENV['FANFORCE_WORKER_SHOULD_BYPASS_ENQUEUE']
|
44
|
+
bypass_enqueue(queue_id, params)
|
45
|
+
else
|
46
|
+
queue_id = Utils.iron_queue_id(queue_id)
|
47
|
+
retries = (options[:retries].present?) ? options.delete(:retries) : 0
|
48
|
+
iron_mq.queue(queue_id).post({params: params, retries: retries}.to_json, options)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.bypass_enqueue(queue_id, params)
|
53
|
+
config_file = "#{Plugin.base_dir}/workers/#{queue_id}.worker"
|
54
|
+
exec_file = "#{Plugin.base_dir}/workers/#{queue_id}.rb"
|
55
|
+
raise "Config file is missing: #{config_file}" if !File.exists?(config_file)
|
56
|
+
raise "Ruby file is missing: #{exec_file}" if !File.exists?(exec_file)
|
57
|
+
raise "RACK_ENV must be development: #{ENV['RACK_ENV']}" if ENV['RACK_ENV'] != 'development'
|
58
|
+
params = {queue_id: queue_id, params: params}
|
59
|
+
binding.eval(File.open(exec_file).read, exec_file)
|
46
60
|
end
|
47
61
|
|
48
62
|
def self.run(worker_data, min_execution_time=300, &code_block)
|
49
|
-
|
63
|
+
if ENV['FANFORCE_WORKER_SHOULD_BYPASS_ENQUEUE']
|
64
|
+
RunnerLocal.new(worker_data, min_execution_time, &code_block)
|
65
|
+
else
|
66
|
+
Runner.new(worker_data, min_execution_time, &code_block)
|
67
|
+
end
|
50
68
|
end
|
51
69
|
|
52
70
|
end
|
@@ -7,6 +7,7 @@ require_relative 'plugin_worker/utils'
|
|
7
7
|
require_relative 'plugin_worker/worker'
|
8
8
|
require_relative 'plugin_worker/errors'
|
9
9
|
require_relative 'plugin_worker/runner'
|
10
|
+
require_relative 'plugin_worker/runner_local' if ENV['RACK_ENV'] == 'development'
|
10
11
|
|
11
12
|
########################################################################################################################
|
12
13
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fanforce-plugin-worker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.
|
4
|
+
version: 2.0.0.rc3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Caleb Clark
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: iron_mq
|
@@ -140,6 +140,7 @@ files:
|
|
140
140
|
- lib/fanforce/plugin_worker.rb
|
141
141
|
- lib/fanforce/plugin_worker/errors.rb
|
142
142
|
- lib/fanforce/plugin_worker/runner.rb
|
143
|
+
- lib/fanforce/plugin_worker/runner_local.rb
|
143
144
|
- lib/fanforce/plugin_worker/utils.rb
|
144
145
|
- lib/fanforce/plugin_worker/version.rb
|
145
146
|
- lib/fanforce/plugin_worker/worker.rb
|