inst-jobs 0.16.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/db/migrate/20101216224513_create_delayed_jobs.rb +2 -0
  3. data/db/migrate/20110208031356_add_delayed_jobs_tag.rb +2 -0
  4. data/db/migrate/20110426161613_add_delayed_jobs_max_attempts.rb +2 -0
  5. data/db/migrate/20110516225834_add_delayed_jobs_strand.rb +2 -0
  6. data/db/migrate/20110531144916_cleanup_delayed_jobs_indexes.rb +2 -0
  7. data/db/migrate/20110610213249_optimize_delayed_jobs.rb +2 -0
  8. data/db/migrate/20110831210257_add_delayed_jobs_next_in_strand.rb +2 -0
  9. data/db/migrate/20120510004759_delayed_jobs_delete_trigger_lock_for_update.rb +2 -0
  10. data/db/migrate/20120531150712_drop_psql_jobs_pop_fn.rb +2 -0
  11. data/db/migrate/20120607164022_delayed_jobs_use_advisory_locks.rb +2 -0
  12. data/db/migrate/20120607181141_index_jobs_on_locked_by.rb +2 -0
  13. data/db/migrate/20120608191051_add_jobs_run_at_index.rb +2 -0
  14. data/db/migrate/20120927184213_change_delayed_jobs_handler_to_text.rb +2 -0
  15. data/db/migrate/20140505215131_add_failed_jobs_original_job_id.rb +2 -0
  16. data/db/migrate/20140505215510_copy_failed_jobs_original_id.rb +2 -0
  17. data/db/migrate/20140505223637_drop_failed_jobs_original_id.rb +2 -0
  18. data/db/migrate/20140512213941_add_source_to_jobs.rb +2 -0
  19. data/db/migrate/20150807133223_add_max_concurrent_to_jobs.rb +2 -0
  20. data/db/migrate/20151123210429_add_expires_at_to_jobs.rb +2 -0
  21. data/db/migrate/20151210162949_improve_max_concurrent.rb +2 -0
  22. data/db/migrate/20161206323555_add_back_default_string_limits_jobs.rb +2 -0
  23. data/db/migrate/20181217155351_speed_up_max_concurrent_triggers.rb +2 -0
  24. data/db/migrate/20190726154743_make_critical_columns_not_null.rb +2 -0
  25. data/db/migrate/20200330230722_add_id_to_get_delayed_jobs_index.rb +2 -0
  26. data/db/migrate/20200824222232_speed_up_max_concurrent_delete_trigger.rb +2 -0
  27. data/db/migrate/20200825011002_add_strand_order_override.rb +2 -0
  28. data/lib/delayed/backend/active_record.rb +6 -4
  29. data/lib/delayed/backend/base.rb +34 -20
  30. data/lib/delayed/backend/redis/functions.rb +2 -0
  31. data/lib/delayed/backend/redis/job.rb +2 -0
  32. data/lib/delayed/batch.rb +5 -3
  33. data/lib/delayed/cli.rb +2 -0
  34. data/lib/delayed/daemon.rb +2 -0
  35. data/lib/delayed/engine.rb +2 -0
  36. data/lib/delayed/job_tracking.rb +2 -0
  37. data/lib/delayed/lifecycle.rb +2 -0
  38. data/lib/delayed/log_tailer.rb +2 -0
  39. data/lib/delayed/logging.rb +2 -0
  40. data/lib/delayed/message_sending.rb +48 -111
  41. data/lib/delayed/performable_method.rb +15 -6
  42. data/lib/delayed/periodic.rb +6 -4
  43. data/lib/delayed/plugin.rb +2 -0
  44. data/lib/delayed/pool.rb +2 -0
  45. data/lib/delayed/server.rb +2 -0
  46. data/lib/delayed/server/helpers.rb +2 -0
  47. data/lib/delayed/settings.rb +2 -0
  48. data/lib/delayed/testing.rb +2 -0
  49. data/lib/delayed/version.rb +3 -1
  50. data/lib/delayed/work_queue/in_process.rb +2 -0
  51. data/lib/delayed/work_queue/parent_process.rb +2 -0
  52. data/lib/delayed/work_queue/parent_process/client.rb +2 -0
  53. data/lib/delayed/work_queue/parent_process/server.rb +2 -0
  54. data/lib/delayed/worker.rb +2 -0
  55. data/lib/delayed/worker/consul_health_check.rb +2 -0
  56. data/lib/delayed/worker/health_check.rb +2 -0
  57. data/lib/delayed/worker/null_health_check.rb +2 -0
  58. data/lib/delayed/worker/process_helper.rb +2 -0
  59. data/lib/delayed/yaml_extensions.rb +2 -0
  60. data/lib/delayed_job.rb +2 -0
  61. data/lib/inst-jobs.rb +2 -0
  62. data/spec/active_record_job_spec.rb +4 -2
  63. data/spec/delayed/cli_spec.rb +2 -0
  64. data/spec/delayed/daemon_spec.rb +2 -0
  65. data/spec/delayed/server_spec.rb +2 -0
  66. data/spec/delayed/settings_spec.rb +2 -0
  67. data/spec/delayed/work_queue/in_process_spec.rb +2 -0
  68. data/spec/delayed/work_queue/parent_process/client_spec.rb +2 -0
  69. data/spec/delayed/work_queue/parent_process/server_spec.rb +2 -0
  70. data/spec/delayed/work_queue/parent_process_spec.rb +2 -0
  71. data/spec/delayed/worker/consul_health_check_spec.rb +2 -0
  72. data/spec/delayed/worker/health_check_spec.rb +2 -0
  73. data/spec/delayed/worker_spec.rb +2 -0
  74. data/spec/gemfiles/42.gemfile.lock +192 -0
  75. data/spec/gemfiles/50.gemfile.lock +197 -0
  76. data/spec/gemfiles/51.gemfile.lock +198 -0
  77. data/spec/gemfiles/52.gemfile.lock +206 -0
  78. data/spec/gemfiles/60.gemfile.lock +222 -0
  79. data/spec/migrate/20140924140513_add_story_table.rb +2 -0
  80. data/spec/redis_job_spec.rb +10 -8
  81. data/spec/sample_jobs.rb +2 -0
  82. data/spec/shared/delayed_batch.rb +17 -15
  83. data/spec/shared/delayed_method.rb +49 -204
  84. data/spec/shared/performable_method.rb +11 -9
  85. data/spec/shared/shared_backend.rb +27 -25
  86. data/spec/shared/testing.rb +7 -5
  87. data/spec/shared/worker.rb +15 -13
  88. data/spec/shared_jobs_specs.rb +2 -0
  89. data/spec/spec_helper.rb +3 -1
  90. metadata +17 -7
@@ -1,13 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Delayed
2
- class PerformableMethod < Struct.new(:object, :method, :args, :fail_cb, :permanent_fail_cb)
3
- def initialize(object, method, args = [], fail_cb = nil, permanent_fail_cb = nil)
4
+ class PerformableMethod < Struct.new(:object, :method, :args, :kwargs, :fail_cb, :permanent_fail_cb)
5
+ def initialize(object, method, args: [], kwargs: {}, on_failure: nil, on_permanent_failure: nil)
4
6
  raise NoMethodError, "undefined method `#{method}' for #{object.inspect}" unless object.respond_to?(method, true)
5
7
 
6
8
  self.object = object
7
9
  self.args = args
10
+ self.kwargs = kwargs
8
11
  self.method = method.to_sym
9
- self.fail_cb = fail_cb
10
- self.permanent_fail_cb = permanent_fail_cb
12
+ self.fail_cb = on_failure
13
+ self.permanent_fail_cb = on_permanent_failure
11
14
  end
12
15
 
13
16
  def display_name
@@ -20,7 +23,12 @@ module Delayed
20
23
  alias_method :tag, :display_name
21
24
 
22
25
  def perform
23
- object.send(method, *args)
26
+ kwargs = self.kwargs || {}
27
+ if kwargs.empty?
28
+ object.send(method, *args)
29
+ else
30
+ object.send(method, *args, **kwargs)
31
+ end
24
32
  end
25
33
 
26
34
  def on_failure(error)
@@ -46,7 +54,8 @@ module Delayed
46
54
 
47
55
  def full_name
48
56
  obj_name = object.is_a?(ActiveRecord::Base) ? "#{object.class}.find(#{object.id}).#{method}" : display_name
49
- "#{obj_name}(#{args.map { |a| deep_de_ar_ize(a) }.join(', ')})"
57
+ kwargs_str = kwargs.map { |(k, v)| ", #{k}: #{deep_de_ar_ize(v)}"}.join("")
58
+ "#{obj_name}(#{args.map { |a| deep_de_ar_ize(a) }.join(', ')}#{kwargs_str})"
50
59
  end
51
60
  end
52
61
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'fugit'
2
4
 
3
5
  module Delayed
@@ -47,10 +49,10 @@ class Periodic
47
49
  end
48
50
 
49
51
  def enqueue
50
- Delayed::Job.enqueue(self, @job_args.merge(:max_attempts => 1,
51
- :run_at => @cron.next_time(Delayed::Periodic.now).utc.to_time,
52
- :singleton => tag,
53
- on_conflict: :patient))
52
+ Delayed::Job.enqueue(self, **@job_args.merge(:max_attempts => 1,
53
+ :run_at => @cron.next_time(Delayed::Periodic.now).utc.to_time,
54
+ :singleton => tag,
55
+ on_conflict: :patient))
54
56
  end
55
57
 
56
58
  def perform
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_support/core_ext/class/attribute'
2
4
 
3
5
  module Delayed
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Delayed
2
4
  class Pool
3
5
  include Delayed::Logging
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sinatra/base'
2
4
  require 'sinatra/json'
3
5
  require 'json'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Delayed
2
4
  class Server
3
5
  module Helpers
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yaml'
2
4
  require 'erb'
3
5
  require 'active_support/core_ext/hash/indifferent_access'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Delayed
2
4
  module Testing
3
5
  def self.run_job(job)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Delayed
2
- VERSION = "0.16.0"
4
+ VERSION = "1.0.0"
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Delayed
2
4
  module WorkQueue
3
5
  # The simplest possible implementation of a WorkQueue -- just turns around and
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pathname'
2
4
  require 'socket'
3
5
  require 'timeout'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Delayed
2
4
  module WorkQueue
3
5
  class ParentProcess
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Delayed
2
4
  module WorkQueue
3
5
  class ParentProcess
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Delayed
2
4
 
3
5
  class TimeoutError < RuntimeError; end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'health_check'
2
4
  require_relative 'process_helper'
3
5
  require 'socket'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Delayed
2
4
  class Worker
3
5
  class HealthCheck
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Delayed
2
4
  class Worker
3
5
  class NullHealthCheck < HealthCheck
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Delayed
2
4
  class Worker
3
5
  module ProcessHelper
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # New definitions for YAML to aid in serialization and deserialization of delayed jobs.
2
4
 
3
5
  require 'yaml'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Delayed
2
4
  MIN_PRIORITY = 0
3
5
  HIGH_PRIORITY = 0
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'delayed_job'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require File.expand_path("../spec_helper", __FILE__)
2
4
 
3
5
  describe 'Delayed::Backed::ActiveRecord::Job' do
@@ -17,7 +19,7 @@ describe 'Delayed::Backed::ActiveRecord::Job' do
17
19
 
18
20
  it "should recover as well as possible from a failure failing a job" do
19
21
  allow(Delayed::Job::Failed).to receive(:create).and_raise(RuntimeError)
20
- job = "test".send_later_enqueue_args :reverse, no_delay: true
22
+ job = "test".delay(ignore_transaction: true).reverse
21
23
  job_id = job.id
22
24
  proc { job.fail! }.should raise_error(RuntimeError)
23
25
  proc { Delayed::Job.find(job_id) }.should raise_error(ActiveRecord::RecordNotFound)
@@ -43,7 +45,7 @@ describe 'Delayed::Backed::ActiveRecord::Job' do
43
45
  it "should select the next job at random if enabled" do
44
46
  begin
45
47
  Delayed::Settings.select_random_from_batch = true
46
- 15.times { "test".send_later :length }
48
+ 15.times { "test".delay.length }
47
49
  founds = []
48
50
  15.times do
49
51
  job = Delayed::Job.get_and_lock_next_available('tester')
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe Delayed::CLI do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe Delayed::Daemon do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'delayed/server'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe Delayed::Settings do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe Delayed::WorkQueue::InProcess do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe Delayed::WorkQueue::ParentProcess::Client do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe Delayed::WorkQueue::ParentProcess::Server do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'fileutils'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'imperium'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe Delayed::Worker::HealthCheck do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "../spec_helper"
2
4
 
3
5
  describe Delayed::Worker do
@@ -0,0 +1,192 @@
1
+ PATH
2
+ remote: ../..
3
+ specs:
4
+ inst-jobs (0.15.12)
5
+ activerecord (>= 4.2)
6
+ activesupport (>= 4.2)
7
+ after_transaction_commit (>= 1.0, < 3)
8
+ railties (>= 4.2)
9
+ redis (> 3.0)
10
+ redis-scripting (~> 1.0.1)
11
+ rufus-scheduler (~> 3.4, < 3.5)
12
+
13
+ GEM
14
+ remote: https://rubygems.org/
15
+ specs:
16
+ actionmailer (4.2.9)
17
+ actionpack (= 4.2.9)
18
+ actionview (= 4.2.9)
19
+ activejob (= 4.2.9)
20
+ mail (~> 2.5, >= 2.5.4)
21
+ rails-dom-testing (~> 1.0, >= 1.0.5)
22
+ actionpack (4.2.9)
23
+ actionview (= 4.2.9)
24
+ activesupport (= 4.2.9)
25
+ rack (~> 1.6)
26
+ rack-test (~> 0.6.2)
27
+ rails-dom-testing (~> 1.0, >= 1.0.5)
28
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
29
+ actionview (4.2.9)
30
+ activesupport (= 4.2.9)
31
+ builder (~> 3.1)
32
+ erubis (~> 2.7.0)
33
+ rails-dom-testing (~> 1.0, >= 1.0.5)
34
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
35
+ activejob (4.2.9)
36
+ activesupport (= 4.2.9)
37
+ globalid (>= 0.3.0)
38
+ activemodel (4.2.9)
39
+ activesupport (= 4.2.9)
40
+ builder (~> 3.1)
41
+ activerecord (4.2.9)
42
+ activemodel (= 4.2.9)
43
+ activesupport (= 4.2.9)
44
+ arel (~> 6.0)
45
+ activesupport (4.2.9)
46
+ i18n (~> 0.7)
47
+ minitest (~> 5.1)
48
+ thread_safe (~> 0.3, >= 0.3.4)
49
+ tzinfo (~> 1.1)
50
+ addressable (2.5.2)
51
+ public_suffix (>= 2.0.2, < 4.0)
52
+ after_transaction_commit (1.1.2)
53
+ activerecord (>= 4.0)
54
+ arel (6.0.4)
55
+ backports (3.8.0)
56
+ builder (3.2.3)
57
+ bump (0.5.4)
58
+ byebug (9.0.6)
59
+ coderay (1.1.1)
60
+ concurrent-ruby (1.0.5)
61
+ database_cleaner (1.6.1)
62
+ diff-lcs (1.3)
63
+ erubis (2.7.0)
64
+ et-orbi (1.2.1)
65
+ tzinfo
66
+ globalid (0.4.0)
67
+ activesupport (>= 4.2.0)
68
+ httpclient (2.8.3)
69
+ i18n (0.8.6)
70
+ imperium (0.3.0)
71
+ addressable (~> 2.5.0)
72
+ httpclient (~> 2.8)
73
+ loofah (2.0.3)
74
+ nokogiri (>= 1.5.9)
75
+ mail (2.6.6)
76
+ mime-types (>= 1.16, < 4)
77
+ method_source (0.8.2)
78
+ mime-types (3.1)
79
+ mime-types-data (~> 3.2015)
80
+ mime-types-data (3.2016.0521)
81
+ mini_portile2 (2.4.0)
82
+ minitest (5.10.3)
83
+ multi_json (1.12.1)
84
+ nokogiri (1.10.4)
85
+ mini_portile2 (~> 2.4.0)
86
+ pg (0.21.0)
87
+ pry (0.10.4)
88
+ coderay (~> 1.1.0)
89
+ method_source (~> 0.8.1)
90
+ slop (~> 3.4)
91
+ public_suffix (3.0.2)
92
+ rack (1.6.8)
93
+ rack-protection (1.5.3)
94
+ rack
95
+ rack-test (0.6.3)
96
+ rack (>= 1.0)
97
+ rails (4.2.9)
98
+ actionmailer (= 4.2.9)
99
+ actionpack (= 4.2.9)
100
+ actionview (= 4.2.9)
101
+ activejob (= 4.2.9)
102
+ activemodel (= 4.2.9)
103
+ activerecord (= 4.2.9)
104
+ activesupport (= 4.2.9)
105
+ bundler (>= 1.3.0, < 2.0)
106
+ railties (= 4.2.9)
107
+ sprockets-rails
108
+ rails-deprecated_sanitizer (1.0.3)
109
+ activesupport (>= 4.2.0.alpha)
110
+ rails-dom-testing (1.0.8)
111
+ activesupport (>= 4.2.0.beta, < 5.0)
112
+ nokogiri (~> 1.6)
113
+ rails-deprecated_sanitizer (>= 1.0.1)
114
+ rails-html-sanitizer (1.0.3)
115
+ loofah (~> 2.0)
116
+ railties (4.2.9)
117
+ actionpack (= 4.2.9)
118
+ activesupport (= 4.2.9)
119
+ rake (>= 0.8.7)
120
+ thor (>= 0.18.1, < 2.0)
121
+ rake (12.0.0)
122
+ redis (4.1.2)
123
+ redis-scripting (1.0.1)
124
+ redis (>= 3.0)
125
+ rspec (3.8.0)
126
+ rspec-core (~> 3.8.0)
127
+ rspec-expectations (~> 3.8.0)
128
+ rspec-mocks (~> 3.8.0)
129
+ rspec-core (3.8.2)
130
+ rspec-support (~> 3.8.0)
131
+ rspec-expectations (3.8.4)
132
+ diff-lcs (>= 1.2.0, < 2.0)
133
+ rspec-support (~> 3.8.0)
134
+ rspec-mocks (3.8.1)
135
+ diff-lcs (>= 1.2.0, < 2.0)
136
+ rspec-support (~> 3.8.0)
137
+ rspec-support (3.8.2)
138
+ rufus-scheduler (3.4.2)
139
+ et-orbi (~> 1.0)
140
+ sinatra (1.4.8)
141
+ rack (~> 1.5)
142
+ rack-protection (~> 1.4)
143
+ tilt (>= 1.3, < 3)
144
+ sinatra-contrib (1.4.7)
145
+ backports (>= 2.0)
146
+ multi_json
147
+ rack-protection
148
+ rack-test
149
+ sinatra (~> 1.4.0)
150
+ tilt (>= 1.3, < 3)
151
+ slop (3.6.0)
152
+ sprockets (3.7.1)
153
+ concurrent-ruby (~> 1.0)
154
+ rack (> 1, < 3)
155
+ sprockets-rails (3.2.0)
156
+ actionpack (>= 4.0)
157
+ activesupport (>= 4.0)
158
+ sprockets (>= 3.0.0)
159
+ test_after_commit (0.4.1)
160
+ activerecord (>= 3.2)
161
+ thor (0.19.4)
162
+ thread_safe (0.3.6)
163
+ tilt (2.0.8)
164
+ timecop (0.7.1)
165
+ tzinfo (1.2.3)
166
+ thread_safe (~> 0.1)
167
+ wwtd (1.3.0)
168
+
169
+ PLATFORMS
170
+ ruby
171
+
172
+ DEPENDENCIES
173
+ after_transaction_commit (< 2)
174
+ bump
175
+ byebug
176
+ database_cleaner (= 1.6.1)
177
+ imperium (>= 0.2.3)
178
+ inst-jobs!
179
+ pg (< 1.0)
180
+ pry
181
+ rack-test
182
+ rails (~> 4.2.5)
183
+ rake
184
+ rspec (~> 3.8.0)
185
+ sinatra
186
+ sinatra-contrib
187
+ test_after_commit (= 0.4.1)
188
+ timecop (= 0.7.1)
189
+ wwtd (~> 1.3.0)
190
+
191
+ BUNDLED WITH
192
+ 1.17.2