simple_scheduler 0.2.7 → 0.3.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
  SHA1:
3
- metadata.gz: cc8ab786b041bb9aa884a20fc7868b959b9007f5
4
- data.tar.gz: 13eea6770174d5d114150cd50d51a8d10597269c
3
+ metadata.gz: 1f751bd8ec5a6af716c6a02b21160687cf3cb9a0
4
+ data.tar.gz: 0d39d2c7480d32eae74d7eb70e19afb3df0da899
5
5
  SHA512:
6
- metadata.gz: 42828b1c2ce9c204dc0534bc88dfc773861fa7e97e949aa6b1a74a545c9258044de2df96b6c0e540ec27ebe2d63c3822b59aa18eb4ea2ecb2c51db3f7e8eff2b
7
- data.tar.gz: 8b8e8872d57f94bfe8c0e7a5a1d18403532d0b85c81e7679138135670c60cf4b947d997145cb3eb901febc63a1e6a8af24bbf0f239b4bdf8e9fe6a0d435ddf39
6
+ metadata.gz: b2258e9b118862d9fe6b2b6dce8e63fa103dbd1eac20ac27788fc6fa5486d37a53a8472d2f484de99527529145a3c50c73ba8b66f4dc61e4634884d3e43bd9cc
7
+ data.tar.gz: 6f9eed4ce1271dc15e582777726e149a83f2d8da23dd6cc9fa3e29406441460484e50fbeef3d006791c4f08a10478fef810796ea88823cff69ab08f86646a34e
data/README.md CHANGED
@@ -123,9 +123,9 @@ How frequently the task should be performed as an ActiveSupport duration definit
123
123
 
124
124
  #### :at (optional)
125
125
 
126
- This is the starting point for the `every` duration. If not given, the job will
126
+ This is the starting point\* for the `:every` duration. If not given, the job will
127
127
  run immediately when the configuration file is loaded for the first time and will
128
- follow the `every` duration to determine future execution times.
128
+ follow the `:every` duration to determine future execution times.
129
129
 
130
130
  Valid string formats/examples:
131
131
 
@@ -134,14 +134,18 @@ Valid string formats/examples:
134
134
  "3:30"
135
135
  "**:00"
136
136
  "*:30"
137
- "Sun 2:00"
138
- "[Sun|Mon|Tue|Wed|Thu|Fri|Sat] 00:00"
137
+ "Sun 2:00" # [Sun|Mon|Tue|Wed|Thu|Fri|Sat]
139
138
  ```
140
139
 
140
+ \* If you specify the hour of the day the job should run, it will only run in that hour,
141
+ so if you specify an `:every` duration of less than `1.day`, the job will only run
142
+ when the run time hour matches the `:at` time's hour.
143
+ See [#17](https://github.com/simplymadeapps/simple_scheduler/issues/17) for more info.
144
+
141
145
  #### :expires_after (optional)
142
146
 
143
147
  If your worker process is down for an extended period of time, you may not want certain jobs
144
- to execute when the server comes back online. The `expires_after` value will be used
148
+ to execute when the server comes back online. The `:expires_after` value will be used
145
149
  to determine if it's too late to run the job at the actual run time.
146
150
 
147
151
  All jobs are scheduled in the future using the `SimpleScheduler::FutureJob`. This
@@ -155,6 +159,27 @@ The string should be in the form of an ActiveSupport duration.
155
159
  "23.hours"
156
160
  ```
157
161
 
162
+ #### :queue_ahead (optional)
163
+
164
+ The `:queue_ahead` is the number of minutes that the job should be scheduled into the future.
165
+ The default value is `360`, so Simple Scheduler will make sure you have scheduled jobs for
166
+ the next 6 hours. This allows for a major outage without losing track of jobs that were
167
+ supposed to run during that time.
168
+
169
+ **There are always a minimum of 2 scheduled jobs for each scheduled task.** This ensures there
170
+ is always one job in the queue that can be used to determine the next run time, even if one of
171
+ the two was executed during the 10 minute Heroku Scheduler wait time.
172
+
173
+ The `:queue_ahead` can be set as a global configuration option or for each individual task.
174
+
175
+ #### :tz (optional)
176
+
177
+ Use `:tz` to specify the time zone of your `:at` time. If no time zone is specified, the Time.zone
178
+ default in your Rails app will be used when parsing the `:at` time. A list of all the available
179
+ timezone identifiers can be obtained using `TZInfo::Timezone.all_identifiers`.
180
+
181
+ The `:tz` can be set as a global configuration option or for each individual task.
182
+
158
183
  ## Writing Your Jobs
159
184
 
160
185
  There is no guarantee that the job will run at the exact time given in the
@@ -171,9 +196,57 @@ class ExampleJob < ActiveJob::Base
171
196
  end
172
197
  ```
173
198
 
199
+ #### Determine if the Job Should Run
200
+
201
+ Simple Scheduler doesn't support specifying multiple days of the week or a specific day of the month.
202
+ You can use the `scheduled_time` with a guard clause to ensure the job only runs on specific days.
203
+
204
+ Set up the jobs to run every day, even though we don't actually want them to run every day:
205
+
206
+ ```yml
207
+ # config/simple_scheduler.yml
208
+ payroll:
209
+ class: "PayrollJob"
210
+ every: "1.day"
211
+ at: "0:00"
212
+
213
+ weekday_reports:
214
+ class: "WeekdayReportsJob"
215
+ every: "1.day"
216
+ at: "18:00"
217
+ ```
218
+
219
+ Use a guard clause in each of our jobs to exit the job if it shouldn't run that day:
220
+
221
+ ```ruby
222
+ # A job that runs only on the 1st and 15th of the month.
223
+ class PayrollJob < ActiveJob::Base
224
+ # @param scheduled_time [Integer] The epoch time for when the job was scheduled to be run
225
+ def perform(scheduled_time)
226
+ # Exit the job unless it's the 1st or 15th day of the month
227
+ day_of_the_month = Time.at(scheduled_time).day
228
+ return unless day_of_the_month == 1 || day_of_the_month == 15
229
+
230
+ # Perform the job...
231
+ end
232
+ end
233
+
234
+ # A job that runs only on weekdays, Monday - Friday.
235
+ class WeekdayReportsJob < ActiveJob::Base
236
+ # @param scheduled_time [Integer] The epoch time for when the job was scheduled to be run
237
+ def perform(scheduled_time)
238
+ # Exit the job unless it's Monday (1), Tuesday (2), Wednesday (3), Thursday (4), or Friday (5)
239
+ day_of_the_week = Time.at(scheduled_time).wday
240
+ return unless (1..5).include?(day_of_the_week)
241
+
242
+ # Perform the job...
243
+ end
244
+ end
245
+ ```
246
+
174
247
  ## Handling Expired Jobs
175
248
 
176
- If you assign the `expires_after` option to your task, you may want to know if
249
+ If you assign the `:expires_after` option to your task, you may want to know if
177
250
  a job wasn't run because it expires. Add this block to an initializer file:
178
251
 
179
252
  ```ruby
@@ -9,7 +9,7 @@ module SimpleScheduler
9
9
  # SimpleScheduler::At.new("Sun 0:00")
10
10
  # # => 2016-12-11 00:00:00 -0600
11
11
  class At < Time
12
- AT_PATTERN = /(Sun|Mon|Tue|Wed|Thu|Fri|Sat)?\s?(?:\*{1,2}|((?:\b[0-1]?[0-9]|2[0-3]))):([0-5]\d)/
12
+ AT_PATTERN = /\A(Sun|Mon|Tue|Wed|Thu|Fri|Sat)?\s?(?:\*{1,2}|((?:\b[0-1]?[0-9]|2[0-3]))):([0-5]\d)\z/
13
13
  DAYS = %w(Sun Mon Tue Wed Thu Fri Sat).freeze
14
14
 
15
15
  # Error class raised when an invalid string is given for the time.
@@ -77,10 +77,10 @@ module SimpleScheduler
77
77
 
78
78
  # Queue the task with the scheduled time if the job allows.
79
79
  def queue_task
80
- if @task.job_class.instance_method(:perform).arity > 0
81
- @task.job_class.send(perform_method, @scheduled_time.to_i)
82
- else
80
+ if @task.job_class.instance_method(:perform).arity.zero?
83
81
  @task.job_class.send(perform_method)
82
+ else
83
+ @task.job_class.send(perform_method, @scheduled_time.to_i)
84
84
  end
85
85
  end
86
86
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleScheduler
2
- VERSION = "0.2.7".freeze
2
+ VERSION = "0.3.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_scheduler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Pattison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-20 00:00:00.000000000 Z
11
+ date: 2017-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -177,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
177
  version: '0'
178
178
  requirements: []
179
179
  rubyforge_project:
180
- rubygems_version: 2.5.1
180
+ rubygems_version: 2.6.11
181
181
  signing_key:
182
182
  specification_version: 4
183
183
  summary: An enhancement for Heroku Scheduler + Sidekiq for scheduling jobs at specific