belated 0.6.4 → 0.7.0
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/.github/workflows/main.yml +9 -4
- data/.rubocop.yml +2 -1
- data/CHANGELOG.md +18 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +12 -4
- data/README.md +19 -10
- data/belated.gemspec +2 -1
- data/bin/belated +9 -1
- data/lib/active_job/queue_adapters/belated_adapter.rb +27 -0
- data/lib/belated/client.rb +20 -14
- data/lib/belated/exceptions.rb +3 -0
- data/lib/belated/job_wrapper.rb +26 -13
- data/lib/belated/logging.rb +8 -0
- data/lib/belated/queue.rb +6 -3
- data/lib/belated/testing.rb +2 -2
- data/lib/belated/version.rb +1 -1
- data/lib/belated.rb +29 -20
- metadata +19 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 625adf33d85f1e94d4d7416db02a50e11fe66bfeb5fa265fa4de2c9b6f1c0750
|
4
|
+
data.tar.gz: 663fa5c0fcb7903b66324723a8cd19a771d596a88a396974d80060bf8c0bfd4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e14413f88843ed9c80391987c5891f821ce0eb43e2759d5be034bb17a9cda78f4de7a67b97f44af933013dd4aef39e0d23d91df9ecfbbf3dbead38427a925450
|
7
|
+
data.tar.gz: aef2baada5a40a7da090e71e1c490d6f901e5178bd5be05001fb53c2863e9b03b86f9b997a53ced594d40aad8eb8700e25419b1378eba13b444b3b62f48d1b65
|
data/.github/workflows/main.yml
CHANGED
@@ -4,14 +4,19 @@ on: [push,pull_request]
|
|
4
4
|
|
5
5
|
jobs:
|
6
6
|
build:
|
7
|
-
|
7
|
+
strategy:
|
8
|
+
fail-fast: false
|
9
|
+
matrix:
|
10
|
+
os: [ubuntu-latest, macos-latest]
|
11
|
+
# Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
|
12
|
+
ruby: [2.7, '3.0']
|
13
|
+
runs-on: ${{ matrix.os }}
|
8
14
|
steps:
|
9
15
|
- uses: actions/checkout@v2
|
10
16
|
- name: Set up Ruby
|
11
17
|
uses: ruby/setup-ruby@v1
|
12
18
|
with:
|
13
|
-
ruby-version:
|
14
|
-
bundler-cache: true
|
15
|
-
cache-version: 1
|
19
|
+
ruby-version: ${{ matrix.ruby }}
|
20
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
16
21
|
- name: Run the default task
|
17
22
|
run: bundle exec rake
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.7] - 2021-09-04
|
4
|
+
- ActiveJob support! Retries, exception rescuing should work as expected.
|
5
|
+
- Second Moderna jab took me out for a while... sorry for the long wait.
|
6
|
+
## [0.6.7] - 2021-08-25
|
7
|
+
|
8
|
+
- A bug fix for bad jobs bringing down client side.
|
9
|
+
- Heartbeat option for server side. It only affects jobs in the wait list, it's used to determine how often to check the future jobs queue.
|
10
|
+
## [0.6.6] - 2021-08-25
|
11
|
+
|
12
|
+
- Tests now run agains Ruby 2.6, so relaxing the version constraint.
|
13
|
+
- Add client_heartbeat option, so you can define how often you want jobs sent to the Belated server.
|
14
|
+
## [0.6.5] - 2021-08-23
|
15
|
+
|
16
|
+
- Timezone used inside Belated is all using the server time now, so it's up to the user to take care of that(using `Time.now` instead of `Time.now.utc`)
|
17
|
+
- Possible to configure host and port.
|
18
|
+
- No need to call `.start` on the client anymore.
|
19
|
+
- Logging some error and warn messages now too, instead of it all being info
|
20
|
+
|
3
21
|
## [0.6.4] - 2021-08-22
|
4
22
|
- Inline jobs for testing!
|
5
23
|
```ruby
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
belated (0.
|
4
|
+
belated (0.7.0)
|
5
5
|
drb
|
6
6
|
dry-configurable
|
7
|
+
ruby2_keywords
|
7
8
|
sorted_set
|
8
9
|
|
9
10
|
GEM
|
@@ -97,9 +98,15 @@ GEM
|
|
97
98
|
marcel (1.0.1)
|
98
99
|
method_source (1.0.0)
|
99
100
|
mini_mime (1.1.0)
|
101
|
+
mini_portile2 (2.6.1)
|
100
102
|
minitest (5.14.4)
|
101
103
|
nio4r (2.5.7)
|
102
|
-
nokogiri (1.
|
104
|
+
nokogiri (1.12.3)
|
105
|
+
mini_portile2 (~> 2.6.1)
|
106
|
+
racc (~> 1.4)
|
107
|
+
nokogiri (1.12.3-x86_64-darwin)
|
108
|
+
racc (~> 1.4)
|
109
|
+
nokogiri (1.12.3-x86_64-linux)
|
103
110
|
racc (~> 1.4)
|
104
111
|
parallel (1.20.1)
|
105
112
|
parser (3.0.2.0)
|
@@ -178,6 +185,7 @@ GEM
|
|
178
185
|
rubocop (~> 1.0)
|
179
186
|
rubocop-ast (>= 1.1.0)
|
180
187
|
ruby-progressbar (1.11.0)
|
188
|
+
ruby2_keywords (0.0.5)
|
181
189
|
set (1.0.1)
|
182
190
|
sorted_set (1.0.3)
|
183
191
|
rbtree
|
@@ -190,7 +198,6 @@ GEM
|
|
190
198
|
activesupport (>= 4.0)
|
191
199
|
sprockets (>= 3.0.0)
|
192
200
|
sqlite3 (1.4.2)
|
193
|
-
stackprof (0.2.16)
|
194
201
|
thor (1.1.0)
|
195
202
|
tzinfo (2.0.4)
|
196
203
|
concurrent-ruby (~> 1.0)
|
@@ -201,6 +208,8 @@ GEM
|
|
201
208
|
zeitwerk (2.4.2)
|
202
209
|
|
203
210
|
PLATFORMS
|
211
|
+
ruby
|
212
|
+
x86_64-darwin-19
|
204
213
|
x86_64-linux
|
205
214
|
|
206
215
|
DEPENDENCIES
|
@@ -214,7 +223,6 @@ DEPENDENCIES
|
|
214
223
|
rubocop (~> 1.7)
|
215
224
|
rubocop-discourse
|
216
225
|
sqlite3
|
217
|
-
stackprof
|
218
226
|
|
219
227
|
BUNDLED WITH
|
220
228
|
2.2.22
|
data/README.md
CHANGED
@@ -10,8 +10,6 @@ Note that Belated used to be called HardWorker. That name was already in use in
|
|
10
10
|
|
11
11
|
It uses dRuby to do the communication! Which is absolute great. No need for Redis or PostgreSQL, just Ruby standard libraries.
|
12
12
|
|
13
|
-
Note that currently the timezone is hardcoded to UTC.
|
14
|
-
|
15
13
|
Can be used with or without Rails.
|
16
14
|
|
17
15
|
Can be used if you're on a normal instance such as EC2 or Digital Ocean drop. Not if you're on a Heroku or Docker, or anything with ephemeral storage.
|
@@ -19,10 +17,6 @@ Can be used if you're on a normal instance such as EC2 or Digital Ocean drop. No
|
|
19
17
|
TODO LIST:
|
20
18
|
|
21
19
|
- Use GDBM for queue storage? That way could maybe get rid of YAML dumping and make things a bit safer. Not ordered though, so maybe keep a list of the jobs as YAML and update it sometimes? Just as backup. Or RocksDB? Would need to be configurable if you don't have something installed.
|
22
|
-
- Make DRb port configurable.
|
23
|
-
- Don't hardcode timezone to UTC.
|
24
|
-
- Add some checks to the client for proper jobs.
|
25
|
-
- Maybe support ActiveJob?
|
26
20
|
- Have a web UI.
|
27
21
|
- Have a job history
|
28
22
|
- Do some performance testing.
|
@@ -53,7 +47,15 @@ Start up Belated!
|
|
53
47
|
|
54
48
|
$ belated
|
55
49
|
|
56
|
-
|
50
|
+
If you're using Rails, just set Belated to be the ActiveJob adapter like below:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
config.active_job.adapter = :belated
|
54
|
+
```
|
55
|
+
|
56
|
+
And you're good to go!
|
57
|
+
|
58
|
+
If not, in your non-ActiveJob using program, connect to Belated and give it a job to do.
|
57
59
|
Sample below:
|
58
60
|
|
59
61
|
```ruby
|
@@ -86,8 +88,6 @@ Then,
|
|
86
88
|
```ruby
|
87
89
|
# Get the client
|
88
90
|
client = Belated::Client.instance
|
89
|
-
# Start the client, only need to do this once
|
90
|
-
client.start unless client.started?
|
91
91
|
```
|
92
92
|
|
93
93
|
and you can use the client!
|
@@ -137,6 +137,16 @@ Path to Rails project.
|
|
137
137
|
|
138
138
|
$ bundle exec belated --workers=10
|
139
139
|
|
140
|
+
Other available settings:
|
141
|
+
|
142
|
+
$ bundle exec belated --host=1.1.1.1 --port=1234
|
143
|
+
# druby://1.1.1.1:1234
|
144
|
+
$ bundle exec belated --env=test
|
145
|
+
# environment
|
146
|
+
$ bundle exec belated --client_heartbeat=10
|
147
|
+
# how often client sends jobs to server, default is once every 5 seconds
|
148
|
+
|
149
|
+
|
140
150
|
Number of workers.
|
141
151
|
|
142
152
|
## Testing
|
@@ -146,7 +156,6 @@ When testing, you can require `belated/testing` and then call `Belated::Testing.
|
|
146
156
|
```ruby
|
147
157
|
`belated/testing`
|
148
158
|
c = Belated::Client.instance
|
149
|
-
c.start
|
150
159
|
c.perform(proc { 2/ 1}) # Tries to push the job to the drb backend
|
151
160
|
# <Belated::JobWrapper:0x00005654bc2db1f0 @at=nil, @completed=false, @id="95e4dc6a-1876-4adf-ae0f-5ae902f5f024", @job=#<Proc:0x00005654bc2db330 (irb):3>, @max_retries=5, @proc_klass=true, @retries=0>
|
152
161
|
Belated::Testing.inline! # Sidekiq-inspired, now jobs run inline
|
data/belated.gemspec
CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
|
|
15
15
|
).gsub(/\s+/, ' ').strip
|
16
16
|
spec.homepage = 'https://github.com/sampokuokkanen/belated'
|
17
17
|
spec.license = 'MIT'
|
18
|
-
spec.required_ruby_version = Gem::Requirement.new('>= 2.
|
18
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
|
19
19
|
|
20
20
|
spec.metadata['homepage_uri'] = spec.homepage
|
21
21
|
spec.metadata['source_code_uri'] = spec.homepage
|
@@ -33,6 +33,7 @@ Gem::Specification.new do |spec|
|
|
33
33
|
# Uncomment to register a new dependency of your gem
|
34
34
|
spec.add_dependency 'drb'
|
35
35
|
spec.add_dependency 'dry-configurable'
|
36
|
+
spec.add_dependency 'ruby2_keywords'
|
36
37
|
spec.add_dependency 'sorted_set'
|
37
38
|
spec.add_development_dependency 'byebug'
|
38
39
|
|
data/bin/belated
CHANGED
@@ -28,9 +28,17 @@ OptionParser.new { |opts|
|
|
28
28
|
Belated.config.env = env
|
29
29
|
end
|
30
30
|
|
31
|
-
opts.on('-c=CONNECT', '--connect=CONNECT', 'Start dRuby connection, default true') do |connect|
|
31
|
+
opts.on('-c=CONNECT', '--connect=CONNECT', 'Start dRuby connection, default true, use for testing only') do |connect|
|
32
32
|
Belated.config.connect = connect == 'true'
|
33
33
|
end
|
34
|
+
|
35
|
+
opts.on('-h=HOST', '--host=HOST', 'dRuby host') do |host|
|
36
|
+
Belated.config.host = host
|
37
|
+
end
|
38
|
+
|
39
|
+
opts.on('-p=PORT', '--port=PORT', 'dRuby port') do |port|
|
40
|
+
Belated.config.port = port
|
41
|
+
end
|
34
42
|
}.parse!
|
35
43
|
|
36
44
|
instance = Belated.instance
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'belated'
|
4
|
+
|
5
|
+
module ActiveJob # :nodoc:
|
6
|
+
module QueueAdapters # :nodoc:
|
7
|
+
# The adapter in charge of handling ActiveJob integration.
|
8
|
+
# WIP
|
9
|
+
class BelatedAdapter
|
10
|
+
def instance
|
11
|
+
@instance ||= Belated::Client.instance
|
12
|
+
rescue StandardError
|
13
|
+
@instance = Belated::Client.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def enqueue(job) # :nodoc:
|
17
|
+
Rails.logger.info "Belated got job #{job}"
|
18
|
+
instance.perform(job, active_job: true)
|
19
|
+
end
|
20
|
+
|
21
|
+
def enqueue_at(job, timestamp) # :nodoc:
|
22
|
+
Rails.logger.info "Belated got job #{job} to be performed at #{Time.at(timestamp)}"
|
23
|
+
instance.perform_belated(job, at: timestamp, active_job: true)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/belated/client.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'belated/job_wrapper'
|
2
|
+
require 'belated/exceptions'
|
2
3
|
require 'singleton'
|
3
4
|
class Belated
|
4
5
|
# The client class is responsible for managing the connection to the
|
@@ -46,15 +47,12 @@ class Belated
|
|
46
47
|
Thread.new do
|
47
48
|
loop do
|
48
49
|
delete_from_table
|
49
|
-
sleep
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
bank.push(wrapper)
|
56
|
-
sleep 5
|
57
|
-
end
|
50
|
+
sleep Belated.client_heartbeat and next if bank.empty?
|
51
|
+
|
52
|
+
bank.length.times do
|
53
|
+
queue.push(wrapper = bank.pop)
|
54
|
+
rescue DRb::DRbConnError
|
55
|
+
bank.push(wrapper)
|
58
56
|
end
|
59
57
|
end
|
60
58
|
end
|
@@ -76,10 +74,11 @@ class Belated
|
|
76
74
|
# @param at [Date] - The time at which the job should be executed.
|
77
75
|
# @param max_retries [Integer] - Times the job should be retried if it fails.
|
78
76
|
# @return [JobWrapper] - The job wrapper for the queue.
|
79
|
-
def perform(job, at: nil, max_retries: 5)
|
80
|
-
|
77
|
+
def perform(job, at: nil, max_retries: 5, active_job: false)
|
78
|
+
start unless started?
|
79
|
+
return unless proper_job?(job)
|
81
80
|
|
82
|
-
job_wrapper = wrap_job(job, at: at, max_retries: max_retries)
|
81
|
+
job_wrapper = wrap_job(job, at: at.to_f, max_retries: max_retries, active_job: active_job)
|
83
82
|
bank.push(job_wrapper)
|
84
83
|
@mutex.synchronize do
|
85
84
|
proc_table[job_wrapper.object_id] = job_wrapper if job_wrapper.proc_klass
|
@@ -92,10 +91,17 @@ class Belated
|
|
92
91
|
|
93
92
|
private
|
94
93
|
|
95
|
-
def
|
94
|
+
def proper_job?(job)
|
95
|
+
return true if job.respond_to?(:call) || job.respond_to?(:perform)
|
96
|
+
|
97
|
+
warn 'job does not implement .call nor .perform!'
|
98
|
+
false
|
99
|
+
end
|
100
|
+
|
101
|
+
def wrap_job(job, at:, max_retries:, active_job:)
|
96
102
|
return job if job.is_a?(JobWrapper)
|
97
103
|
|
98
|
-
JobWrapper.new(job: job, at: at, max_retries: max_retries)
|
104
|
+
JobWrapper.new(job: job, at: at, max_retries: max_retries, active_job: active_job)
|
99
105
|
end
|
100
106
|
|
101
107
|
def drb_connected?
|
data/lib/belated/job_wrapper.rb
CHANGED
@@ -13,16 +13,17 @@ class Belated
|
|
13
13
|
class JobWrapper
|
14
14
|
include Comparable
|
15
15
|
include Logging
|
16
|
-
attr_accessor :retries, :max_retries, :id, :job, :at, :completed, :proc_klass
|
16
|
+
attr_accessor :retries, :max_retries, :id, :job, :at, :completed, :proc_klass, :error, :active_job
|
17
17
|
|
18
|
-
def initialize(job:, max_retries: 5, at: nil)
|
18
|
+
def initialize(job:, max_retries: 5, at: nil, active_job: false)
|
19
19
|
self.retries = 0
|
20
20
|
self.max_retries = max_retries
|
21
|
-
self.id = SecureRandom.uuid
|
21
|
+
self.id = job.respond_to?(:job_id) ? job.job_id : SecureRandom.uuid
|
22
22
|
self.job = job
|
23
23
|
self.at = at
|
24
24
|
self.completed = false
|
25
25
|
self.proc_klass = job.instance_of?(Proc)
|
26
|
+
self.active_job = active_job
|
26
27
|
end
|
27
28
|
|
28
29
|
def <=>(other)
|
@@ -31,11 +32,7 @@ class Belated
|
|
31
32
|
|
32
33
|
# rubocop:disable Lint/RescueException
|
33
34
|
def perform
|
34
|
-
resp =
|
35
|
-
job.call
|
36
|
-
else
|
37
|
-
job.perform
|
38
|
-
end
|
35
|
+
resp = execute
|
39
36
|
self.completed = true
|
40
37
|
resp
|
41
38
|
rescue Exception => e
|
@@ -43,17 +40,33 @@ class Belated
|
|
43
40
|
when Interrupt, SignalException
|
44
41
|
raise e
|
45
42
|
else
|
46
|
-
retry_job
|
47
|
-
"Error while executing job, #{e.inspect}. Retry #{retries} of #{max_retries}"
|
43
|
+
retry_job(e)
|
44
|
+
"Error while executing job #{job.inspect}, #{e.inspect}. Retry #{retries} of #{max_retries}"
|
48
45
|
end
|
49
46
|
end
|
47
|
+
|
50
48
|
# rubocop:enable Lint/RescueException
|
49
|
+
def execute
|
50
|
+
if active_job
|
51
|
+
ActiveJob::Base.execute job.serialize
|
52
|
+
elsif job.respond_to?(:call)
|
53
|
+
job.call
|
54
|
+
elsif job.respond_to?(:arguments)
|
55
|
+
job.perform(*job.arguments)
|
56
|
+
else
|
57
|
+
job.perform
|
58
|
+
end
|
59
|
+
end
|
51
60
|
|
52
|
-
def retry_job
|
61
|
+
def retry_job(error)
|
53
62
|
self.retries += 1
|
54
|
-
|
63
|
+
if retries > max_retries
|
64
|
+
self.error = error
|
65
|
+
return
|
66
|
+
end
|
55
67
|
|
56
|
-
|
68
|
+
seconds_to_retry = $TESTING ? 0.05 : retries.next**4
|
69
|
+
self.at = (Time.now + seconds_to_retry).to_f
|
57
70
|
log "Job #{id} failed, retrying at #{at}"
|
58
71
|
Belated.job_list.push(self)
|
59
72
|
end
|
data/lib/belated/logging.rb
CHANGED
data/lib/belated/queue.rb
CHANGED
@@ -19,15 +19,18 @@ class Belated
|
|
19
19
|
|
20
20
|
def initialize(queue: Thread::Queue.new, future_jobs: SortedSet.new)
|
21
21
|
@queue = queue
|
22
|
+
@mutex = Mutex.new
|
22
23
|
self.future_jobs = future_jobs
|
23
24
|
end
|
24
25
|
|
25
26
|
def push(job)
|
26
27
|
if job.is_a?(Symbol) || job.at.nil? ||
|
27
|
-
job.at <= Time.now.
|
28
|
+
job.at <= Time.now.to_f
|
28
29
|
@queue.push(job)
|
29
30
|
else
|
30
|
-
@
|
31
|
+
@mutex.synchronize do
|
32
|
+
@future_jobs << job
|
33
|
+
end
|
31
34
|
end
|
32
35
|
end
|
33
36
|
|
@@ -54,7 +57,7 @@ class Belated
|
|
54
57
|
|
55
58
|
jobs = YAML.load(File.binread(FILE_NAME))
|
56
59
|
jobs.each do |job|
|
57
|
-
if job.at && job.at > Time.now.
|
60
|
+
if job.at && job.at > Time.now.to_f
|
58
61
|
future_jobs.push(job)
|
59
62
|
else
|
60
63
|
@queue.push(job)
|
data/lib/belated/testing.rb
CHANGED
@@ -22,7 +22,7 @@ class Belated
|
|
22
22
|
# A client that can perform jobs inline
|
23
23
|
class Client
|
24
24
|
alias old_perform perform
|
25
|
-
def perform(job, at: nil, max_retries: 5)
|
25
|
+
def perform(job, at: nil, max_retries: 5, active_job: false)
|
26
26
|
if Belated::Testing.inline?
|
27
27
|
if job.respond_to?(:call)
|
28
28
|
job.call
|
@@ -30,7 +30,7 @@ class Belated
|
|
30
30
|
job.perform
|
31
31
|
end
|
32
32
|
else
|
33
|
-
old_perform(job, at: at, max_retries: max_retries)
|
33
|
+
old_perform(job, at: at, max_retries: max_retries, active_job: active_job)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
data/lib/belated/version.rb
CHANGED
data/lib/belated.rb
CHANGED
@@ -22,7 +22,6 @@ class Belated
|
|
22
22
|
extend Dry::Configurable
|
23
23
|
include Logging
|
24
24
|
include Singleton unless $TESTING
|
25
|
-
URI = 'druby://localhost:8788'
|
26
25
|
@@queue = Belated::Queue.new
|
27
26
|
|
28
27
|
setting :rails, true
|
@@ -32,6 +31,11 @@ class Belated
|
|
32
31
|
setting :environment, 'development', reader: true
|
33
32
|
setting :logger, Logger.new($stdout), reader: true
|
34
33
|
setting :log_level, :info, reader: true
|
34
|
+
setting :host, 'localhost', reader: true
|
35
|
+
setting :port, '8788', reader: true
|
36
|
+
setting :heartbeat, 1, reader: true
|
37
|
+
setting :client_heartbeat, 5, reader: true
|
38
|
+
URI = "druby://#{Belated.host}:#{Belated.port}"
|
35
39
|
|
36
40
|
# Since it's running as a singleton, we need something to start it up.
|
37
41
|
# Aliased for testing purposes.
|
@@ -53,12 +57,15 @@ class Belated
|
|
53
57
|
|
54
58
|
# Handles connection to DRb server.
|
55
59
|
def connect!
|
60
|
+
i = 0
|
56
61
|
DRb.start_service(URI, @@queue, verbose: true)
|
57
62
|
rescue DRb::DRbConnError, Errno::EADDRINUSE
|
58
|
-
|
63
|
+
sleep 0.1 and retry if (i += 1) < 5
|
64
|
+
error 'Could not connect to DRb server.'
|
59
65
|
end
|
60
66
|
|
61
67
|
def trap_signals
|
68
|
+
pp 'trap'
|
62
69
|
%w[INT TERM].each do |signal|
|
63
70
|
Signal.trap(signal) do
|
64
71
|
@worker_list.length.times do
|
@@ -90,18 +97,17 @@ class Belated
|
|
90
97
|
|
91
98
|
def enqueue_future_jobs
|
92
99
|
loop do
|
93
|
-
sleep 0.1
|
94
100
|
job = @@queue.future_jobs.min
|
95
101
|
if job.nil?
|
96
|
-
sleep
|
102
|
+
sleep Belated.heartbeat
|
97
103
|
next
|
98
104
|
end
|
99
|
-
if job.at <= Time.now.
|
105
|
+
if job.at <= Time.now.to_f
|
100
106
|
log "Deleting #{@@queue.future_jobs.delete(job)} from future jobs"
|
101
107
|
@@queue.push(job)
|
102
108
|
end
|
103
109
|
rescue DRb::DRbConnError
|
104
|
-
|
110
|
+
error 'DRb connection error!!!!!!'
|
105
111
|
log stats
|
106
112
|
end
|
107
113
|
end
|
@@ -151,19 +157,25 @@ class Belated
|
|
151
157
|
}
|
152
158
|
end
|
153
159
|
|
154
|
-
|
155
|
-
|
156
|
-
|
160
|
+
class << self
|
161
|
+
def find(job_id)
|
162
|
+
@@queue.future_jobs.find { |job| job.id == job_id }
|
157
163
|
end
|
158
|
-
clear_queue!
|
159
|
-
end
|
160
164
|
|
161
|
-
|
162
|
-
|
163
|
-
|
165
|
+
def kill_and_clear_queue!
|
166
|
+
@worker_list&.each do |worker|
|
167
|
+
Thread.kill(worker)
|
168
|
+
end
|
169
|
+
clear_queue!
|
170
|
+
end
|
164
171
|
|
165
|
-
|
166
|
-
|
172
|
+
def clear_queue!
|
173
|
+
@@queue.clear
|
174
|
+
end
|
175
|
+
|
176
|
+
def fetch_job
|
177
|
+
@@queue.pop
|
178
|
+
end
|
167
179
|
end
|
168
180
|
|
169
181
|
def job_list
|
@@ -173,8 +185,5 @@ class Belated
|
|
173
185
|
def self.job_list
|
174
186
|
@@queue
|
175
187
|
end
|
176
|
-
|
177
|
-
class Error < StandardError; end
|
178
188
|
end
|
179
|
-
|
180
|
-
require 'belated/rails' if defined?(::Rails::Engine)
|
189
|
+
require 'active_job/queue_adapters/belated_adapter' if defined?(::Rails)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: belated
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sampo Kuokkanen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: drb
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: ruby2_keywords
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: sorted_set
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -92,8 +106,10 @@ files:
|
|
92
106
|
- bin/bundle
|
93
107
|
- bin/console
|
94
108
|
- bin/setup
|
109
|
+
- lib/active_job/queue_adapters/belated_adapter.rb
|
95
110
|
- lib/belated.rb
|
96
111
|
- lib/belated/client.rb
|
112
|
+
- lib/belated/exceptions.rb
|
97
113
|
- lib/belated/job.rb
|
98
114
|
- lib/belated/job_wrapper.rb
|
99
115
|
- lib/belated/logging.rb
|
@@ -117,7 +133,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
117
133
|
requirements:
|
118
134
|
- - ">="
|
119
135
|
- !ruby/object:Gem::Version
|
120
|
-
version: 2.
|
136
|
+
version: 2.6.0
|
121
137
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
138
|
requirements:
|
123
139
|
- - ">="
|