simple_scheduler 0.2.7 → 0.3.0
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 +4 -4
- data/README.md +79 -6
- data/lib/simple_scheduler/at.rb +1 -1
- data/lib/simple_scheduler/future_job.rb +3 -3
- data/lib/simple_scheduler/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f751bd8ec5a6af716c6a02b21160687cf3cb9a0
|
4
|
+
data.tar.gz: 0d39d2c7480d32eae74d7eb70e19afb3df0da899
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
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
|
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
|
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
|
data/lib/simple_scheduler/at.rb
CHANGED
@@ -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 =
|
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
|
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
|
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.
|
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-
|
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.
|
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
|