rocketjob 3.3.3 → 3.3.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 296d6077572bea816bb7b5823df1bab3f4291b42
4
- data.tar.gz: 593b8a806b15fc01903818b7eeb003d3d54effb3
3
+ metadata.gz: d6c4cf70983793dd982cefbc5b58b7ae33d6b8f1
4
+ data.tar.gz: 2c593219205c7ff16dbd02dce31c57b8c67dcfa9
5
5
  SHA512:
6
- metadata.gz: 443c33e173c47eb83b916c9e9c1592551989996bdf116f8b53f0f2f811540cf712c2eb6815cf843742102705f6b6c645991db8b1f2675cfb02b1bd7203e4343d
7
- data.tar.gz: 9234139d37b517607de16d2a6a3fb553be22f7fec2dc633b40f69df1022f24f7141c0053740f6677a84804ecdd2b80acc94a3e83072d4cdf9309d9125a72c3d4
6
+ metadata.gz: 6dd940e8008cc81dd36085bc12f705c87a12a348e1edf29c3dbf34c1b6000bcfaf3ed085505968c35f94072f862cd13f524371836b5fe0eb7b0697da7181ca47
7
+ data.tar.gz: b2e616a1ef53886ea4a5c2fef6c097d3fc640ce9a71971f1ebdb9ee4d1fc1bcd57372773af8e81003d873b4e30eb2497c2708755067b51d3994d8d74104cc288
@@ -32,6 +32,8 @@ module RocketJob
32
32
  # - The job will not be restarted if:
33
33
  # - A validation fails after cloning this job.
34
34
  # - The job has expired.
35
+ # - Any time the `cron_schedule` is changed, the `run_at` is automatically set before saving the changes.
36
+ # - However, if the `run_at` is explicitly set then it will not be overriden.
35
37
  #
36
38
  # Example:
37
39
  #
@@ -102,7 +104,7 @@ module RocketJob
102
104
 
103
105
  field :cron_schedule, type: String, class_attribute: true, user_editable: true, copy_on_restart: true
104
106
 
105
- before_create :rocket_job_set_run_at
107
+ before_save :rocket_job_set_run_at
106
108
 
107
109
  validates_presence_of :cron_schedule
108
110
  validates_each :cron_schedule do |record, attr, value|
@@ -114,10 +116,20 @@ module RocketJob
114
116
  end
115
117
  end
116
118
 
119
+ # Returns [Time] the next time this job will be scheduled to run at.
120
+ #
121
+ # Parameters
122
+ # time: [Time]
123
+ # The next time as of this time.
124
+ # Default: Time.now
125
+ def rocket_job_cron_next_time(time = Time.now)
126
+ RocketJob::Plugins::Rufus::CronLine.new(cron_schedule).next_time(time)
127
+ end
128
+
117
129
  private
118
130
 
119
131
  def rocket_job_set_run_at
120
- self.run_at = RocketJob::Plugins::Rufus::CronLine.new(cron_schedule).next_time
132
+ self.run_at = rocket_job_cron_next_time if cron_schedule_changed? && !run_at_changed?
121
133
  end
122
134
 
123
135
  end
@@ -1,3 +1,3 @@
1
1
  module RocketJob #:nodoc
2
- VERSION = '3.3.3'
2
+ VERSION = '3.3.4'
3
3
  end
@@ -54,6 +54,22 @@ module Plugins
54
54
 
55
55
  end
56
56
 
57
+ describe '#save' do
58
+ it 'updates run_at for a new record' do
59
+ @job = CronJob.create!(cron_schedule: '* 1 * * *')
60
+ assert @job.run_at
61
+ end
62
+
63
+ it 'updates run_at for a modified record' do
64
+ @job = CronJob.create!(cron_schedule: '* 1 * * * UTC')
65
+ assert run_at = @job.run_at
66
+ @job.cron_schedule = '* 2 * * * UTC'
67
+ assert_equal run_at, @job.run_at
68
+ @job.save!
69
+ assert run_at < @job.run_at
70
+ end
71
+ end
72
+
57
73
  describe '#valid?' do
58
74
  it 'fails on missing cron schedule' do
59
75
  @job = CronJob.new
data/test/test_db.sqlite3 CHANGED
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rocketjob
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.3
4
+ version: 3.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reid Morrison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-13 00:00:00.000000000 Z
11
+ date: 2017-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby