clockwork 2.0.4 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7ad11e2b8e79db572d4240dd9ce2065067b22514919d4debc3758065b438ebca
4
- data.tar.gz: 5dec51edf5bbd101a002e8c6ede3f11918441d75281b2baff3091bc0995721c4
3
+ metadata.gz: 81357fe2cd463fcf64f263400fd180f02a2c6e14fc281c32cd5098dbe6971487
4
+ data.tar.gz: 2eec51851477a00654c88adaa7b5e4b5abac252fa808957d1f3cfafda49572f4
5
5
  SHA512:
6
- metadata.gz: f06770eaf4eb2b473ee165a00ddf7b6326f957ccfbf1eb71ee65a3e4a840ea8a42fe052a52a7032f7b786677bad54e94bc58a7f3961a44bb404c16685dcddc48
7
- data.tar.gz: 5a60bddb9ae7b7312e8df9a4b01a022d9072a3a4f2fdb7f5790f03a61cf8b31a0d6fc4a76c3b80abeee63eeb269447922b2c065982497f2d6f7becd33082f78e
6
+ metadata.gz: ee46e6ec0c2da3bda8c38ab24ad29b50d01d058e0e1580c6cc2c0f1a5b000a649453ddc780b5d007b37c25f3a8380303f00344b9c171f5febb2742b11127c25c
7
+ data.tar.gz: 1d64979d6c6a494963bf27283aff3da36345441be828c0496fc25858e6c0834d87aaf8283ea3cf7d3bf396dea30e0d27c681b2ea52ab8e04681440491ddbef20
data/.travis.yml CHANGED
@@ -9,10 +9,22 @@ before_install:
9
9
  - gem install bundler -v '< 2'
10
10
  rvm:
11
11
  - 2.3.8
12
- - 2.4.5
13
- - 2.5.3
12
+ - 2.4.9
13
+ - 2.5.7
14
+ - 2.6.5
15
+ - 2.7.0
16
+ - 3.0.2
14
17
  - jruby-9.1.17.0
15
- - jruby-9.2.6.0
18
+ - jruby-9.2.11.0
16
19
  gemfile:
17
20
  - gemfiles/activesupport4.gemfile
18
21
  - gemfiles/activesupport5.gemfile
22
+ - gemfiles/activesupport6.gemfile
23
+ matrix:
24
+ exclude:
25
+ - rvm: 2.3.8
26
+ gemfile: gemfiles/activesupport6.gemfile
27
+ - rvm: 2.4.9
28
+ gemfile: gemfiles/activesupport6.gemfile
29
+ - rvm: jruby-9.1.17.0
30
+ gemfile: gemfiles/activesupport6.gemfile
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## 3.0.0 ##
2
+
3
+ * BREAKING CHANGE: drop Rubinius support
4
+ * add Ruby 3.0 support (65d71f)
5
+ * fix a bug with OpenStruct (15eb030)
6
+ * allow `:skip_first_run` in database events (429bc0a)
7
+ * add rescue to prevent hung up by exception (cc1b7c9)
8
+ * fix CI errors (16b4e19 & e4480ea)
9
+ * fix a compatibility bug with Rails 7 (5907bc7)
10
+ * Add "Finished" log with duration and error summary (66419ab)
11
+
1
12
  ## 2.0.4 ##
2
13
 
3
14
  * Reverts the breaking changes in PR #18 that went out in patch 2.0.3
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- Clockwork - a clock process to replace cron [![Build Status](https://api.travis-ci.org/Rykian/clockwork.png?branch=master)](https://travis-ci.org/Rykian/clockwork)
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "clockwork"
3
- s.version = "2.0.4"
3
+ s.version = "3.0.0"
4
4
 
5
5
  s.authors = ["Adam Wiggins", "tomykaira"]
6
6
  s.license = 'MIT'
@@ -1,11 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- platforms :rbx do
4
- gem 'rubysl', '~> 2.0'
5
- gem 'rubysl-test-unit'
6
- gem 'rubinius-developer_tools'
7
- end
8
-
9
3
  gem 'activesupport', '~> 4.2'
10
4
  gem 'minitest', '~> 5.0'
11
5
  gemspec :path=>"../"
@@ -1,11 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- platforms :rbx do
4
- gem 'rubysl', '~> 2.0'
5
- gem 'rubysl-test-unit'
6
- gem 'rubinius-developer_tools'
7
- end
8
-
9
3
  gem 'activesupport', '~> 5.0'
10
4
  gem 'minitest', '~> 5.0'
11
5
  gemspec :path=>"../"
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'activesupport', '~> 6.0'
4
+ gem 'minitest', '~> 5.0'
5
+ gemspec :path=>"../"
@@ -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
@@ -1,5 +1,3 @@
1
- require_relative '../database_events'
2
-
3
1
  module Clockwork
4
2
 
5
3
  module DatabaseEvents
@@ -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)
@@ -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,14 @@ module Clockwork
160
160
 
161
161
  private
162
162
  def events_to_run(t)
163
- @events.select{ |event| event.run_now?(t) }
163
+ @events.select do |event|
164
+ begin
165
+ event.run_now?(t)
166
+ rescue => e
167
+ log_error(e)
168
+ false
169
+ end
170
+ end
164
171
  end
165
172
 
166
173
  def register(period, job, block, options)
data/lib/clockwork.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'logger'
2
+ require 'active_support'
2
3
  require 'active_support/time'
3
4
 
4
5
  require 'clockwork/at'
data/test/at_test.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require File.expand_path('../../lib/clockwork', __FILE__)
2
2
  require "minitest/autorun"
3
- require 'mocha/setup'
3
+ require 'mocha/minitest'
4
4
  require 'time'
5
5
  require 'active_support/time'
6
6
 
@@ -1,6 +1,6 @@
1
1
  require File.expand_path('../../lib/clockwork', __FILE__)
2
2
  require 'minitest/autorun'
3
- require 'mocha/setup'
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
@@ -1,6 +1,7 @@
1
1
  require "minitest/autorun"
2
2
  require 'clockwork/database_events/event_store'
3
3
  require 'clockwork/database_events/event_collection'
4
+ require 'ostruct'
4
5
 
5
6
  describe Clockwork::DatabaseEvents::EventStore do
6
7
 
@@ -28,8 +28,8 @@ module ActiveRecordFake
28
28
  end
29
29
 
30
30
  module ClassMethods
31
- def create *args
32
- new *args
31
+ def create(*args)
32
+ new(*args)
33
33
  end
34
34
 
35
35
  def delete_all
@@ -1,5 +1,5 @@
1
1
  require "minitest/autorun"
2
- require 'mocha/setup'
2
+ require 'mocha/minitest'
3
3
  require 'time'
4
4
  require 'active_support/time'
5
5
 
@@ -36,19 +36,35 @@ end
36
36
 
37
37
  class DatabaseEventModel
38
38
  include ActiveRecordFake
39
- attr_accessor :name, :frequency, :at, :tz
39
+ attr_accessor :frequency, :at, :tz
40
40
 
41
41
  def name
42
- @name || "#{self.class}:#{id}"
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 :name, :frequency, :at, :tz
56
+ attr_accessor :frequency, :at, :tz
49
57
 
50
58
  def name
51
- @name || "#{self.class}:#{id}"
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 :name, :frequency, :at, :tz, :if_state
78
+ attr_accessor :frequency, :at, :tz, :if_state
63
79
 
64
80
  def name
65
- @name || "#{self.class}:#{id}"
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
@@ -1,6 +1,6 @@
1
1
  require File.expand_path('../../lib/clockwork', __FILE__)
2
2
  require "minitest/autorun"
3
- require 'mocha/setup'
3
+ require 'mocha/minitest'
4
4
  require 'time'
5
5
  require 'active_support/time'
6
6
 
data/test/signal_test.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'test/unit'
2
- require 'mocha/setup'
2
+ require 'mocha/minitest'
3
3
  require 'fileutils'
4
4
 
5
5
  class SignalTest < Test::Unit::TestCase
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: 2.0.4
4
+ version: 3.0.0
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: 2019-07-25 00:00:00.000000000 Z
12
+ date: 2021-12-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: tzinfo
@@ -135,6 +135,7 @@ files:
135
135
  - example.rb
136
136
  - gemfiles/activesupport4.gemfile
137
137
  - gemfiles/activesupport5.gemfile
138
+ - gemfiles/activesupport6.gemfile
138
139
  - lib/clockwork.rb
139
140
  - lib/clockwork/at.rb
140
141
  - lib/clockwork/database_events.rb
@@ -159,7 +160,7 @@ homepage: http://github.com/Rykian/clockwork
159
160
  licenses:
160
161
  - MIT
161
162
  metadata: {}
162
- post_install_message:
163
+ post_install_message:
163
164
  rdoc_options: []
164
165
  require_paths:
165
166
  - lib
@@ -174,9 +175,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
174
175
  - !ruby/object:Gem::Version
175
176
  version: '0'
176
177
  requirements: []
177
- rubyforge_project:
178
- rubygems_version: 2.7.6
179
- signing_key:
178
+ rubygems_version: 3.2.22
179
+ signing_key:
180
180
  specification_version: 4
181
181
  summary: A scheduler process to replace cron.
182
182
  test_files: