inst-jobs 2.3.3 → 2.4.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/db/migrate/20101216224513_create_delayed_jobs.rb +9 -7
- data/db/migrate/20110531144916_cleanup_delayed_jobs_indexes.rb +8 -13
- data/db/migrate/20110610213249_optimize_delayed_jobs.rb +8 -8
- data/db/migrate/20110831210257_add_delayed_jobs_next_in_strand.rb +25 -25
- data/db/migrate/20120510004759_delayed_jobs_delete_trigger_lock_for_update.rb +4 -8
- data/db/migrate/20120531150712_drop_psql_jobs_pop_fn.rb +1 -3
- data/db/migrate/20120607164022_delayed_jobs_use_advisory_locks.rb +11 -15
- data/db/migrate/20120607181141_index_jobs_on_locked_by.rb +1 -1
- data/db/migrate/20120608191051_add_jobs_run_at_index.rb +2 -2
- data/db/migrate/20120927184213_change_delayed_jobs_handler_to_text.rb +1 -1
- data/db/migrate/20140505215510_copy_failed_jobs_original_id.rb +2 -3
- data/db/migrate/20150807133223_add_max_concurrent_to_jobs.rb +9 -13
- data/db/migrate/20151210162949_improve_max_concurrent.rb +4 -8
- data/db/migrate/20161206323555_add_back_default_string_limits_jobs.rb +3 -2
- data/db/migrate/20181217155351_speed_up_max_concurrent_triggers.rb +13 -17
- data/db/migrate/20200330230722_add_id_to_get_delayed_jobs_index.rb +8 -8
- data/db/migrate/20200824222232_speed_up_max_concurrent_delete_trigger.rb +72 -77
- data/db/migrate/20200825011002_add_strand_order_override.rb +93 -97
- data/db/migrate/20210809145804_add_n_strand_index.rb +3 -3
- data/db/migrate/20210812210128_add_singleton_column.rb +200 -0
- data/db/migrate/20210917232626_add_delete_conflicting_singletons_before_unlock_trigger.rb +27 -0
- data/db/migrate/20210928174754_fix_singleton_condition_in_before_insert.rb +56 -0
- data/exe/inst_jobs +3 -2
- data/lib/delayed/backend/active_record.rb +204 -150
- data/lib/delayed/backend/base.rb +106 -82
- data/lib/delayed/batch.rb +11 -9
- data/lib/delayed/cli.rb +98 -84
- data/lib/delayed/core_ext/kernel.rb +4 -2
- data/lib/delayed/daemon.rb +70 -74
- data/lib/delayed/job_tracking.rb +26 -25
- data/lib/delayed/lifecycle.rb +27 -24
- data/lib/delayed/log_tailer.rb +17 -17
- data/lib/delayed/logging.rb +13 -16
- data/lib/delayed/message_sending.rb +43 -52
- data/lib/delayed/performable_method.rb +6 -8
- data/lib/delayed/periodic.rb +72 -65
- data/lib/delayed/plugin.rb +2 -4
- data/lib/delayed/pool.rb +198 -193
- data/lib/delayed/server/helpers.rb +6 -6
- data/lib/delayed/server.rb +51 -54
- data/lib/delayed/settings.rb +93 -81
- data/lib/delayed/testing.rb +21 -22
- data/lib/delayed/version.rb +1 -1
- data/lib/delayed/work_queue/in_process.rb +21 -18
- data/lib/delayed/work_queue/parent_process/client.rb +54 -55
- data/lib/delayed/work_queue/parent_process/server.rb +219 -208
- data/lib/delayed/work_queue/parent_process.rb +52 -53
- data/lib/delayed/worker/consul_health_check.rb +21 -19
- data/lib/delayed/worker/health_check.rb +29 -22
- data/lib/delayed/worker/null_health_check.rb +3 -1
- data/lib/delayed/worker/process_helper.rb +8 -9
- data/lib/delayed/worker.rb +271 -265
- data/lib/delayed/yaml_extensions.rb +12 -10
- data/lib/delayed_job.rb +37 -38
- data/lib/inst-jobs.rb +1 -1
- data/spec/active_record_job_spec.rb +129 -136
- data/spec/delayed/cli_spec.rb +7 -7
- data/spec/delayed/daemon_spec.rb +10 -9
- data/spec/delayed/message_sending_spec.rb +16 -9
- data/spec/delayed/periodic_spec.rb +13 -12
- data/spec/delayed/server_spec.rb +38 -38
- data/spec/delayed/settings_spec.rb +26 -25
- data/spec/delayed/work_queue/in_process_spec.rb +7 -8
- data/spec/delayed/work_queue/parent_process/client_spec.rb +17 -12
- data/spec/delayed/work_queue/parent_process/server_spec.rb +70 -41
- data/spec/delayed/work_queue/parent_process_spec.rb +21 -23
- data/spec/delayed/worker/consul_health_check_spec.rb +22 -22
- data/spec/delayed/worker/health_check_spec.rb +60 -52
- data/spec/delayed/worker_spec.rb +28 -25
- data/spec/sample_jobs.rb +45 -15
- data/spec/shared/delayed_batch.rb +74 -67
- data/spec/shared/delayed_method.rb +143 -102
- data/spec/shared/performable_method.rb +39 -38
- data/spec/shared/shared_backend.rb +547 -441
- data/spec/shared/testing.rb +14 -14
- data/spec/shared/worker.rb +155 -147
- data/spec/shared_jobs_specs.rb +13 -13
- data/spec/spec_helper.rb +46 -41
- metadata +79 -55
- data/lib/delayed/backend/redis/bulk_update.lua +0 -50
- data/lib/delayed/backend/redis/destroy_job.lua +0 -2
- data/lib/delayed/backend/redis/enqueue.lua +0 -29
- data/lib/delayed/backend/redis/fail_job.lua +0 -5
- data/lib/delayed/backend/redis/find_available.lua +0 -3
- data/lib/delayed/backend/redis/functions.rb +0 -59
- data/lib/delayed/backend/redis/get_and_lock_next_available.lua +0 -17
- data/lib/delayed/backend/redis/includes/jobs_common.lua +0 -203
- data/lib/delayed/backend/redis/job.rb +0 -528
- data/lib/delayed/backend/redis/set_running.lua +0 -5
- data/lib/delayed/backend/redis/tickle_strand.lua +0 -2
- data/spec/gemfiles/52.gemfile +0 -7
- data/spec/gemfiles/60.gemfile +0 -7
- data/spec/gemfiles/60.gemfile.lock +0 -246
- data/spec/gemfiles/61.gemfile +0 -7
- data/spec/redis_job_spec.rb +0 -148
data/spec/spec_helper.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "delayed_job"
|
4
|
+
require "delayed/testing"
|
5
5
|
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
6
|
+
require "database_cleaner"
|
7
|
+
require "fileutils"
|
8
|
+
require "rack/test"
|
9
|
+
require "timecop"
|
10
|
+
require "webmock/rspec"
|
10
11
|
|
11
|
-
require
|
12
|
-
require
|
12
|
+
require "pry"
|
13
|
+
require "byebug"
|
13
14
|
|
14
15
|
RSpec.configure do |config|
|
15
|
-
|
16
16
|
config.expect_with(:rspec) do |c|
|
17
|
-
c.syntax = [
|
17
|
+
c.syntax = %i[should expect]
|
18
18
|
end
|
19
19
|
|
20
20
|
config.before(:suite) do
|
@@ -23,47 +23,42 @@ RSpec.configure do |config|
|
|
23
23
|
WebMock.disable_net_connect!
|
24
24
|
end
|
25
25
|
|
26
|
-
config.before
|
27
|
-
if
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
26
|
+
config.before do |example|
|
27
|
+
DatabaseCleaner.strategy = if example.metadata[:sinatra] || example.metadata[:non_transactional]
|
28
|
+
:truncation
|
29
|
+
else
|
30
|
+
:transaction
|
31
|
+
end
|
32
32
|
DatabaseCleaner.start
|
33
33
|
end
|
34
34
|
|
35
|
-
config.after
|
35
|
+
config.after do
|
36
36
|
DatabaseCleaner.clean
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
40
|
module NoYamlDump
|
41
|
-
def encode_with(coder)
|
42
|
-
end
|
41
|
+
def encode_with(coder); end
|
43
42
|
end
|
44
43
|
# example groups are often the sender, and if we try to serialize them,
|
45
44
|
# the resultant object is then encoded in the sender, and then we serialize
|
46
45
|
# again, and it just keeps getting bigger and bigger and bigger...
|
47
46
|
RSpec::Core::ExampleGroup.include(NoYamlDump)
|
48
47
|
|
49
|
-
ENV[
|
50
|
-
ENV[
|
51
|
-
ENV[
|
52
|
-
ENV['TEST_REDIS_CONNECTION'] ||= 'redis://localhost:6379/'
|
53
|
-
|
54
|
-
Delayed::Backend::Redis::Job.redis = Redis.new(url: ENV['TEST_REDIS_CONNECTION'])
|
55
|
-
Delayed::Backend::Redis::Job.redis.select ENV['TEST_ENV_NUMBER']
|
48
|
+
ENV["TEST_ENV_NUMBER"] ||= "1"
|
49
|
+
ENV["TEST_DB_HOST"] ||= "localhost"
|
50
|
+
ENV["TEST_DB_DATABASE"] ||= "inst-jobs-test-#{ENV['TEST_ENV_NUMBER']}"
|
56
51
|
|
57
52
|
connection_config = {
|
58
53
|
adapter: :postgresql,
|
59
|
-
host: ENV[
|
60
|
-
encoding:
|
61
|
-
username: ENV[
|
62
|
-
database: ENV[
|
54
|
+
host: ENV["TEST_DB_HOST"].presence,
|
55
|
+
encoding: "utf8",
|
56
|
+
username: ENV["TEST_DB_USERNAME"],
|
57
|
+
database: ENV["TEST_DB_DATABASE"]
|
63
58
|
}
|
64
59
|
|
65
60
|
def migrate(file)
|
66
|
-
if ::Rails.version >=
|
61
|
+
if ::Rails.version >= "6"
|
67
62
|
ActiveRecord::MigrationContext.new(file, ActiveRecord::SchemaMigration).migrate
|
68
63
|
else
|
69
64
|
ActiveRecord::MigrationContext.new(file).migrate
|
@@ -71,27 +66,37 @@ def migrate(file)
|
|
71
66
|
end
|
72
67
|
|
73
68
|
# create the test db if it does not exist, to help out wwtd
|
74
|
-
ActiveRecord::Base.establish_connection(connection_config.merge(database:
|
69
|
+
ActiveRecord::Base.establish_connection(connection_config.merge(database: "postgres"))
|
75
70
|
begin
|
76
71
|
ActiveRecord::Base.connection.create_database(connection_config[:database])
|
77
72
|
rescue ActiveRecord::StatementInvalid
|
73
|
+
nil
|
78
74
|
end
|
79
75
|
ActiveRecord::Base.establish_connection(connection_config)
|
80
|
-
# TODO reset db and migrate again, to test migrations
|
76
|
+
# TODO: reset db and migrate again, to test migrations
|
81
77
|
|
82
78
|
migrate("db/migrate")
|
83
79
|
migrate("spec/migrate")
|
84
80
|
Delayed::Backend::ActiveRecord::Job.reset_column_information
|
85
81
|
Delayed::Backend::ActiveRecord::Job::Failed.reset_column_information
|
86
82
|
|
87
|
-
Time.zone =
|
88
|
-
|
83
|
+
Time.zone = "UTC" # rubocop:disable Rails/TimeZoneAssignment
|
84
|
+
FileUtils.mkdir_p("tmp")
|
85
|
+
ActiveRecord::Base.logger = Rails.logger = Logger.new("tmp/test.log")
|
89
86
|
|
90
87
|
# Purely useful for test cases...
|
91
88
|
class Story < ActiveRecord::Base
|
92
|
-
def tell
|
93
|
-
|
94
|
-
|
89
|
+
def tell
|
90
|
+
text
|
91
|
+
end
|
92
|
+
|
93
|
+
def whatever(times, _)
|
94
|
+
tell * times
|
95
|
+
end
|
96
|
+
|
97
|
+
def whatever_else(times, _)
|
98
|
+
tell * times
|
99
|
+
end
|
95
100
|
|
96
101
|
handle_asynchronously :whatever
|
97
102
|
handle_asynchronously :whatever_else, queue: "testqueue"
|
@@ -114,7 +119,7 @@ module MyReverser
|
|
114
119
|
end
|
115
120
|
|
116
121
|
def change_setting(klass, setting_name, value)
|
117
|
-
old_val = klass.
|
122
|
+
old_val = klass.send(setting_name)
|
118
123
|
klass.send("#{setting_name}=", value)
|
119
124
|
yield
|
120
125
|
ensure
|
@@ -125,5 +130,5 @@ def run_job(job)
|
|
125
130
|
Delayed::Testing.run_job(job)
|
126
131
|
end
|
127
132
|
|
128
|
-
|
129
|
-
|
133
|
+
require_relative "sample_jobs"
|
134
|
+
require_relative "shared_jobs_specs"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inst-jobs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Luetke
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2023-02-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -60,75 +60,61 @@ dependencies:
|
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '3'
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '5.2'
|
69
|
-
type: :runtime
|
70
|
-
prerelease: false
|
71
|
-
version_requirements: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '5.2'
|
76
|
-
- !ruby/object:Gem::Dependency
|
77
|
-
name: redis
|
63
|
+
name: debug_inspector
|
78
64
|
requirement: !ruby/object:Gem::Requirement
|
79
65
|
requirements:
|
80
|
-
- - "
|
66
|
+
- - "~>"
|
81
67
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
68
|
+
version: '1.0'
|
83
69
|
type: :runtime
|
84
70
|
prerelease: false
|
85
71
|
version_requirements: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
|
-
- - "
|
73
|
+
- - "~>"
|
88
74
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
75
|
+
version: '1.0'
|
90
76
|
- !ruby/object:Gem::Dependency
|
91
|
-
name:
|
77
|
+
name: fugit
|
92
78
|
requirement: !ruby/object:Gem::Requirement
|
93
79
|
requirements:
|
94
80
|
- - "~>"
|
95
81
|
- !ruby/object:Gem::Version
|
96
|
-
version: 1.
|
82
|
+
version: '1.3'
|
97
83
|
type: :runtime
|
98
84
|
prerelease: false
|
99
85
|
version_requirements: !ruby/object:Gem::Requirement
|
100
86
|
requirements:
|
101
87
|
- - "~>"
|
102
88
|
- !ruby/object:Gem::Version
|
103
|
-
version: 1.
|
89
|
+
version: '1.3'
|
104
90
|
- !ruby/object:Gem::Dependency
|
105
|
-
name:
|
91
|
+
name: railties
|
106
92
|
requirement: !ruby/object:Gem::Requirement
|
107
93
|
requirements:
|
108
|
-
- - "
|
94
|
+
- - ">="
|
109
95
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
96
|
+
version: '5.2'
|
111
97
|
type: :runtime
|
112
98
|
prerelease: false
|
113
99
|
version_requirements: !ruby/object:Gem::Requirement
|
114
100
|
requirements:
|
115
|
-
- - "
|
101
|
+
- - ">="
|
116
102
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
103
|
+
version: '5.2'
|
118
104
|
- !ruby/object:Gem::Dependency
|
119
|
-
name:
|
105
|
+
name: appraisal
|
120
106
|
requirement: !ruby/object:Gem::Requirement
|
121
107
|
requirements:
|
122
108
|
- - "~>"
|
123
109
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
125
|
-
type: :
|
110
|
+
version: '2.4'
|
111
|
+
type: :development
|
126
112
|
prerelease: false
|
127
113
|
version_requirements: !ruby/object:Gem::Requirement
|
128
114
|
requirements:
|
129
115
|
- - "~>"
|
130
116
|
- !ruby/object:Gem::Version
|
131
|
-
version: '
|
117
|
+
version: '2.4'
|
132
118
|
- !ruby/object:Gem::Dependency
|
133
119
|
name: bump
|
134
120
|
requirement: !ruby/object:Gem::Requirement
|
@@ -283,6 +269,62 @@ dependencies:
|
|
283
269
|
- - "~>"
|
284
270
|
- !ruby/object:Gem::Version
|
285
271
|
version: '3.10'
|
272
|
+
- !ruby/object:Gem::Dependency
|
273
|
+
name: rubocop
|
274
|
+
requirement: !ruby/object:Gem::Requirement
|
275
|
+
requirements:
|
276
|
+
- - "~>"
|
277
|
+
- !ruby/object:Gem::Version
|
278
|
+
version: '1.19'
|
279
|
+
type: :development
|
280
|
+
prerelease: false
|
281
|
+
version_requirements: !ruby/object:Gem::Requirement
|
282
|
+
requirements:
|
283
|
+
- - "~>"
|
284
|
+
- !ruby/object:Gem::Version
|
285
|
+
version: '1.19'
|
286
|
+
- !ruby/object:Gem::Dependency
|
287
|
+
name: rubocop-rails
|
288
|
+
requirement: !ruby/object:Gem::Requirement
|
289
|
+
requirements:
|
290
|
+
- - "~>"
|
291
|
+
- !ruby/object:Gem::Version
|
292
|
+
version: '2.11'
|
293
|
+
type: :development
|
294
|
+
prerelease: false
|
295
|
+
version_requirements: !ruby/object:Gem::Requirement
|
296
|
+
requirements:
|
297
|
+
- - "~>"
|
298
|
+
- !ruby/object:Gem::Version
|
299
|
+
version: '2.11'
|
300
|
+
- !ruby/object:Gem::Dependency
|
301
|
+
name: rubocop-rake
|
302
|
+
requirement: !ruby/object:Gem::Requirement
|
303
|
+
requirements:
|
304
|
+
- - "~>"
|
305
|
+
- !ruby/object:Gem::Version
|
306
|
+
version: '0.6'
|
307
|
+
type: :development
|
308
|
+
prerelease: false
|
309
|
+
version_requirements: !ruby/object:Gem::Requirement
|
310
|
+
requirements:
|
311
|
+
- - "~>"
|
312
|
+
- !ruby/object:Gem::Version
|
313
|
+
version: '0.6'
|
314
|
+
- !ruby/object:Gem::Dependency
|
315
|
+
name: rubocop-rspec
|
316
|
+
requirement: !ruby/object:Gem::Requirement
|
317
|
+
requirements:
|
318
|
+
- - "~>"
|
319
|
+
- !ruby/object:Gem::Version
|
320
|
+
version: '2.4'
|
321
|
+
type: :development
|
322
|
+
prerelease: false
|
323
|
+
version_requirements: !ruby/object:Gem::Requirement
|
324
|
+
requirements:
|
325
|
+
- - "~>"
|
326
|
+
- !ruby/object:Gem::Version
|
327
|
+
version: '2.4'
|
286
328
|
- !ruby/object:Gem::Dependency
|
287
329
|
name: sinatra
|
288
330
|
requirement: !ruby/object:Gem::Requirement
|
@@ -388,20 +430,12 @@ files:
|
|
388
430
|
- db/migrate/20200824222232_speed_up_max_concurrent_delete_trigger.rb
|
389
431
|
- db/migrate/20200825011002_add_strand_order_override.rb
|
390
432
|
- db/migrate/20210809145804_add_n_strand_index.rb
|
433
|
+
- db/migrate/20210812210128_add_singleton_column.rb
|
434
|
+
- db/migrate/20210917232626_add_delete_conflicting_singletons_before_unlock_trigger.rb
|
435
|
+
- db/migrate/20210928174754_fix_singleton_condition_in_before_insert.rb
|
391
436
|
- exe/inst_jobs
|
392
437
|
- lib/delayed/backend/active_record.rb
|
393
438
|
- lib/delayed/backend/base.rb
|
394
|
-
- lib/delayed/backend/redis/bulk_update.lua
|
395
|
-
- lib/delayed/backend/redis/destroy_job.lua
|
396
|
-
- lib/delayed/backend/redis/enqueue.lua
|
397
|
-
- lib/delayed/backend/redis/fail_job.lua
|
398
|
-
- lib/delayed/backend/redis/find_available.lua
|
399
|
-
- lib/delayed/backend/redis/functions.rb
|
400
|
-
- lib/delayed/backend/redis/get_and_lock_next_available.lua
|
401
|
-
- lib/delayed/backend/redis/includes/jobs_common.lua
|
402
|
-
- lib/delayed/backend/redis/job.rb
|
403
|
-
- lib/delayed/backend/redis/set_running.lua
|
404
|
-
- lib/delayed/backend/redis/tickle_strand.lua
|
405
439
|
- lib/delayed/batch.rb
|
406
440
|
- lib/delayed/cli.rb
|
407
441
|
- lib/delayed/core_ext/kernel.rb
|
@@ -451,12 +485,7 @@ files:
|
|
451
485
|
- spec/delayed/worker/consul_health_check_spec.rb
|
452
486
|
- spec/delayed/worker/health_check_spec.rb
|
453
487
|
- spec/delayed/worker_spec.rb
|
454
|
-
- spec/gemfiles/52.gemfile
|
455
|
-
- spec/gemfiles/60.gemfile
|
456
|
-
- spec/gemfiles/60.gemfile.lock
|
457
|
-
- spec/gemfiles/61.gemfile
|
458
488
|
- spec/migrate/20140924140513_add_story_table.rb
|
459
|
-
- spec/redis_job_spec.rb
|
460
489
|
- spec/sample_jobs.rb
|
461
490
|
- spec/shared/delayed_batch.rb
|
462
491
|
- spec/shared/delayed_method.rb
|
@@ -484,18 +513,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
484
513
|
- !ruby/object:Gem::Version
|
485
514
|
version: '0'
|
486
515
|
requirements: []
|
487
|
-
rubygems_version: 3.
|
516
|
+
rubygems_version: 3.1.6
|
488
517
|
signing_key:
|
489
518
|
specification_version: 4
|
490
519
|
summary: Instructure-maintained fork of delayed_job
|
491
520
|
test_files:
|
492
521
|
- spec/sample_jobs.rb
|
493
522
|
- spec/spec_helper.rb
|
494
|
-
- spec/redis_job_spec.rb
|
495
|
-
- spec/gemfiles/60.gemfile.lock
|
496
|
-
- spec/gemfiles/61.gemfile
|
497
|
-
- spec/gemfiles/60.gemfile
|
498
|
-
- spec/gemfiles/52.gemfile
|
499
523
|
- spec/shared_jobs_specs.rb
|
500
524
|
- spec/shared/performable_method.rb
|
501
525
|
- spec/shared/testing.rb
|
@@ -1,50 +0,0 @@
|
|
1
|
-
local action, id_string, flavor, query, now = unpack(ARGV)
|
2
|
-
|
3
|
-
local ids = {}
|
4
|
-
|
5
|
-
if string.len(flavor) > 0 then
|
6
|
-
if flavor == 'current' then
|
7
|
-
ids = redis.call('ZRANGE', Keys.queue(query), 0, -1)
|
8
|
-
elseif flavor == 'future' then
|
9
|
-
ids = redis.call('ZRANGE', Keys.future_queue(query), 0, -1)
|
10
|
-
elseif flavor == 'strand' then
|
11
|
-
ids = redis.call('LRANGE', Keys.strand(query), 0, -1)
|
12
|
-
elseif flavor == 'tag' then
|
13
|
-
ids = redis.call('SMEMBERS', Keys.tag(query))
|
14
|
-
end
|
15
|
-
else
|
16
|
-
-- can't pass an array to redis/lua, so we split the string here
|
17
|
-
for id in string.gmatch(id_string, "([%w-]+)") do
|
18
|
-
if job_exists(id) then
|
19
|
-
table.insert(ids, id)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
local count = 0
|
25
|
-
for idx, job_id in ipairs(ids) do
|
26
|
-
if action == 'hold' then
|
27
|
-
local queue, strand, locked_by = unpack(redis.call('HMGET', Keys.job(job_id), 'queue', 'strand', 'locked_by'))
|
28
|
-
if not locked_by then
|
29
|
-
count = count + 1
|
30
|
-
remove_from_queues(job_id, queue, strand)
|
31
|
-
redis.call('HMSET', Keys.job(job_id), 'locked_at', now, 'locked_by', 'on hold', 'attempts', 50)
|
32
|
-
end
|
33
|
-
elseif action == 'unhold' then
|
34
|
-
local queue, locked_by = unpack(redis.call('HMGET', Keys.job(job_id), 'queue', 'locked_by'))
|
35
|
-
if locked_by == 'on hold' then
|
36
|
-
count = count + 1
|
37
|
-
add_to_queues(job_id, queue, now)
|
38
|
-
redis.call('HDEL', Keys.job(job_id), 'locked_at', 'locked_by')
|
39
|
-
redis.call('HMSET', Keys.job(job_id), 'attempts', 0)
|
40
|
-
end
|
41
|
-
elseif action == 'destroy' then
|
42
|
-
local locked_by = redis.call('HGET', Keys.job(job_id), 'locked_by')
|
43
|
-
if not locked_by or locked_by == 'on hold' then
|
44
|
-
count = count + 1
|
45
|
-
destroy_job(job_id, now)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
return count
|
@@ -1,29 +0,0 @@
|
|
1
|
-
local job_id, queue, strand, now, for_singleton = unpack(ARGV)
|
2
|
-
local strand_key = Keys.strand(strand)
|
3
|
-
|
4
|
-
-- if this is a singleton job, only queue it up if another doesn't exist on the strand
|
5
|
-
-- otherwise, delete it and return the other job id
|
6
|
-
if for_singleton then
|
7
|
-
local job_ids = redis.call('LRANGE', strand_key, 0, 1)
|
8
|
-
local job_to_check = 1
|
9
|
-
if job_exists(job_ids[1]) and redis.call('HGET', Keys.job(job_ids[1]), 'locked_at') then
|
10
|
-
job_to_check = 2
|
11
|
-
end
|
12
|
-
|
13
|
-
local job_to_check_id = job_ids[job_to_check]
|
14
|
-
if job_exists(job_to_check_id) then
|
15
|
-
-- delete the new job, we found a match
|
16
|
-
redis.call('DEL', Keys.job(job_id))
|
17
|
-
return job_to_check_id
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
-- if this job is in a strand, add it to the strand queue first
|
22
|
-
-- if it's not at the front of the strand, we won't enqueue it below
|
23
|
-
if strand_key then
|
24
|
-
add_to_strand(job_id, strand)
|
25
|
-
end
|
26
|
-
|
27
|
-
add_to_queues(job_id, queue, now)
|
28
|
-
|
29
|
-
return job_id
|
@@ -1,59 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'redis/scripting'
|
4
|
-
|
5
|
-
# This module handles loading the Lua functions into Redis and running them
|
6
|
-
module Delayed::Backend::Redis
|
7
|
-
class Functions < ::Redis::Scripting::Module
|
8
|
-
def initialize(redis)
|
9
|
-
super(redis, File.dirname(__FILE__))
|
10
|
-
end
|
11
|
-
|
12
|
-
def run_script(script, keys, argv)
|
13
|
-
result = nil
|
14
|
-
ms = Benchmark.ms { result = super }
|
15
|
-
line = 'Redis Jobs Timing: %s (%.1fms)' % [script.name, ms]
|
16
|
-
ActiveRecord::Base.logger.debug(line)
|
17
|
-
result
|
18
|
-
end
|
19
|
-
|
20
|
-
def find_available(queue, limit, offset, min_priority, max_priority, now)
|
21
|
-
run(:find_available, [], [queue, limit, offset, min_priority, max_priority, now.utc.to_f])
|
22
|
-
end
|
23
|
-
|
24
|
-
def get_and_lock_next_available(worker_name, queue, min_priority, max_priority, now)
|
25
|
-
attrs = run(:get_and_lock_next_available, [], [queue, min_priority, max_priority, worker_name, now.utc.to_f])
|
26
|
-
Hash[*attrs]
|
27
|
-
end
|
28
|
-
|
29
|
-
def enqueue(job_id, queue, strand, now)
|
30
|
-
run(:enqueue, [], [job_id, queue, strand, now.utc.to_f])
|
31
|
-
end
|
32
|
-
|
33
|
-
def create_singleton(job_id, queue, strand, now)
|
34
|
-
run(:enqueue, [], [job_id, queue, strand, now.utc.to_f, true])
|
35
|
-
end
|
36
|
-
|
37
|
-
def destroy_job(job_id, now)
|
38
|
-
run(:destroy_job, [], [job_id, now.utc.to_f])
|
39
|
-
end
|
40
|
-
|
41
|
-
def tickle_strand(job_id, strand, now)
|
42
|
-
run(:tickle_strand, [], [job_id, strand, now.utc.to_f])
|
43
|
-
end
|
44
|
-
|
45
|
-
def fail_job(job_id)
|
46
|
-
run(:fail_job, [], [job_id])
|
47
|
-
end
|
48
|
-
|
49
|
-
def set_running(job_id)
|
50
|
-
run(:set_running, [], [job_id])
|
51
|
-
end
|
52
|
-
|
53
|
-
def bulk_update(action, ids, flavor, query, now)
|
54
|
-
ids = (ids || []).join(",")
|
55
|
-
run(:bulk_update, [], [action, ids, flavor, query, now.utc.to_f])
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
59
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
local queue, min_priority, max_priority, worker_name, now = unpack(ARGV)
|
2
|
-
local job_id = find_available(queue, 1, 0, min_priority, max_priority, now)[1]
|
3
|
-
|
4
|
-
if job_exists(job_id) then
|
5
|
-
-- update the job with locked_by and locked_at
|
6
|
-
redis.call('HMSET', Keys.job(job_id), 'locked_by', worker_name, 'locked_at', now)
|
7
|
-
|
8
|
-
-- add the job to the running_jobs set
|
9
|
-
redis.call('ZADD', Keys.running_jobs(), now, job_id)
|
10
|
-
-- remove the job from the pending jobs queue
|
11
|
-
redis.call('ZREM', Keys.queue(queue), job_id)
|
12
|
-
|
13
|
-
-- return the list of job attributes
|
14
|
-
return redis.call('HGETALL', Keys.job(job_id))
|
15
|
-
else
|
16
|
-
return {}
|
17
|
-
end
|