rocketjob 3.4.3 → 3.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +27 -0
- data/bin/rocketjob +1 -1
- data/lib/rocket_job/active_worker.rb +4 -3
- data/lib/rocket_job/cli.rb +13 -12
- data/lib/rocket_job/config.rb +17 -13
- data/lib/rocket_job/dirmon_entry.rb +88 -91
- data/lib/rocket_job/extensions/mongo/logging.rb +8 -4
- data/lib/rocket_job/extensions/mongoid/factory.rb +8 -6
- data/lib/rocket_job/extensions/rocket_job_adapter.rb +2 -4
- data/lib/rocket_job/heartbeat.rb +7 -8
- data/lib/rocket_job/job_exception.rb +6 -5
- data/lib/rocket_job/jobs/dirmon_job.rb +5 -7
- data/lib/rocket_job/jobs/housekeeping_job.rb +3 -2
- data/lib/rocket_job/jobs/on_demand_job.rb +104 -0
- data/lib/rocket_job/jobs/simple_job.rb +0 -2
- data/lib/rocket_job/jobs/upload_file_job.rb +100 -0
- data/lib/rocket_job/performance.rb +15 -10
- data/lib/rocket_job/plugins/cron.rb +7 -124
- data/lib/rocket_job/plugins/document.rb +8 -10
- data/lib/rocket_job/plugins/job/callbacks.rb +0 -1
- data/lib/rocket_job/plugins/job/logger.rb +0 -1
- data/lib/rocket_job/plugins/job/model.rb +15 -20
- data/lib/rocket_job/plugins/job/persistence.rb +3 -13
- data/lib/rocket_job/plugins/job/state_machine.rb +1 -2
- data/lib/rocket_job/plugins/job/throttle.rb +16 -12
- data/lib/rocket_job/plugins/job/worker.rb +15 -19
- data/lib/rocket_job/plugins/processing_window.rb +2 -2
- data/lib/rocket_job/plugins/restart.rb +3 -4
- data/lib/rocket_job/plugins/retry.rb +2 -3
- data/lib/rocket_job/plugins/singleton.rb +2 -3
- data/lib/rocket_job/plugins/state_machine.rb +19 -23
- data/lib/rocket_job/rocket_job.rb +4 -5
- data/lib/rocket_job/server.rb +35 -41
- data/lib/rocket_job/version.rb +2 -2
- data/lib/rocket_job/worker.rb +22 -21
- data/lib/rocketjob.rb +2 -0
- data/test/config/mongoid.yml +2 -2
- data/test/config_test.rb +0 -2
- data/test/dirmon_entry_test.rb +161 -134
- data/test/dirmon_job_test.rb +80 -78
- data/test/job_test.rb +0 -2
- data/test/jobs/housekeeping_job_test.rb +0 -1
- data/test/jobs/on_demand_job_test.rb +59 -0
- data/test/jobs/upload_file_job_test.rb +99 -0
- data/test/plugins/cron_test.rb +1 -3
- data/test/plugins/job/callbacks_test.rb +8 -13
- data/test/plugins/job/defaults_test.rb +0 -1
- data/test/plugins/job/logger_test.rb +2 -4
- data/test/plugins/job/model_test.rb +1 -2
- data/test/plugins/job/persistence_test.rb +0 -2
- data/test/plugins/job/state_machine_test.rb +0 -2
- data/test/plugins/job/throttle_test.rb +6 -8
- data/test/plugins/job/worker_test.rb +1 -2
- data/test/plugins/processing_window_test.rb +0 -2
- data/test/plugins/restart_test.rb +0 -1
- data/test/plugins/retry_test.rb +1 -2
- data/test/plugins/singleton_test.rb +0 -2
- data/test/plugins/state_machine_event_callbacks_test.rb +1 -2
- data/test/plugins/state_machine_test.rb +0 -2
- data/test/plugins/transaction_test.rb +5 -7
- data/test/test_db.sqlite3 +0 -0
- data/test/test_helper.rb +2 -1
- metadata +42 -36
@@ -2,129 +2,7 @@ require 'active_support/concern'
|
|
2
2
|
|
3
3
|
module RocketJob
|
4
4
|
module Plugins
|
5
|
-
#
|
6
|
-
# Once started the job will automatically restart on completion and will only run again
|
7
|
-
# according to the `cron_schedule`.
|
8
|
-
# Failed jobs are aborted so that they cannot be restarted since a new instance has already
|
9
|
-
# been enqueued.
|
10
|
-
#
|
11
|
-
# Include RocketJob::Plugins::Singleton to prevent multiple copies of the job from running at
|
12
|
-
# the same time.
|
13
|
-
#
|
14
|
-
# Unlike cron, if a job is already running, another one is not queued when the cron
|
15
|
-
# schedule needs another started, but rather on completion of the current job. This prevents
|
16
|
-
# multiple instances of the same job from running at the same time. The next instance of the
|
17
|
-
# job is only scheduled on completion of the current job instance.
|
18
|
-
#
|
19
|
-
# For example if the job takes 10 minutes to complete, and is scheduled to run every 5 minutes,
|
20
|
-
# it will only be run every 10 minutes.
|
21
|
-
#
|
22
|
-
# Their is no centralized scheduler or need to start schedulers anywhere, since the jobs
|
23
|
-
# can be picked up by any Rocket Job worker. Once processing is complete a new instance is then
|
24
|
-
# automatically scheduled based on the `cron_schedule`.
|
25
|
-
#
|
26
|
-
# A job is only queued to run at the specified `cron_schedule`, it will only run if there are workers
|
27
|
-
# available to run. For example if workers are busy working on higher priority jobs, then the job
|
28
|
-
# will only run once those jobs have completed, or their priority lowered. Additionally, while the
|
29
|
-
# job is queued no additional instances will be enqueued, even if the next cron interval has been reached.
|
30
|
-
#
|
31
|
-
# Notes:
|
32
|
-
# - The job will not be restarted if:
|
33
|
-
# - A validation fails after cloning this job.
|
34
|
-
# - The job has expired.
|
35
|
-
# - Any time the `cron_schedule` is changed, the `run_at` is automatically set before saving the changes.
|
36
|
-
# - However, if the `run_at` is explicitly set then it will not be overridden.
|
37
|
-
# - `cron_schedule` is not a required field so that the same job class
|
38
|
-
# - can be scheduled to run at regular intervals,
|
39
|
-
# - and run on an ad-hoc basis with custom values.
|
40
|
-
# - On job failure
|
41
|
-
# - a new future instance is created immediately.
|
42
|
-
# - the current instance is marked as failed and its cron schedule is set to nil.
|
43
|
-
# - Prevents the failed instance from creating a new future instance when it completes.
|
44
|
-
#
|
45
|
-
# Example, schedule the job to run at regular intervals:
|
46
|
-
#
|
47
|
-
# class MyCronJob < RocketJob::Job
|
48
|
-
# include RocketJob::Plugins::Cron
|
49
|
-
#
|
50
|
-
# # Set the default cron_schedule
|
51
|
-
# self.cron_schedule = "* 1 * * * UTC"
|
52
|
-
#
|
53
|
-
# def perform
|
54
|
-
# puts "DONE"
|
55
|
-
# end
|
56
|
-
# end
|
57
|
-
#
|
58
|
-
# # Queue the job for processing using the default cron_schedule specified above.
|
59
|
-
# MyCronJob.create!
|
60
|
-
#
|
61
|
-
#
|
62
|
-
# Example, a job that can run at regular intervals, and can be run for ad-hoc reporting etc.:
|
63
|
-
#
|
64
|
-
# class ReportJob < RocketJob::Job
|
65
|
-
# # Do not set a default cron_schedule so that the job can also be used for ad-hoc work.
|
66
|
-
# include RocketJob::Plugins::Cron
|
67
|
-
#
|
68
|
-
# field :start_date, type: Date
|
69
|
-
# field :end_date, type: Date
|
70
|
-
#
|
71
|
-
# def perform
|
72
|
-
# # Uses `scheduled_at` to take into account any possible delays.
|
73
|
-
# self.start_at ||= scheduled_at.beginning_of_week.to_date
|
74
|
-
# self.end_at ||= scheduled_at.end_of_week.to_date
|
75
|
-
#
|
76
|
-
# puts "Running report, starting at #{start_date}, ending at #{end_date}"
|
77
|
-
# end
|
78
|
-
# end
|
79
|
-
#
|
80
|
-
# # Queue the job for processing using a cron_schedule.
|
81
|
-
# # On completion the job will create a new instance to run at a future date.
|
82
|
-
# ReportJob.create!(cron_schedule: '* 1 * * * America/New_York')
|
83
|
-
#
|
84
|
-
# # Queue the job for processing outside of the above cron schedule.
|
85
|
-
# # On completion the job will _not_ create a new instance to run at a future date.
|
86
|
-
# job = ReportJob.create!(start_date: 30.days.ago, end_date: 10.days.ago)
|
87
|
-
#
|
88
|
-
#
|
89
|
-
# To prevent multiple instances of the job from running at the same time, add the singleton plug-in:
|
90
|
-
# include RocketJob::Plugins::Singleton
|
91
|
-
#
|
92
|
-
# Example: Only allow one instance of this job to be active at the same time (running, queued, scheduled, or failed):
|
93
|
-
#
|
94
|
-
# class MyCronJob < RocketJob::Job
|
95
|
-
# # Add `cron_schedule`
|
96
|
-
# include RocketJob::Plugins::Cron
|
97
|
-
# # Prevents mutiple instances from being queued or run at the same time
|
98
|
-
# include RocketJob::Plugins::Singleton
|
99
|
-
#
|
100
|
-
# # Set the default cron_schedule
|
101
|
-
# self.cron_schedule = "* 1 * * * UTC"
|
102
|
-
#
|
103
|
-
# def perform
|
104
|
-
# puts "DONE"
|
105
|
-
# end
|
106
|
-
# end
|
107
|
-
#
|
108
|
-
# Note: The cron_schedule field is formatted as follows:
|
109
|
-
#
|
110
|
-
# * * * * * *
|
111
|
-
# ┬ ┬ ┬ ┬ ┬ ┬
|
112
|
-
# │ │ │ │ │ │
|
113
|
-
# │ │ │ │ │ └ Optional: Timezone, for example: 'America/New_York', 'UTC'
|
114
|
-
# │ │ │ │ └───── day_of_week (0-7) (0 or 7 is Sun, or use 3-letter names)
|
115
|
-
# │ │ │ └────────── month (1-12, or use 3-letter names)
|
116
|
-
# │ │ └─────────────── day_of_month (1-31)
|
117
|
-
# │ └──────────────────── hour (0-23)
|
118
|
-
# └───────────────────────── minute (0-59)
|
119
|
-
#
|
120
|
-
# * When specifying day of week, both day 0 and day 7 is Sunday.
|
121
|
-
# * Ranges & Lists of numbers are allowed.
|
122
|
-
# * Ranges or lists of names are not allowed.
|
123
|
-
# * Ranges can include 'steps', so `1-9/2` is the same as `1,3,5,7,9`.
|
124
|
-
# * Months or days of the week can be specified by name.
|
125
|
-
# * Use the first three letters of the particular day or month (case doesn't matter).
|
126
|
-
# * The timezone is recommended to prevent any issues with possible default timezone
|
127
|
-
# differences across servers, or environments.
|
5
|
+
# Schedule jobs to run at set intervals.
|
128
6
|
module Cron
|
129
7
|
extend ActiveSupport::Concern
|
130
8
|
|
@@ -176,6 +54,12 @@ module RocketJob
|
|
176
54
|
run_at || created_at
|
177
55
|
end
|
178
56
|
|
57
|
+
# Make this job run now, regardless of the cron schedule.
|
58
|
+
# Upon completion the job will automatically reschedule itself.
|
59
|
+
def run_now!
|
60
|
+
update_attributes(run_at: nil) if cron_schedule
|
61
|
+
end
|
62
|
+
|
179
63
|
# Returns [Time] the next time this job will be scheduled to run at.
|
180
64
|
#
|
181
65
|
# Parameters
|
@@ -192,7 +76,6 @@ module RocketJob
|
|
192
76
|
return unless cron_schedule
|
193
77
|
self.run_at = rocket_job_cron_next_time if cron_schedule_changed? && !run_at_changed?
|
194
78
|
end
|
195
|
-
|
196
79
|
end
|
197
80
|
end
|
198
81
|
end
|
@@ -34,17 +34,15 @@ module RocketJob
|
|
34
34
|
# Apply changes to this document returning the updated document from the database.
|
35
35
|
# Allows other changes to be made on the server that will be loaded.
|
36
36
|
def find_and_update(attrs)
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
37
|
+
doc = collection.find(_id: id).find_one_and_update({'$set' => attrs}, return_document: :after)
|
38
|
+
raise(Mongoid::Errors::DocumentNotFound.new(self.class, id)) unless doc
|
39
|
+
|
40
|
+
# Clear out keys that are not returned during the reload from MongoDB
|
41
|
+
(fields.keys + embedded_relations.keys - doc.keys).each { |key| send("#{key}=", nil) }
|
42
|
+
@attributes = doc
|
43
|
+
apply_defaults
|
44
|
+
self
|
46
45
|
end
|
47
|
-
|
48
46
|
end
|
49
47
|
end
|
50
48
|
end
|
@@ -9,7 +9,7 @@ module RocketJob
|
|
9
9
|
|
10
10
|
included do
|
11
11
|
# Fields that are end user editable.
|
12
|
-
# For example are editable in Rocket Job
|
12
|
+
# For example are editable in Rocket Job Web Interface.
|
13
13
|
class_attribute :user_editable_fields, instance_accessor: false
|
14
14
|
self.user_editable_fields = []
|
15
15
|
|
@@ -156,7 +156,7 @@ module RocketJob
|
|
156
156
|
# Scope for queued jobs that can run now
|
157
157
|
# I.e. Queued jobs excluding scheduled jobs
|
158
158
|
def queued_now
|
159
|
-
queued.or({:
|
159
|
+
queued.or({run_at: nil}, :run_at.lte => Time.now)
|
160
160
|
end
|
161
161
|
|
162
162
|
# Defines all the fields that are accessible on the Document
|
@@ -182,10 +182,8 @@ module RocketJob
|
|
182
182
|
end
|
183
183
|
if options.delete(:class_attribute) == true
|
184
184
|
class_attribute(name, instance_accessor: false)
|
185
|
-
if options.
|
186
|
-
|
187
|
-
end
|
188
|
-
options[:default] = lambda { self.class.public_send(name) }
|
185
|
+
public_send("#{name}=", options[:default]) if options.key?(:default)
|
186
|
+
options[:default] = -> { self.class.public_send(name) }
|
189
187
|
end
|
190
188
|
if options.delete(:copy_on_restart) == true
|
191
189
|
self.rocket_job_restart_attributes += [name.to_sym] unless rocket_job_restart_attributes.include?(name.to_sym)
|
@@ -248,7 +246,7 @@ module RocketJob
|
|
248
246
|
# Return [true|false] whether this job is sleeping.
|
249
247
|
# I.e. No workers currently working on this job even if it is running.
|
250
248
|
def sleeping?
|
251
|
-
running? &&
|
249
|
+
running? && worker_count.zero?
|
252
250
|
end
|
253
251
|
|
254
252
|
# Returns [Integer] the number of workers currently working on this job.
|
@@ -263,32 +261,31 @@ module RocketJob
|
|
263
261
|
|
264
262
|
# Returns [Hash] status of this job
|
265
263
|
def as_json
|
266
|
-
attrs = serializable_hash(methods: [
|
264
|
+
attrs = serializable_hash(methods: %i[seconds duration])
|
267
265
|
attrs.delete('result') unless collect_output?
|
268
|
-
attrs.delete('failure_count') unless failure_count
|
269
|
-
|
270
|
-
when queued?
|
266
|
+
attrs.delete('failure_count') unless failure_count.positive?
|
267
|
+
if queued?
|
271
268
|
attrs.delete('started_at')
|
272
269
|
attrs.delete('completed_at')
|
273
270
|
attrs.delete('result')
|
274
271
|
attrs
|
275
|
-
|
272
|
+
elsif running?
|
276
273
|
attrs.delete('completed_at')
|
277
274
|
attrs.delete('result')
|
278
275
|
attrs
|
279
|
-
|
276
|
+
elsif completed?
|
280
277
|
attrs.delete('percent_complete')
|
281
278
|
attrs
|
282
|
-
|
279
|
+
elsif paused?
|
283
280
|
attrs.delete('completed_at')
|
284
281
|
attrs.delete('result')
|
285
282
|
# Ensure 'paused_at' appears first in the hash
|
286
283
|
{'paused_at' => completed_at}.merge(attrs)
|
287
|
-
|
284
|
+
elsif aborted?
|
288
285
|
attrs.delete('completed_at')
|
289
286
|
attrs.delete('result')
|
290
287
|
{'aborted_at' => completed_at}.merge(attrs)
|
291
|
-
|
288
|
+
elsif failed?
|
292
289
|
attrs.delete('completed_at')
|
293
290
|
attrs.delete('result')
|
294
291
|
{'failed_at' => completed_at}.merge(attrs)
|
@@ -302,10 +299,9 @@ module RocketJob
|
|
302
299
|
h = as_json
|
303
300
|
h.delete('seconds')
|
304
301
|
h.dup.each_pair do |k, v|
|
305
|
-
|
306
|
-
when v.is_a?(Time)
|
302
|
+
if v.is_a?(Time)
|
307
303
|
h[k] = v.in_time_zone(time_zone).to_s
|
308
|
-
|
304
|
+
elsif v.is_a?(BSON::ObjectId)
|
309
305
|
h[k] = v.to_s
|
310
306
|
end
|
311
307
|
end
|
@@ -317,7 +313,6 @@ module RocketJob
|
|
317
313
|
return false unless worker_name.present? && server_name.present?
|
318
314
|
worker_name.start_with?(server_name)
|
319
315
|
end
|
320
|
-
|
321
316
|
end
|
322
317
|
end
|
323
318
|
end
|
@@ -10,8 +10,6 @@ module RocketJob
|
|
10
10
|
included do
|
11
11
|
# Store all job types in this collection
|
12
12
|
store_in collection: 'rocket_job.jobs'
|
13
|
-
|
14
|
-
after_initialize :remove_arguments
|
15
13
|
end
|
16
14
|
|
17
15
|
module ClassMethods
|
@@ -84,11 +82,11 @@ module RocketJob
|
|
84
82
|
end
|
85
83
|
|
86
84
|
# Calculate :queued_now and :scheduled if there are queued jobs
|
87
|
-
if queued_count = counts[:queued]
|
85
|
+
if (queued_count = counts[:queued])
|
88
86
|
scheduled_count = RocketJob::Job.scheduled.count
|
89
|
-
if scheduled_count
|
87
|
+
if scheduled_count.positive?
|
90
88
|
queued_now_count = queued_count - scheduled_count
|
91
|
-
counts[:queued_now] = queued_count - scheduled_count if queued_now_count
|
89
|
+
counts[:queued_now] = queued_count - scheduled_count if queued_now_count.positive?
|
92
90
|
counts[:scheduled] = scheduled_count
|
93
91
|
else
|
94
92
|
counts[:queued_now] = queued_count
|
@@ -112,14 +110,6 @@ module RocketJob
|
|
112
110
|
self
|
113
111
|
end
|
114
112
|
end
|
115
|
-
|
116
|
-
private
|
117
|
-
|
118
|
-
# Remove old style arguments that were stored as an array
|
119
|
-
def remove_arguments
|
120
|
-
attributes.delete('arguments') unless respond_to?('arguments='.to_sym)
|
121
|
-
end
|
122
|
-
|
123
113
|
end
|
124
114
|
end
|
125
115
|
end
|
@@ -78,7 +78,7 @@ module RocketJob
|
|
78
78
|
|
79
79
|
event :requeue do
|
80
80
|
transitions from: :running, to: :queued,
|
81
|
-
if: ->
|
81
|
+
if: ->(server_name) { worker_on_server?(server_name) },
|
82
82
|
after: :rocket_job_clear_started_at
|
83
83
|
end
|
84
84
|
end
|
@@ -165,7 +165,6 @@ module RocketJob
|
|
165
165
|
destroy if destroy_on_complete && !new_record?
|
166
166
|
end
|
167
167
|
end
|
168
|
-
|
169
168
|
end
|
170
169
|
end
|
171
170
|
end
|
@@ -47,21 +47,28 @@ module RocketJob
|
|
47
47
|
#
|
48
48
|
# Note: Throttles are executed in the order they are defined.
|
49
49
|
def define_throttle(method_name, filter: :throttle_filter_class)
|
50
|
-
|
51
|
-
|
50
|
+
unless filter.is_a?(Symbol) || filter.is_a?(Proc)
|
51
|
+
raise(ArgumentError, "Filter for #{method_name} must be a Symbol or Proc")
|
52
|
+
end
|
53
|
+
if throttle?(method_name)
|
54
|
+
raise(ArgumentError, "Cannot define #{method_name} twice, undefine previous throttle first")
|
55
|
+
end
|
52
56
|
|
53
57
|
self.rocket_job_throttles += [ThrottleDefinition.new(method_name, filter)]
|
54
58
|
end
|
55
59
|
|
56
60
|
# Undefine a previously defined throttle
|
57
|
-
def undefine_throttle(
|
58
|
-
rocket_job_throttles.delete_if
|
61
|
+
def undefine_throttle(_method_name)
|
62
|
+
rocket_job_throttles.delete_if(&:method_name)
|
59
63
|
end
|
60
64
|
|
61
65
|
# Has a throttle been defined?
|
62
|
-
def
|
66
|
+
def throttle?(method_name)
|
63
67
|
rocket_job_throttles.find { |throttle| throttle.method_name == method_name }
|
64
68
|
end
|
69
|
+
|
70
|
+
# DEPRECATED
|
71
|
+
alias has_throttle? throttle?
|
65
72
|
end
|
66
73
|
|
67
74
|
# Default throttle to use when the throttle is exceeded.
|
@@ -86,17 +93,14 @@ module RocketJob
|
|
86
93
|
def rocket_job_evaluate_throttles
|
87
94
|
rocket_job_throttles.each do |throttle|
|
88
95
|
# Throttle exceeded?
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
end
|
96
|
+
next unless send(throttle.method_name)
|
97
|
+
logger.debug { "Throttle: #{throttle.method_name} has been exceeded. #{self.class.name}:#{id}" }
|
98
|
+
filter = throttle.filter
|
99
|
+
return filter.is_a?(Proc) ? filter.call(self) : send(filter)
|
94
100
|
end
|
95
101
|
nil
|
96
102
|
end
|
97
|
-
|
98
103
|
end
|
99
|
-
|
100
104
|
end
|
101
105
|
end
|
102
106
|
end
|
@@ -10,15 +10,15 @@ module RocketJob
|
|
10
10
|
module ClassMethods
|
11
11
|
# Run this job now.
|
12
12
|
#
|
13
|
-
# The job is not saved to the database since it is processed
|
13
|
+
# The job is not saved to the database since it is processed entirely in memory
|
14
14
|
# As a result before_save and before_destroy callbacks will not be called.
|
15
15
|
# Validations are still called however prior to calling #perform
|
16
16
|
#
|
17
17
|
# Note:
|
18
18
|
# - Only batch throttles are checked when perform_now is called.
|
19
|
-
def perform_now(args
|
19
|
+
def perform_now(args)
|
20
20
|
job = new(args)
|
21
|
-
|
21
|
+
yield(job) if block_given?
|
22
22
|
job.perform_now
|
23
23
|
job
|
24
24
|
end
|
@@ -38,14 +38,13 @@ module RocketJob
|
|
38
38
|
# If a job is in queued state it will be started
|
39
39
|
def rocket_job_next_job(worker_name, filter = {})
|
40
40
|
while (job = rocket_job_retrieve(worker_name, filter))
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
when job.expired?
|
41
|
+
# Batch Job?
|
42
|
+
return job if job.running?
|
43
|
+
|
44
|
+
if job.expired?
|
46
45
|
job.rocket_job_fail_on_exception!(worker_name) { job.destroy }
|
47
46
|
logger.info "Destroyed expired job #{job.class.name}, id:#{job.id}"
|
48
|
-
|
47
|
+
elsif (new_filter = job.send(:rocket_job_evaluate_throttles))
|
49
48
|
rocket_job_merge_filter(filter, new_filter)
|
50
49
|
# Restore retrieved job so that other workers can process it later
|
51
50
|
job.set(worker_name: nil, state: :queued)
|
@@ -62,7 +61,7 @@ module RocketJob
|
|
62
61
|
# Requeues all jobs that were running on a server that died
|
63
62
|
def requeue_dead_server(server_name)
|
64
63
|
# Need to requeue paused, failed since user may have transitioned job before it finished
|
65
|
-
where(:state.in => [
|
64
|
+
where(:state.in => %i[running paused failed]).each do |job|
|
66
65
|
job.requeue!(server_name) if job.may_requeue?(server_name)
|
67
66
|
end
|
68
67
|
end
|
@@ -73,7 +72,7 @@ module RocketJob
|
|
73
72
|
perform_now(args, &block)
|
74
73
|
else
|
75
74
|
job = new(args)
|
76
|
-
|
75
|
+
yield(job) if block
|
77
76
|
job.save!
|
78
77
|
job
|
79
78
|
end
|
@@ -84,7 +83,7 @@ module RocketJob
|
|
84
83
|
def rocket_job_merge_filter(target, source)
|
85
84
|
source.each_pair do |k, v|
|
86
85
|
target[k] =
|
87
|
-
if previous = target[k]
|
86
|
+
if (previous = target[k])
|
88
87
|
v.is_a?(Array) ? previous + v : v
|
89
88
|
else
|
90
89
|
v
|
@@ -136,12 +135,10 @@ module RocketJob
|
|
136
135
|
self.exception = JobException.from_exception(exc)
|
137
136
|
exception.worker_name = worker_name
|
138
137
|
save! unless new_record? || destroyed?
|
138
|
+
elsif new_record? || destroyed?
|
139
|
+
fail(worker_name, exc)
|
139
140
|
else
|
140
|
-
|
141
|
-
fail(worker_name, exc)
|
142
|
-
else
|
143
|
-
fail!(worker_name, exc)
|
144
|
-
end
|
141
|
+
fail!(worker_name, exc)
|
145
142
|
end
|
146
143
|
raise exc if re_raise_exceptions
|
147
144
|
end
|
@@ -154,7 +151,7 @@ module RocketJob
|
|
154
151
|
# is set in the job itself.
|
155
152
|
#
|
156
153
|
# Thread-safe, can be called by multiple threads at the same time
|
157
|
-
def rocket_job_work(worker, re_raise_exceptions = false,
|
154
|
+
def rocket_job_work(worker, re_raise_exceptions = false, _filter = nil)
|
158
155
|
raise(ArgumentError, 'Job must be started before calling #rocket_job_work') unless running?
|
159
156
|
rocket_job_fail_on_exception!(worker.name, re_raise_exceptions) do
|
160
157
|
if _perform_callbacks.empty?
|
@@ -186,7 +183,6 @@ module RocketJob
|
|
186
183
|
return [] if !running? || (server_name && !worker_on_server?(server_name))
|
187
184
|
[ActiveWorker.new(worker_name, started_at, self)]
|
188
185
|
end
|
189
|
-
|
190
186
|
end
|
191
187
|
end
|
192
188
|
end
|