clockwork 2.0.4 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +36 -0
- data/CHANGELOG.md +15 -0
- data/Gemfile +5 -0
- data/README.md +4 -2
- data/clockwork.gemspec +1 -1
- data/lib/clockwork/database_events/event_store.rb +1 -0
- data/lib/clockwork/database_events/synchronizer.rb +0 -2
- data/lib/clockwork/event.rb +9 -0
- data/lib/clockwork/manager.rb +10 -2
- data/lib/clockwork.rb +1 -0
- data/test/at_test.rb +1 -1
- data/test/clockwork_test.rb +17 -1
- data/test/database_events/event_store_test.rb +1 -0
- data/test/database_events/support/active_record_fake.rb +2 -2
- data/test/database_events/synchronizer_test.rb +1 -1
- data/test/database_events/test_helpers.rb +30 -6
- data/test/manager_test.rb +1 -1
- data/test/signal_test.rb +1 -1
- metadata +7 -10
- data/.travis.yml +0 -18
- data/gemfiles/activesupport4.gemfile +0 -11
- data/gemfiles/activesupport5.gemfile +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92b0e84804fd39ef988e03c0f76cff4bf6e8af060cc395b150f24622c5a8a43d
|
4
|
+
data.tar.gz: 0d217fe414875b7124f3b0362e6e4fd8c3eff240d09d67bd88a0ae4dc695e934
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c1b94426a6f419580db0f67ebdb88f20c17a758a055b242c1cc59c40664e4cea0c0f61bda47c06ea3327d95e507cd9bdde9a4d296f099b15bf6903115fcf840
|
7
|
+
data.tar.gz: ccb09e88187c401b435292d36fd4abe4ac82794dec361ff20cdac5e8e458f6225e429c6a1ee2c3d94724a6e3d4bc95f028806aae849662d277a2ff0669668c27
|
@@ -0,0 +1,36 @@
|
|
1
|
+
name: Tests
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ master ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
build:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
strategy:
|
13
|
+
matrix:
|
14
|
+
ruby: [ "2.7", "3.0", "3.1", "3.2", jruby ]
|
15
|
+
active_support: [ "6.0", "7.0" ]
|
16
|
+
exclude:
|
17
|
+
- ruby: "3.0"
|
18
|
+
active_support: "6.0"
|
19
|
+
- ruby: "3.1"
|
20
|
+
active_support: "6.0"
|
21
|
+
- ruby: "3.2"
|
22
|
+
active_support: "6.0"
|
23
|
+
name: Ruby ${{ matrix.ruby }} - ActiveSupport ${{ matrix.active_support }}
|
24
|
+
env:
|
25
|
+
ACTIVE_SUPPORT_VERSION: ${{ matrix.active_support }}
|
26
|
+
steps:
|
27
|
+
- uses: actions/checkout@v3
|
28
|
+
- uses: ruby/setup-ruby@v1
|
29
|
+
with:
|
30
|
+
ruby-version: ${{ matrix.ruby }}
|
31
|
+
bundler-cache: true
|
32
|
+
- name: Run Tests
|
33
|
+
env:
|
34
|
+
RUBYOPT: "-W:deprecated" # Show Ruby's deprecation warnings
|
35
|
+
run: |
|
36
|
+
bundle exec rake
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
## 3.0.1 ##
|
2
|
+
|
3
|
+
* Notify error using error handler if configured (49075c2)
|
4
|
+
|
5
|
+
## 3.0.0 ##
|
6
|
+
|
7
|
+
* BREAKING CHANGE: drop Rubinius support
|
8
|
+
* add Ruby 3.0 support (65d71f)
|
9
|
+
* fix a bug with OpenStruct (15eb030)
|
10
|
+
* allow `:skip_first_run` in database events (429bc0a)
|
11
|
+
* add rescue to prevent hung up by exception (cc1b7c9)
|
12
|
+
* fix CI errors (16b4e19 & e4480ea)
|
13
|
+
* fix a compatibility bug with Rails 7 (5907bc7)
|
14
|
+
* Add "Finished" log with duration and error summary (66419ab)
|
15
|
+
|
1
16
|
## 2.0.4 ##
|
2
17
|
|
3
18
|
* Reverts the breaking changes in PR #18 that went out in patch 2.0.3
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Clockwork - a clock process to replace cron [![Build Status](https://api.travis-ci.
|
1
|
+
Clockwork - a clock process to replace cron [![Build Status](https://api.travis-ci.com/Rykian/clockwork.svg?branch=master)](https://travis-ci.org/Rykian/clockwork)
|
2
2
|
===========================================
|
3
3
|
|
4
4
|
Cron is non-ideal for running scheduled application tasks, especially in an app
|
@@ -171,6 +171,8 @@ When one of the events is ready to be run (based on it's `frequency`, and possib
|
|
171
171
|
|
172
172
|
- `tz` *(optional)* returning the timezone to use (default is the local timezone)
|
173
173
|
|
174
|
+
- `skip_first_run` *(optional)* self explanatory, see [dedicated section](#skip_first_run)
|
175
|
+
|
174
176
|
#### Example Setup
|
175
177
|
|
176
178
|
Here's an example of one way of setting up your ActiveRecord models:
|
@@ -502,7 +504,7 @@ end
|
|
502
504
|
```
|
503
505
|
|
504
506
|
In addition, Clockwork also supports `:before_tick`, `:after_tick`, `:before_run`, and `:after_run` callbacks.
|
505
|
-
All callbacks are optional. The `tick` callbacks run every tick (a tick being whatever your `:sleep_timeout`
|
507
|
+
All callbacks are optional. All `before` callbacks must return a truthy value otherwise the job will not run. The `tick` callbacks run every tick (a tick being whatever your `:sleep_timeout`
|
506
508
|
is set to, default is 1 second):
|
507
509
|
|
508
510
|
```ruby
|
data/clockwork.gemspec
CHANGED
@@ -119,6 +119,7 @@ module Clockwork
|
|
119
119
|
options[:if] = ->(time){ model.if?(time) } if model.respond_to?(:if?)
|
120
120
|
options[:tz] = model.tz if model.respond_to?(:tz)
|
121
121
|
options[:ignored_attributes] = model.ignored_attributes if model.respond_to?(:ignored_attributes)
|
122
|
+
options[:skip_first_run] = model.skip_first_run if model.respond_to?(:skip_first_run)
|
122
123
|
|
123
124
|
# store the state of the model at time of registering so we can
|
124
125
|
# easily compare and determine if state has changed later
|
data/lib/clockwork/event.rb
CHANGED
@@ -55,10 +55,19 @@ module Clockwork
|
|
55
55
|
|
56
56
|
private
|
57
57
|
def execute
|
58
|
+
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
59
|
+
error = nil
|
60
|
+
|
58
61
|
@block.call(@job, @last)
|
59
62
|
rescue => e
|
63
|
+
error = e
|
60
64
|
@manager.log_error e
|
61
65
|
@manager.handle_error e
|
66
|
+
ensure
|
67
|
+
finish = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
68
|
+
duration = ((finish - start) * 1000).round # milliseconds
|
69
|
+
|
70
|
+
@manager.log "Finished '#{self}' duration_ms=#{duration} error=#{error.inspect}"
|
62
71
|
end
|
63
72
|
|
64
73
|
def elapsed_ready?(t)
|
data/lib/clockwork/manager.rb
CHANGED
@@ -37,7 +37,7 @@ module Clockwork
|
|
37
37
|
|
38
38
|
def error_handler(&block)
|
39
39
|
@error_handler = block if block_given?
|
40
|
-
@error_handler
|
40
|
+
@error_handler if instance_variable_defined?("@error_handler")
|
41
41
|
end
|
42
42
|
|
43
43
|
def on(event, options={}, &block)
|
@@ -160,7 +160,15 @@ module Clockwork
|
|
160
160
|
|
161
161
|
private
|
162
162
|
def events_to_run(t)
|
163
|
-
@events.select
|
163
|
+
@events.select do |event|
|
164
|
+
begin
|
165
|
+
event.run_now?(t)
|
166
|
+
rescue => e
|
167
|
+
log_error(e)
|
168
|
+
handle_error(e)
|
169
|
+
false
|
170
|
+
end
|
171
|
+
end
|
164
172
|
end
|
165
173
|
|
166
174
|
def register(period, job, block, options)
|
data/lib/clockwork.rb
CHANGED
data/test/at_test.rb
CHANGED
data/test/clockwork_test.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path('../../lib/clockwork', __FILE__)
|
2
2
|
require 'minitest/autorun'
|
3
|
-
require 'mocha/
|
3
|
+
require 'mocha/minitest'
|
4
4
|
|
5
5
|
describe Clockwork do
|
6
6
|
before do
|
@@ -27,6 +27,7 @@ describe Clockwork do
|
|
27
27
|
|
28
28
|
assert run
|
29
29
|
assert @log_output.string.include?('Triggering')
|
30
|
+
assert @log_output.string.include?('Finished')
|
30
31
|
end
|
31
32
|
|
32
33
|
it 'should log event correctly' do
|
@@ -39,6 +40,21 @@ describe Clockwork do
|
|
39
40
|
Clockwork.run
|
40
41
|
assert run
|
41
42
|
assert @log_output.string.include?("Triggering 'an event'")
|
43
|
+
assert_match(/Finished 'an event' duration_ms=\d+ error=nil/, @log_output.string)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should log exceptions' do
|
47
|
+
run = false
|
48
|
+
Clockwork.handler do |job|
|
49
|
+
run = job == 'an event'
|
50
|
+
raise 'boom'
|
51
|
+
end
|
52
|
+
Clockwork.every(1.minute, 'an event')
|
53
|
+
Clockwork.manager.stubs(:run_tick_loop).returns(Clockwork.manager.tick)
|
54
|
+
Clockwork.run
|
55
|
+
assert run
|
56
|
+
assert @log_output.string.include?("Triggering 'an event'")
|
57
|
+
assert_match(/Finished 'an event' duration_ms=\d+ error=#<RuntimeError: boom>/, @log_output.string)
|
42
58
|
end
|
43
59
|
|
44
60
|
it 'should pass event without modification to handler' do
|
@@ -36,19 +36,35 @@ end
|
|
36
36
|
|
37
37
|
class DatabaseEventModel
|
38
38
|
include ActiveRecordFake
|
39
|
-
attr_accessor :
|
39
|
+
attr_accessor :frequency, :at, :tz
|
40
40
|
|
41
41
|
def name
|
42
|
-
@name
|
42
|
+
if instance_variable_defined?("@name")
|
43
|
+
@name
|
44
|
+
else
|
45
|
+
"#{self.class}:#{id}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def name=(name)
|
50
|
+
@name = name
|
43
51
|
end
|
44
52
|
end
|
45
53
|
|
46
54
|
class DatabaseEventModel2
|
47
55
|
include ActiveRecordFake
|
48
|
-
attr_accessor :
|
56
|
+
attr_accessor :frequency, :at, :tz
|
49
57
|
|
50
58
|
def name
|
51
|
-
@name
|
59
|
+
if instance_variable_defined?("@name")
|
60
|
+
@name
|
61
|
+
else
|
62
|
+
"#{self.class}:#{id}"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def name=(name)
|
67
|
+
@name = name
|
52
68
|
end
|
53
69
|
end
|
54
70
|
|
@@ -59,10 +75,18 @@ end
|
|
59
75
|
|
60
76
|
class DatabaseEventModelWithIf
|
61
77
|
include ActiveRecordFake
|
62
|
-
attr_accessor :
|
78
|
+
attr_accessor :frequency, :at, :tz, :if_state
|
63
79
|
|
64
80
|
def name
|
65
|
-
@name
|
81
|
+
if instance_variable_defined?("@name")
|
82
|
+
@name
|
83
|
+
else
|
84
|
+
"#{self.class}:#{id}"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def name=(name)
|
89
|
+
@name = name
|
66
90
|
end
|
67
91
|
|
68
92
|
def if?(time)
|
data/test/manager_test.rb
CHANGED
data/test/signal_test.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clockwork
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Wiggins
|
8
8
|
- tomykaira
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-12-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: tzinfo
|
@@ -121,8 +121,8 @@ extensions: []
|
|
121
121
|
extra_rdoc_files:
|
122
122
|
- README.md
|
123
123
|
files:
|
124
|
+
- ".github/workflows/tests.yml"
|
124
125
|
- ".gitignore"
|
125
|
-
- ".travis.yml"
|
126
126
|
- CHANGELOG.md
|
127
127
|
- Gemfile
|
128
128
|
- LICENSE
|
@@ -133,8 +133,6 @@ files:
|
|
133
133
|
- clockwork.gemspec
|
134
134
|
- clockworkd.1
|
135
135
|
- example.rb
|
136
|
-
- gemfiles/activesupport4.gemfile
|
137
|
-
- gemfiles/activesupport5.gemfile
|
138
136
|
- lib/clockwork.rb
|
139
137
|
- lib/clockwork/at.rb
|
140
138
|
- lib/clockwork/database_events.rb
|
@@ -159,7 +157,7 @@ homepage: http://github.com/Rykian/clockwork
|
|
159
157
|
licenses:
|
160
158
|
- MIT
|
161
159
|
metadata: {}
|
162
|
-
post_install_message:
|
160
|
+
post_install_message:
|
163
161
|
rdoc_options: []
|
164
162
|
require_paths:
|
165
163
|
- lib
|
@@ -174,9 +172,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
174
172
|
- !ruby/object:Gem::Version
|
175
173
|
version: '0'
|
176
174
|
requirements: []
|
177
|
-
|
178
|
-
|
179
|
-
signing_key:
|
175
|
+
rubygems_version: 3.3.7
|
176
|
+
signing_key:
|
180
177
|
specification_version: 4
|
181
178
|
summary: A scheduler process to replace cron.
|
182
179
|
test_files:
|
data/.travis.yml
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
sudo: false
|
3
|
-
cache: bundler
|
4
|
-
before_install:
|
5
|
-
- gem update --system
|
6
|
-
# This is required to support ActiveSupport 4
|
7
|
-
# https://docs.travis-ci.com/user/languages/ruby/#bundler-20
|
8
|
-
- gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
|
9
|
-
- gem install bundler -v '< 2'
|
10
|
-
rvm:
|
11
|
-
- 2.3.8
|
12
|
-
- 2.4.5
|
13
|
-
- 2.5.3
|
14
|
-
- jruby-9.1.17.0
|
15
|
-
- jruby-9.2.6.0
|
16
|
-
gemfile:
|
17
|
-
- gemfiles/activesupport4.gemfile
|
18
|
-
- gemfiles/activesupport5.gemfile
|