rocketjob 4.3.0.beta2 → 5.0.0.beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/rocketjob +2 -10
- data/lib/rocket_job/batch/worker.rb +1 -1
- data/lib/rocket_job/cli.rb +14 -33
- data/lib/rocket_job/config.rb +71 -34
- data/lib/rocket_job/plugins/job/throttle.rb +2 -2
- data/lib/rocket_job/plugins/job/worker.rb +0 -12
- data/lib/rocket_job/railtie.rb +36 -0
- data/lib/rocket_job/server/model.rb +4 -16
- data/lib/rocket_job/supervisor.rb +5 -5
- data/lib/rocket_job/version.rb +1 -1
- data/lib/rocket_job/worker.rb +13 -19
- data/lib/rocket_job/worker_pool.rb +4 -5
- data/lib/rocketjob.rb +2 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3574aea0102c28eece0aefa25631e57d6458e5e7fb1191e464e6e1f885d83128
|
4
|
+
data.tar.gz: 7909db1e628d5460c8500d269a9d3af7fe5a15b685065869a4b93a0919db1b63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22da70f046dea52843f8f3b7b215ab541eb1242db629cb2833a37d9d2afd0743334935824f48cf03ab50c2952f17b84d3fe80134ad3173c5487457dbea22c4ea
|
7
|
+
data.tar.gz: '045886026776a1273844b1184ac0e1ce09b681dbce377029869cceab914d23755eea956bda79bf2794f1d4b3b74ef79859d529bd175a5cef717cfa33902c0a32'
|
data/bin/rocketjob
CHANGED
@@ -4,13 +4,5 @@ require 'semantic_logger'
|
|
4
4
|
require 'rocket_job/cli'
|
5
5
|
|
6
6
|
# Start a rocketjob server instance from the command line
|
7
|
-
|
8
|
-
|
9
|
-
rescue Exception => exc
|
10
|
-
return if exc.class == SystemExit
|
11
|
-
# Failsafe logger that writes to STDERR
|
12
|
-
SemanticLogger.add_appender(io: STDERR, level: :error, formatter: :color)
|
13
|
-
SemanticLogger['RocketJob'].error('Rocket Job shutting down due to exception', exc)
|
14
|
-
SemanticLogger.flush
|
15
|
-
exit 1
|
16
|
-
end
|
7
|
+
# Allow Ruby to catch and display any startup exceptions
|
8
|
+
RocketJob::CLI.new(ARGV).run
|
data/lib/rocket_job/cli.rb
CHANGED
@@ -8,13 +8,10 @@ module RocketJob
|
|
8
8
|
# Command Line Interface parser for Rocket Job
|
9
9
|
class CLI
|
10
10
|
include SemanticLogger::Loggable
|
11
|
-
attr_accessor :
|
12
|
-
:log_level, :log_file, :mongo_config, :symmetric_encryption_config
|
13
|
-
:include_filter, :exclude_filter, :where_filter
|
11
|
+
attr_accessor :environment, :pidfile, :directory, :quiet,
|
12
|
+
:log_level, :log_file, :mongo_config, :symmetric_encryption_config
|
14
13
|
|
15
14
|
def initialize(argv)
|
16
|
-
@name = nil
|
17
|
-
@workers = nil
|
18
15
|
@quiet = false
|
19
16
|
@environment = nil
|
20
17
|
@pidfile = nil
|
@@ -40,14 +37,7 @@ module RocketJob
|
|
40
37
|
# In case Rails did not load the Mongoid Config
|
41
38
|
RocketJob::Config.load!(environment, mongo_config, symmetric_encryption_config) if ::Mongoid::Config.clients.empty?
|
42
39
|
|
43
|
-
|
44
|
-
|
45
|
-
opts = {}
|
46
|
-
opts[:name] = name if name
|
47
|
-
opts[:max_workers] = workers if workers
|
48
|
-
opts[:filter] = filter if filter
|
49
|
-
|
50
|
-
Supervisor.run(opts)
|
40
|
+
Supervisor.run
|
51
41
|
end
|
52
42
|
|
53
43
|
def rails?
|
@@ -63,6 +53,8 @@ module RocketJob
|
|
63
53
|
logger.info "Loading Rails environment: #{environment}"
|
64
54
|
RocketJob.rails!
|
65
55
|
|
56
|
+
require 'rails'
|
57
|
+
require 'rocket_job/railtie'
|
66
58
|
boot_file = Pathname.new(directory).join('config/environment.rb').expand_path
|
67
59
|
require(boot_file.to_s)
|
68
60
|
|
@@ -153,38 +145,27 @@ module RocketJob
|
|
153
145
|
end
|
154
146
|
end
|
155
147
|
|
156
|
-
# Returns [Hash] a where clause filter to apply to this server.
|
157
|
-
# Returns nil if no filter should be applied
|
158
|
-
def build_filter
|
159
|
-
raise(ArgumentError, 'Cannot supply both a filter and an exclusion filter') if include_filter && exclude_filter
|
160
|
-
|
161
|
-
filter = where_filter
|
162
|
-
(filter ||= {})['_type'] = include_filter if include_filter
|
163
|
-
(filter ||= {})['_type'] = {'$not' => exclude_filter} if exclude_filter
|
164
|
-
filter
|
165
|
-
end
|
166
|
-
|
167
148
|
# Parse command line options placing results in the corresponding instance variables
|
168
149
|
def parse(argv)
|
169
150
|
parser = OptionParser.new do |o|
|
170
151
|
o.on('-n', '--name NAME', 'Unique Name of this server (Default: host_name:PID)') do |arg|
|
171
|
-
|
152
|
+
Config.name = arg
|
172
153
|
end
|
173
154
|
o.on('-w', '--workers COUNT', 'Number of workers (threads) to start') do |arg|
|
174
|
-
|
155
|
+
Config.max_workers = arg.to_i
|
175
156
|
end
|
176
|
-
o.on('
|
177
|
-
|
178
|
-
@workers = arg.to_i
|
157
|
+
o.on('--include REGEXP', 'Limit this server to only those job classes that match this regular expression (case-insensitive). Example: "DirmonJob|WeeklyReportJob"') do |arg|
|
158
|
+
Config.include_filter = Regexp.new(arg, true)
|
179
159
|
end
|
180
|
-
o.on('-F', '--filter REGEXP', '
|
181
|
-
|
160
|
+
o.on('-F', '--filter REGEXP', 'DEPRECATED. Use --include') do |arg|
|
161
|
+
warn '-F and --filter are deprecated, use --include'
|
162
|
+
Config.include_filter = Regexp.new(arg, true)
|
182
163
|
end
|
183
164
|
o.on('-E', '--exclude REGEXP', 'Prevent this server from working on any job classes that match this regular expression (case-insensitive). Example: "DirmonJob|WeeklyReportJob"') do |arg|
|
184
|
-
|
165
|
+
Config.exclude_filter = Regexp.new(arg, true)
|
185
166
|
end
|
186
167
|
o.on('-W', '--where JSON', "Limit this server instance to the supplied mongo query filter. Supply as a string in JSON format. Example: '{\"priority\":{\"$lte\":25}}'") do |arg|
|
187
|
-
|
168
|
+
Config.where_filter = JSON.parse(arg)
|
188
169
|
end
|
189
170
|
o.on('-q', '--quiet', 'Do not write to stdout, only to logfile. Necessary when running as a daemon') do
|
190
171
|
@quiet = true
|
data/lib/rocket_job/config.rb
CHANGED
@@ -1,52 +1,75 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
module RocketJob
|
3
|
-
#
|
3
|
+
# Rocket Job Configuration
|
4
4
|
class Config
|
5
|
-
include
|
6
|
-
|
7
|
-
# Returns the single instance of the Rocket Job Configuration for this site
|
8
|
-
# in a thread-safe way
|
9
|
-
def self.instance
|
10
|
-
@instance ||= begin
|
11
|
-
first || create
|
12
|
-
rescue StandardError
|
13
|
-
# In case another process has already created the first document
|
14
|
-
first
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
# DEPRECATED
|
19
|
-
cattr_accessor(:inline_mode) { false }
|
5
|
+
include SemanticLogger::Loggable
|
20
6
|
|
21
|
-
|
7
|
+
# [String] This Rocket Job Server name
|
8
|
+
class_attribute :server_name
|
9
|
+
self.server_name = "#{SemanticLogger.host}:#{$$}"
|
22
10
|
|
23
|
-
#
|
24
|
-
|
25
|
-
|
11
|
+
# [Integer] The maximum number of workers to create on any one server
|
12
|
+
class_attribute :max_workers
|
13
|
+
self.max_workers = 10
|
26
14
|
|
27
|
-
#
|
28
|
-
|
15
|
+
# [Integer] Number of seconds between heartbeats from a Rocket Job Server process
|
16
|
+
class_attribute :heartbeat_seconds
|
17
|
+
self.heartbeat_seconds = 15.0
|
29
18
|
|
30
|
-
#
|
31
|
-
|
19
|
+
# [Integer] Maximum number of seconds a Worker will wait before checking for new jobs
|
20
|
+
class_attribute :max_poll_seconds
|
21
|
+
self.max_poll_seconds = 5.0
|
32
22
|
|
33
|
-
#
|
34
|
-
# Workers
|
35
|
-
#
|
36
|
-
|
37
|
-
# Maximum number of seconds a Worker will wait before checking for new jobs
|
38
|
-
field :max_poll_seconds, type: Integer, default: 5
|
39
|
-
|
40
|
-
# Number of seconds between checking for:
|
23
|
+
# [Integer] Number of seconds between checking for:
|
41
24
|
# - Jobs with a higher priority
|
42
25
|
# - If the current job has been paused, or aborted
|
43
26
|
#
|
44
27
|
# Making this interval too short results in too many checks for job status
|
45
28
|
# changes instead of focusing on completing the active tasks
|
46
29
|
#
|
30
|
+
# Notes:
|
31
|
+
# - Not all job types support pausing in the middle
|
32
|
+
#
|
33
|
+
# Default: 60 seconds between checks.
|
34
|
+
class_attribute :re_check_seconds
|
35
|
+
self.re_check_seconds = 60.0
|
36
|
+
|
37
|
+
# [Regexp] Limit this server to only those job classes that match this regular expression.
|
38
|
+
#
|
47
39
|
# Note:
|
48
|
-
#
|
49
|
-
|
40
|
+
# - Supply a case insensitive Regexp if required.
|
41
|
+
# - Only supply include_filter or exclude_filter, not both.
|
42
|
+
#
|
43
|
+
# Example:
|
44
|
+
# # This server can only work on jobs that include anywhere
|
45
|
+
# # in their names: `DirmonJob` or `WeeklyReportJob`
|
46
|
+
# RocketJob::Config.include_filter = /DirmonJob|WeeklyReportJob/i
|
47
|
+
class_attribute :include_filter
|
48
|
+
self.include_filter = nil
|
49
|
+
|
50
|
+
# [Regexp] Prevent this server from working on any job classes that match this regular expression.
|
51
|
+
#
|
52
|
+
# Notes:
|
53
|
+
# - Supply a case insensitive Regexp if required.
|
54
|
+
# - Only supply include_filter or exclude_filter, not both.
|
55
|
+
#
|
56
|
+
# Example:
|
57
|
+
# # This server can only work any job except that that include anywhere
|
58
|
+
# # in their names: `DirmonJob` or `WeeklyReportJob`
|
59
|
+
# RocketJob::Config.exclude_filter = /DirmonJob|WeeklyReportJob/i
|
60
|
+
class_attribute :exclude_filter
|
61
|
+
self.exclude_filter = nil
|
62
|
+
|
63
|
+
# [Hash] Limit this server instance to the supplied mongo query filter.
|
64
|
+
#
|
65
|
+
# Notes:
|
66
|
+
# - Can be supplied together with `include_filter` or `exclude_filter` above.
|
67
|
+
#
|
68
|
+
# Example:
|
69
|
+
# # This server can only work on jobs with priorities between 1 and 25
|
70
|
+
# RocketJob::Config.where_filter = { "priority" => {"$lte" => 25}}
|
71
|
+
class_attribute :where_filter
|
72
|
+
self.where_filter = nil
|
50
73
|
|
51
74
|
# Configure Mongoid
|
52
75
|
def self.load!(environment = 'development', file_name = nil, encryption_file_name = nil)
|
@@ -72,5 +95,19 @@ module RocketJob
|
|
72
95
|
logger.debug "Reading SymmetricEncryption configuration from: #{config_file}"
|
73
96
|
SymmetricEncryption.load!(config_file.to_s, environment)
|
74
97
|
end
|
98
|
+
|
99
|
+
# Returns [Hash] the where clause built from the filters above:
|
100
|
+
# include_filter, exclude_filter, and where_filter.
|
101
|
+
# Returns nil if no filter should be applied.
|
102
|
+
def self.filter
|
103
|
+
if include_filter && exclude_filter
|
104
|
+
raise(ArgumentError, 'Cannot supply both an include_filter and an exclude_filter')
|
105
|
+
end
|
106
|
+
|
107
|
+
filter = where_filter
|
108
|
+
(filter ||= {})['_type'] = include_filter if include_filter
|
109
|
+
(filter ||= {})['_type'] = {'$not' => exclude_filter} if exclude_filter
|
110
|
+
filter
|
111
|
+
end
|
75
112
|
end
|
76
113
|
end
|
@@ -70,14 +70,14 @@ module RocketJob
|
|
70
70
|
|
71
71
|
# Default throttle to use when the throttle is exceeded.
|
72
72
|
# When the throttle has been exceeded all jobs of this class will be ignored until the
|
73
|
-
# next refresh. `RocketJob::Config
|
73
|
+
# next refresh. `RocketJob::Config.re_check_seconds` which by default is 60 seconds.
|
74
74
|
def throttle_filter_class
|
75
75
|
{:_type.nin => [self.class.name]}
|
76
76
|
end
|
77
77
|
|
78
78
|
# Filter out only this instance of the job.
|
79
79
|
# When the throttle has been exceeded this job will be ignored by this server until the next refresh.
|
80
|
-
# `RocketJob::Config
|
80
|
+
# `RocketJob::Config.re_check_seconds` which by default is 60 seconds.
|
81
81
|
def throttle_filter_id
|
82
82
|
{:id.nin => [id]}
|
83
83
|
end
|
@@ -66,18 +66,6 @@ module RocketJob
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
-
# DEPRECATED
|
70
|
-
def perform_later(args, &block)
|
71
|
-
if RocketJob::Config.inline_mode
|
72
|
-
perform_now(args, &block)
|
73
|
-
else
|
74
|
-
job = new(args)
|
75
|
-
yield(job) if block
|
76
|
-
job.save!
|
77
|
-
job
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
69
|
private
|
82
70
|
|
83
71
|
def rocket_job_merge_filter(target, source)
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module RocketJob
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
# Exposes Rocket Job's configuration to the Rails application configuration.
|
4
|
+
#
|
5
|
+
# @example Set up configuration in the Rails app.
|
6
|
+
# module MyApplication
|
7
|
+
# class Application < Rails::Application
|
8
|
+
# # The maximum number of workers to create on any one server. (Default: 10)
|
9
|
+
# config.rocket_job.max_workers = config.secret_config.fetch("rocket_job/max_workers", type: :integer, default: 10)
|
10
|
+
#
|
11
|
+
# # Number of seconds between heartbeats from a Rocket Job Server process. (Default: 15)
|
12
|
+
# config.rocket_job.heartbeat_seconds = config.secret_config.fetch("rocket_job/heartbeat_seconds", type: :float, default: 15.0)
|
13
|
+
#
|
14
|
+
# # Maximum number of seconds a Worker will wait before checking for new jobs. (Default: 5)
|
15
|
+
# config.rocket_job.max_poll_seconds = config.secret_config.fetch("rocket_job/max_poll_seconds", type: :float, default: 5.0)
|
16
|
+
#
|
17
|
+
# # Number of seconds between checking for:
|
18
|
+
# # - Jobs with a higher priority
|
19
|
+
# # - If the current job has been paused, or aborted
|
20
|
+
# #
|
21
|
+
# # Making this interval too short results in too many checks for job status
|
22
|
+
# # changes instead of focusing on completing the active tasks
|
23
|
+
# #
|
24
|
+
# # Note:
|
25
|
+
# # Not all job types support pausing in the middle
|
26
|
+
# # Default: 60 seconds between checks.
|
27
|
+
# config.rocket_job.re_check_seconds = config.secret_config.fetch("rocket_job/re_check_seconds", type: :float, default: 60.0)
|
28
|
+
#
|
29
|
+
# config.rocket_job.include_filter = config.secret_config["rocket_job/include_filter"]
|
30
|
+
# config.rocket_job.exclude_filter = config.secret_config["rocket_job/exclude_filter"]
|
31
|
+
# config.rocket_job.where_filter = config.secret_config["rocket_job/where_filter"]
|
32
|
+
# end
|
33
|
+
# end
|
34
|
+
config.rocket_job = Config
|
35
|
+
end
|
36
|
+
end
|
@@ -14,18 +14,15 @@ module RocketJob
|
|
14
14
|
# Default: `host name:PID`
|
15
15
|
# The unique name is used on re-start to re-queue any jobs that were being processed
|
16
16
|
# at the time the server unexpectedly terminated, if any
|
17
|
-
field :name, type: String, default: -> {
|
17
|
+
field :name, type: String, default: -> { Config.server_name }
|
18
18
|
|
19
19
|
# The maximum number of workers this server should start
|
20
20
|
# If set, it will override the default value in RocketJob::Config
|
21
|
-
field :max_workers, type: Integer, default: -> { Config.
|
21
|
+
field :max_workers, type: Integer, default: -> { Config.max_workers }
|
22
22
|
|
23
23
|
# When this server process was started
|
24
24
|
field :started_at, type: Time
|
25
25
|
|
26
|
-
# Filter to apply to control which job classes this server can process
|
27
|
-
field :yaml_filter, type: String
|
28
|
-
|
29
26
|
# The heartbeat information for this server
|
30
27
|
embeds_one :heartbeat, class_name: 'RocketJob::Heartbeat'
|
31
28
|
|
@@ -82,7 +79,7 @@ module RocketJob
|
|
82
79
|
|
83
80
|
# Scope for all zombie servers
|
84
81
|
def self.zombies(missed = 4)
|
85
|
-
dead_seconds = Config.
|
82
|
+
dead_seconds = Config.heartbeat_seconds * missed
|
86
83
|
last_heartbeat_time = Time.now - dead_seconds
|
87
84
|
where(
|
88
85
|
:state.in => %i[stopping running paused],
|
@@ -94,15 +91,6 @@ module RocketJob
|
|
94
91
|
end
|
95
92
|
end
|
96
93
|
|
97
|
-
# Where clause filter to apply to workers looking for jobs
|
98
|
-
def filter
|
99
|
-
YAML.load(yaml_filter) if yaml_filter
|
100
|
-
end
|
101
|
-
|
102
|
-
def filter=(hash)
|
103
|
-
self.yaml_filter = hash.nil? ? nil : hash.to_yaml
|
104
|
-
end
|
105
|
-
|
106
94
|
# Returns [true|false] if this server has missed at least the last 4 heartbeats
|
107
95
|
#
|
108
96
|
# Possible causes for a server to miss its heartbeats:
|
@@ -112,7 +100,7 @@ module RocketJob
|
|
112
100
|
def zombie?(missed = 4)
|
113
101
|
return false unless running? || stopping? || paused?
|
114
102
|
return true if heartbeat.nil? || heartbeat.updated_at.nil?
|
115
|
-
dead_seconds = Config.
|
103
|
+
dead_seconds = Config.heartbeat_seconds * missed
|
116
104
|
(Time.now - heartbeat.updated_at) >= dead_seconds
|
117
105
|
end
|
118
106
|
|
@@ -10,12 +10,12 @@ module RocketJob
|
|
10
10
|
attr_accessor :worker_id
|
11
11
|
|
12
12
|
# Start the Supervisor, using the supplied attributes to create a new Server instance.
|
13
|
-
def self.run
|
13
|
+
def self.run
|
14
14
|
Thread.current.name = 'rocketjob main'
|
15
15
|
RocketJob.create_indexes
|
16
16
|
register_signal_handlers
|
17
17
|
|
18
|
-
server = Server.create!
|
18
|
+
server = Server.create!
|
19
19
|
new(server).run
|
20
20
|
ensure
|
21
21
|
server&.destroy
|
@@ -23,13 +23,13 @@ module RocketJob
|
|
23
23
|
|
24
24
|
def initialize(server)
|
25
25
|
@server = server
|
26
|
-
@worker_pool = WorkerPool.new(server.name
|
26
|
+
@worker_pool = WorkerPool.new(server.name)
|
27
27
|
@mutex = Mutex.new
|
28
28
|
end
|
29
29
|
|
30
30
|
def run
|
31
31
|
logger.info "Using MongoDB Database: #{RocketJob::Job.collection.database.name}"
|
32
|
-
logger.info('Running with filter',
|
32
|
+
logger.info('Running with filter', Config.filter) if Config.filter
|
33
33
|
server.started!
|
34
34
|
logger.info 'Rocket Job Server started'
|
35
35
|
|
@@ -81,7 +81,7 @@ module RocketJob
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
-
self.class.wait_for_event(Config.
|
84
|
+
self.class.wait_for_event(Config.heartbeat_seconds)
|
85
85
|
|
86
86
|
break if self.class.shutdown?
|
87
87
|
|
data/lib/rocket_job/version.rb
CHANGED
data/lib/rocket_job/worker.rb
CHANGED
@@ -11,7 +11,7 @@ module RocketJob
|
|
11
11
|
|
12
12
|
define_callbacks :running
|
13
13
|
|
14
|
-
attr_accessor :id, :
|
14
|
+
attr_accessor :id, :current_filter
|
15
15
|
attr_reader :thread, :name, :inline
|
16
16
|
|
17
17
|
# Raised when a worker is killed so that it shutdown immediately, yet cleanly.
|
@@ -33,21 +33,15 @@ module RocketJob
|
|
33
33
|
set_callback(:running, :around, *filters, &blk)
|
34
34
|
end
|
35
35
|
|
36
|
-
def initialize(id: 0,
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
@
|
42
|
-
@
|
43
|
-
@
|
44
|
-
@
|
45
|
-
@re_check_seconds = (re_check_seconds || 60).to_f
|
46
|
-
@re_check_start = Time.now
|
47
|
-
@filter = filter.nil? ? {} : filter.dup
|
48
|
-
@current_filter = @filter.dup
|
49
|
-
@thread = Thread.new { run } unless inline
|
50
|
-
@inline = inline
|
36
|
+
def initialize(id: 0, server_name: 'inline:0', inline: false)
|
37
|
+
@id = id
|
38
|
+
@server_name = server_name
|
39
|
+
@shutdown = Concurrent::Event.new
|
40
|
+
@name = "#{server_name}:#{id}"
|
41
|
+
@re_check_start = Time.now
|
42
|
+
@current_filter = Config.filter || {}
|
43
|
+
@thread = Thread.new { run } unless inline
|
44
|
+
@inline = inline
|
51
45
|
end
|
52
46
|
|
53
47
|
def alive?
|
@@ -93,7 +87,7 @@ module RocketJob
|
|
93
87
|
Thread.current.name = format('rocketjob %03i', id)
|
94
88
|
logger.info 'Started'
|
95
89
|
until shutdown?
|
96
|
-
wait =
|
90
|
+
wait = Config.max_poll_seconds
|
97
91
|
if process_available_jobs
|
98
92
|
# Keeps workers staggered across the poll interval so that
|
99
93
|
# all workers don't poll at the same time
|
@@ -131,10 +125,10 @@ module RocketJob
|
|
131
125
|
def reset_filter_if_expired
|
132
126
|
# Only clear out the current_filter after every `re_check_seconds`
|
133
127
|
time = Time.now
|
134
|
-
return unless (time - @re_check_start) > re_check_seconds
|
128
|
+
return unless (time - @re_check_start) > Config.re_check_seconds
|
135
129
|
|
136
130
|
@re_check_start = time
|
137
|
-
self.current_filter =
|
131
|
+
self.current_filter = Config.filter
|
138
132
|
end
|
139
133
|
end
|
140
134
|
end
|
@@ -5,11 +5,10 @@ module RocketJob
|
|
5
5
|
class WorkerPool
|
6
6
|
include SemanticLogger::Loggable
|
7
7
|
|
8
|
-
attr_reader :server_name, :
|
8
|
+
attr_reader :server_name, :workers
|
9
9
|
|
10
|
-
def initialize(server_name
|
10
|
+
def initialize(server_name)
|
11
11
|
@server_name = server_name
|
12
|
-
@filter = filter
|
13
12
|
@workers = Concurrent::Array.new
|
14
13
|
@worker_id = 0
|
15
14
|
end
|
@@ -34,7 +33,7 @@ module RocketJob
|
|
34
33
|
|
35
34
|
add_one
|
36
35
|
count -= 1
|
37
|
-
delay = Config.
|
36
|
+
delay = Config.max_poll_seconds.to_f / max_workers
|
38
37
|
|
39
38
|
count.times.each do
|
40
39
|
sleep(delay) if stagger_start
|
@@ -90,7 +89,7 @@ module RocketJob
|
|
90
89
|
private
|
91
90
|
|
92
91
|
def add_one
|
93
|
-
workers << Worker.new(id: next_worker_id, server_name: server_name
|
92
|
+
workers << Worker.new(id: next_worker_id, server_name: server_name)
|
94
93
|
rescue StandardError => exc
|
95
94
|
logger.fatal('Cannot start worker', exc)
|
96
95
|
end
|
data/lib/rocketjob.rb
CHANGED
@@ -4,6 +4,8 @@ require 'mongoid'
|
|
4
4
|
require 'rocket_job/extensions/mongo/logging'
|
5
5
|
require 'rocket_job/version'
|
6
6
|
require 'rocket_job/rocket_job'
|
7
|
+
require 'rocket_job/config'
|
8
|
+
require 'rocket_job/railtie' if defined?(Rails)
|
7
9
|
|
8
10
|
# Apply patches to implement `with_collection`
|
9
11
|
if Mongoid::VERSION.to_i >= 6
|
@@ -21,7 +23,6 @@ module RocketJob
|
|
21
23
|
autoload :ActiveWorker, 'rocket_job/active_worker'
|
22
24
|
autoload :Batch, 'rocket_job/batch'
|
23
25
|
autoload :CLI, 'rocket_job/cli'
|
24
|
-
autoload :Config, 'rocket_job/config'
|
25
26
|
autoload :DirmonEntry, 'rocket_job/dirmon_entry'
|
26
27
|
autoload :Event, 'rocket_job/event'
|
27
28
|
autoload :Heartbeat, 'rocket_job/heartbeat'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rocketjob
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.0.0.beta
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Reid Morrison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10-
|
11
|
+
date: 2019-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aasm
|
@@ -155,6 +155,7 @@ files:
|
|
155
155
|
- lib/rocket_job/plugins/singleton.rb
|
156
156
|
- lib/rocket_job/plugins/state_machine.rb
|
157
157
|
- lib/rocket_job/plugins/transaction.rb
|
158
|
+
- lib/rocket_job/railtie.rb
|
158
159
|
- lib/rocket_job/rocket_job.rb
|
159
160
|
- lib/rocket_job/server.rb
|
160
161
|
- lib/rocket_job/server/model.rb
|