simple_scheduler 0.2.2 → 0.2.3

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
  SHA1:
3
- metadata.gz: 2fcaf4fe9556dbb85aec2ed64578416c97121157
4
- data.tar.gz: 6cd57daf1dd3a2d8fe31c4eed3ba18904d2f4121
3
+ metadata.gz: 965fd30f738af89658435f906c3f8cd3367632ec
4
+ data.tar.gz: adc78088a3126a006eed623162ab99dcb373c218
5
5
  SHA512:
6
- metadata.gz: 2a6c2563947e0450d48f6d3729b3fe9746917056747894f8ad2d887c29b5a81bb2eb34a7d02785355c1b65a4bedf1fd97e6d303da1845eb9396e0bffb65707b2
7
- data.tar.gz: 475b59cac94a988e02cb4eccd6f907b64221bb64c67184beefdc0d5089d104600b5598ceee675cf89ccea197f29380f2ec55e93b1e9b0dbc7eb80456a93b269b
6
+ metadata.gz: 6fac392b17f7584ed1d7136200b88ec64e2ae104a3e6fdd4d5d9ce7ef1b9084f03dc719e8f002c40c32c5370b27dac546044c9c109bdf05cee1b565fc2ad1cf2
7
+ data.tar.gz: ed647beb0eef9ddbfeaafb0d2d3c125e2a1dfff45cbbb007da8fdc5febfb1a17f662fe8fcd7290e9d4afa5859a0d816e9c76c3fd455f19fd5659bc93c7971c2d
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/simplymadeapps/simple_scheduler.svg?branch=master)](https://travis-ci.org/simplymadeapps/simple_scheduler)
4
4
  [![Code Climate](https://codeclimate.com/github/simplymadeapps/simple_scheduler/badges/gpa.svg)](https://codeclimate.com/github/simplymadeapps/simple_scheduler)
5
+ [![Test Coverage](https://codeclimate.com/github/simplymadeapps/simple_scheduler/badges/coverage.svg)](https://codeclimate.com/github/simplymadeapps/simple_scheduler/coverage)
5
6
  [![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/github/simplymadeapps/simple_scheduler/)
6
7
 
7
8
  Simple Scheduler is a scheduling add-on that is designed to be used with
@@ -81,6 +82,8 @@ Add the rake task to Heroku Scheduler and set it to run every 10 minutes:
81
82
  rake simple_scheduler
82
83
  ```
83
84
 
85
+ ![Heroku Scheduler](https://cloud.githubusercontent.com/assets/124570/21104523/6d733d1a-c04c-11e6-89af-590e7d234cdf.gif)
86
+
84
87
  It may be useful to point to a specific configuration file in non-production environments:
85
88
 
86
89
  ```
@@ -126,10 +129,13 @@ Valid string formats/examples:
126
129
 
127
130
  #### :expires_after (optional)
128
131
 
129
- If your worker process is down for an extended period of time, you may not want jobs
130
- to execute when the server comes back online. By specifying an `expires_after` value,
131
- your job will not fire if the time the job actually runs later, by the specified
132
- duration, than the scheduled run time.
132
+ If your worker process is down for an extended period of time, you may not want certain jobs
133
+ to execute when the server comes back online. The `expires_after` value will be used
134
+ to determine if it's too late to run the job at the actual run time.
135
+
136
+ All jobs are scheduled in the future using the `SimpleScheculder::FutureJob`. This
137
+ wrapper job does the work of evaluating the current time and determining if the
138
+ scheduled job should run. See [Handling Expired Jobs](#handling-expired-jobs).
133
139
 
134
140
  The string should be in the form of an ActiveSupport duration.
135
141
 
@@ -179,9 +185,9 @@ end
179
185
 
180
186
  ## How It Works
181
187
 
182
- Once the rake task is added to Heroku Scheduler, the Simple Scheduler library
183
- will load the configuration file every 10 minutes, and ensure that each task
184
- has jobs scheduled in the future be checking the `Sidekiq::ScheduledSet`.
188
+ The Heroku Scheduler must be set up to run `rake simple_scheduler` every 10 minutes.
189
+ The rake task will load the configuration file each time and ensure that each task has
190
+ jobs scheduled for the future. This is done by checking the `Sidekiq::ScheduledSet`.
185
191
 
186
192
  A minimum of two jobs is always added to the scheduled set. By default all
187
193
  jobs for the next six hours are queued in advance. This ensures that there is
@@ -7,7 +7,7 @@ module SimpleScheduler
7
7
  # SimpleScheduler::At.new("1:00")
8
8
  # # => 2016-12-10 01:00:00 -0600
9
9
  # SimpleScheduler::At.new("Sun 0:00")
10
- # # => 2016-12-11 01:00:00 -0600
10
+ # # => 2016-12-11 00:00:00 -0600
11
11
  class At < Time
12
12
  AT_PATTERN = /(Sun|Mon|Tue|Wed|Thu|Fri|Sat)?\s?(?:\*{1,2}|(\d{1,2})):(\d{1,2})/
13
13
  DAYS = %w(Sun Mon Tue Wed Thu Fri Sat).freeze
@@ -29,7 +29,8 @@ module SimpleScheduler
29
29
  parsed_time.hour, parsed_time.min, parsed_time.sec, parsed_time.utc_offset)
30
30
  end
31
31
 
32
- # Always returns the specified hour.
32
+ # Always returns the specified hour if the hour was given, otherwise
33
+ # it returns the hour calculated based on other specified options.
33
34
  # @return [Integer]
34
35
  def hour
35
36
  hour? ? at_hour : super
@@ -64,7 +65,7 @@ module SimpleScheduler
64
65
  end
65
66
 
66
67
  def next_hour?
67
- !hour? && at_hour == now.hour && at_min < now.min
68
+ !hour? && at_min < now.min
68
69
  end
69
70
 
70
71
  def now
@@ -90,8 +91,14 @@ module SimpleScheduler
90
91
 
91
92
  @parsed_time = parsed_day
92
93
  change_hour = at_hour
94
+
95
+ # Add an additional hour if a specific hour wasn't given, if the minutes
96
+ # given are less than the current time's minutes.
93
97
  change_hour += 1 if next_hour?
94
98
  @parsed_time = @parsed_time.change(hour: change_hour, min: at_min)
99
+
100
+ # If the parsed time is still before the current time, add an additional day if
101
+ # the week day wasn't specified or add an additional week to get the correct time.
95
102
  @parsed_time += at_wday? ? 1.week : 1.day if now > @parsed_time
96
103
  @parsed_time
97
104
  end
@@ -30,6 +30,7 @@ module SimpleScheduler
30
30
 
31
31
  # The duration between the scheduled run time and actual run time that
32
32
  # will cause the job to expire. Expired jobs will not be executed.
33
+ # @return [ActiveSupport::Duration]
33
34
  def expire_duration
34
35
  split_duration = @task.expires_after.split(".")
35
36
  duration = split_duration[0].to_i
@@ -24,10 +24,8 @@ module SimpleScheduler
24
24
  # Queue each of the future jobs into Sidekiq from the defined tasks.
25
25
  def queue_future_jobs
26
26
  tasks.each do |task|
27
- new_run_times = task.future_run_times - task.existing_run_times
28
- next if new_run_times.empty?
29
-
30
27
  # Schedule the new run times using the future job wrapper.
28
+ new_run_times = task.future_run_times - task.existing_run_times
31
29
  new_run_times.each do |time|
32
30
  SimpleScheduler::FutureJob.set(wait_until: time).perform_later(task.params, time.to_i)
33
31
  end
@@ -35,7 +33,7 @@ module SimpleScheduler
35
33
  end
36
34
 
37
35
  # The array of tasks loaded from the config YAML.
38
- # @return [Array<SimpleScheduler::SchedulerJob]
36
+ # @return [Array<SimpleScheduler::Task]
39
37
  def tasks
40
38
  @config.map do |task_name, options|
41
39
  task_params = options.symbolize_keys
@@ -42,8 +42,8 @@ module SimpleScheduler
42
42
  def existing_jobs
43
43
  @existing_jobs ||= SimpleScheduler::Task.scheduled_set.select do |job|
44
44
  next unless job.display_class == "SimpleScheduler::FutureJob"
45
- task_params = job.display_args[0]
46
- task_params["class"] == job_class_name && task_params["name"] == name
45
+ task_params = job.display_args[0].symbolize_keys
46
+ task_params[:class] == job_class_name && task_params[:name] == name
47
47
  end.to_a
48
48
  end
49
49
 
@@ -68,8 +68,10 @@ module SimpleScheduler
68
68
  last_run_time = last_run_time.in_time_zone(time_zone)
69
69
 
70
70
  # Ensure there are at least two future jobs scheduled and that the queue ahead time is filled
71
- while future_run_times.length < 2 || ((last_run_time - Time.now) / 1.minute) < queue_ahead
71
+ while future_run_times.length < 2 || minutes_queued_ahead(last_run_time) < queue_ahead
72
72
  last_run_time = frequency.from_now(last_run_time)
73
+ # The hour may not match because of a shift caused by DST in previous run times,
74
+ # so we need to ensure that the hour matches the specified hour if given.
73
75
  last_run_time = last_run_time.change(hour: at.hour, min: at.min) if at.hour?
74
76
  future_run_times << last_run_time
75
77
  end
@@ -110,6 +112,10 @@ module SimpleScheduler
110
112
 
111
113
  private
112
114
 
115
+ def minutes_queued_ahead(last_run_time)
116
+ (last_run_time - Time.now) / 1.minute
117
+ end
118
+
113
119
  def parse_frequency(every_string)
114
120
  split_duration = every_string.split(".")
115
121
  frequency = split_duration[0].to_i
@@ -1,3 +1,3 @@
1
1
  module SimpleScheduler
2
- VERSION = "0.2.2".freeze
2
+ VERSION = "0.2.3".freeze
3
3
  end
metadata CHANGED
@@ -1,111 +1,125 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_scheduler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Pattison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-09 00:00:00.000000000 Z
11
+ date: 2016-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '4.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '4.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sidekiq
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: '4.2'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '4.2'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: appraisal
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: codeclimate-test-reporter
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rspec-rails
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - ">="
73
+ - - '>='
60
74
  - !ruby/object:Gem::Version
61
75
  version: '0'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - ">="
80
+ - - '>='
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rubocop
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - ">="
87
+ - - '>='
74
88
  - !ruby/object:Gem::Version
75
89
  version: '0'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - ">="
94
+ - - '>='
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: simplecov
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
- - - ">="
101
+ - - '>='
88
102
  - !ruby/object:Gem::Version
89
103
  version: '0'
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
- - - ">="
108
+ - - '>='
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: simplecov-rcov
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
- - - ">="
115
+ - - '>='
102
116
  - !ruby/object:Gem::Version
103
117
  version: '0'
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
- - - ">="
122
+ - - '>='
109
123
  - !ruby/object:Gem::Version
110
124
  version: '0'
111
125
  description: |2
@@ -118,17 +132,17 @@ executables: []
118
132
  extensions: []
119
133
  extra_rdoc_files: []
120
134
  files:
121
- - MIT-LICENSE
122
- - README.md
123
- - Rakefile
124
- - lib/simple_scheduler.rb
125
135
  - lib/simple_scheduler/at.rb
126
136
  - lib/simple_scheduler/future_job.rb
127
137
  - lib/simple_scheduler/railtie.rb
128
138
  - lib/simple_scheduler/scheduler_job.rb
129
139
  - lib/simple_scheduler/task.rb
130
140
  - lib/simple_scheduler/version.rb
141
+ - lib/simple_scheduler.rb
131
142
  - lib/tasks/simple_scheduler_tasks.rake
143
+ - MIT-LICENSE
144
+ - Rakefile
145
+ - README.md
132
146
  homepage: https://github.com/simplymadeapps/simple_scheduler
133
147
  licenses:
134
148
  - MIT
@@ -139,17 +153,17 @@ require_paths:
139
153
  - lib
140
154
  required_ruby_version: !ruby/object:Gem::Requirement
141
155
  requirements:
142
- - - ">="
156
+ - - '>='
143
157
  - !ruby/object:Gem::Version
144
158
  version: '0'
145
159
  required_rubygems_version: !ruby/object:Gem::Requirement
146
160
  requirements:
147
- - - ">="
161
+ - - '>='
148
162
  - !ruby/object:Gem::Version
149
163
  version: '0'
150
164
  requirements: []
151
165
  rubyforge_project:
152
- rubygems_version: 2.5.1
166
+ rubygems_version: 2.0.14.1
153
167
  signing_key:
154
168
  specification_version: 4
155
169
  summary: An enhancement for Heroku Scheduler + Sidekiq for scheduling jobs at specific