simple_scheduler 0.3.4 → 1.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
  SHA1:
3
- metadata.gz: 3a60a51725c69fc147ebb5b90adb50e784fbf4b5
4
- data.tar.gz: 8b4db53f04de5e0812fe5f9d6a6e00392d2be9c7
3
+ metadata.gz: 778a394ce23dfc08f29201e0d0734a5521c42747
4
+ data.tar.gz: f35fccb6c74a0a5d5e73c39736b09db21bf1f030
5
5
  SHA512:
6
- metadata.gz: 3027279bb87fbda962ebb7b583f63011fd038c803c4496d9d04097b2ccdd4e6a7dac8a0fbd65c6568bad883026020057794fa4d1b5d43a176eb050361c3e5f12
7
- data.tar.gz: 1361d030b08fef5f7d790ded52d90620af9a9d6db9f2d7bab36973e7f701c300665de670fba252a3548ff161cab743c1aa838fd294b95ab0ebc8526396871fd5
6
+ metadata.gz: 58b59b0e13d746d27ddbf0261972337957bf912f172ff13fbefa5a0d0186da03446212ce9a105182539043fcf49d2786ab8bf0d926527879660fe54c5103bc29
7
+ data.tar.gz: 77a7202de9dd23ad87e16c850eb93fe4bf090bd6adf1476ea32300971e622b9118df4fc0b30ac3597e1aca8ec8f46ba8166687c2eade8f49de837fa91f698252
data/README.md CHANGED
@@ -28,11 +28,14 @@ Every option we evaluated seems to have the same flaw: **If your server is down,
28
28
  You must be using:
29
29
 
30
30
  - Rails 4.2+
31
+ - ActiveJob
31
32
  - [Sidekiq](http://sidekiq.org)
32
- - [Heroku Scheduler](https://elements.heroku.com/addons/scheduler)
33
+ - [Heroku Scheduler](https://elements.heroku.com/addons/scheduler)*
33
34
 
34
35
  Both Active Job and Sidekiq::Worker classes can be queued by the scheduler.
35
36
 
37
+ *\* Not actually required, but you're on your own for scheduling the `rake simple_scheduler` task to run every 10 minutes.*
38
+
36
39
  ## Installation
37
40
 
38
41
  Add this line to your application's Gemfile:
@@ -54,8 +57,9 @@ $ bundle
54
57
  Create the file `config/simple_scheduler.yml` in your Rails project:
55
58
 
56
59
  ```yml
57
- # Global configuration options. These can also be set on each task.
60
+ # Global configuration options. The `queue_ahead` and `tz` options can also be set on each task.
58
61
  queue_ahead: 360 # Number of minutes to queue jobs into the future
62
+ queue_name: "default" # The Sidekiq queue name used by SimpleScheduler::FutureJob
59
63
  tz: "America/Chicago" # The application time zone will be used by default if not set
60
64
 
61
65
  # Runs once every 2 minutes
@@ -95,10 +99,11 @@ rake simple_scheduler
95
99
 
96
100
  ![Heroku Scheduler](https://cloud.githubusercontent.com/assets/124570/21104523/6d733d1a-c04c-11e6-89af-590e7d234cdf.gif)
97
101
 
98
- It may be useful to point to a specific configuration file in non-production environments:
102
+ It may be useful to point to a specific configuration file in non-production environments.
103
+ Use a custom configuration file by setting the `SIMPLE_SCHEDULER_CONFIG` environment variable.
99
104
 
100
105
  ```
101
- rake simple_scheduler["config/simple_scheduler.staging.yml"]
106
+ SIMPLE_SCHEDULER_CONFIG=config/simple_scheduler.staging.yml
102
107
  ```
103
108
 
104
109
  ### Task Options
@@ -259,9 +264,9 @@ SimpleScheduler.expired_task do |exception|
259
264
  ExceptionNotifier.notify_exception(
260
265
  exception,
261
266
  data: {
262
- task: exception.task.name,
267
+ task: exception.task.name,
263
268
  scheduled: exception.scheduled_time,
264
- actual: exception.run_time
269
+ actual: exception.run_time
265
270
  }
266
271
  )
267
272
  end
@@ -279,6 +284,7 @@ Reasons you may need to reset the job queue:
279
284
  - Deleting a scheduled task
280
285
  - Changing the task's run time interval
281
286
  - Changing the day of the week the job is run
287
+ - Changing the `queue_name` in the config file
282
288
 
283
289
  A rake task exists to delete all existing scheduled jobs and queue them back up from scratch:
284
290
 
@@ -286,12 +292,6 @@ A rake task exists to delete all existing scheduled jobs and queue them back up
286
292
  rake simple_scheduler:reset
287
293
  ```
288
294
 
289
- If you're using a custom configuration file:
290
-
291
- ```
292
- rake simple_scheduler:reset["config/simple_scheduler.staging.yml"]
293
- ```
294
-
295
295
  ## Contributing
296
296
 
297
297
  1. Fork it
@@ -1,23 +1,27 @@
1
1
  module SimpleScheduler
2
2
  # Active Job class that queues jobs defined in the config file.
3
3
  class SchedulerJob < ActiveJob::Base
4
- # Accepts a file path to read the scheduler configuration.
5
- # @param config_path [String]
6
- def perform(config_path = nil)
7
- config_path ||= "config/simple_scheduler.yml"
8
- load_config(config_path)
4
+ def perform
5
+ load_config
9
6
  queue_future_jobs
10
7
  end
11
8
 
12
9
  private
13
10
 
11
+ # Returns the path of the Simple Scheduler configuration file.
12
+ # @return [String]
13
+ def config_path
14
+ ENV["SIMPLE_SCHEDULER_CONFIG"] || "config/simple_scheduler.yml"
15
+ end
16
+
14
17
  # Load the global scheduler config from the YAML file.
15
- # @param config_path [String]
16
- def load_config(config_path)
17
- @config = YAML.load(ERB.new(File.read(config_path)).result)
18
+ def load_config
19
+ @config = YAML.safe_load(ERB.new(File.read(config_path)).result)
18
20
  @queue_ahead = @config["queue_ahead"] || Task::DEFAULT_QUEUE_AHEAD_MINUTES
21
+ @queue_name = @config["queue_name"] || "default"
19
22
  @time_zone = @config["tz"] || Time.zone.tzinfo.name
20
23
  @config.delete("queue_ahead")
24
+ @config.delete("queue_name")
21
25
  @config.delete("tz")
22
26
  end
23
27
 
@@ -27,7 +31,8 @@ module SimpleScheduler
27
31
  # Schedule the new run times using the future job wrapper.
28
32
  new_run_times = task.future_run_times - task.existing_run_times
29
33
  new_run_times.each do |time|
30
- SimpleScheduler::FutureJob.set(wait_until: time).perform_later(task.params, time.to_i)
34
+ SimpleScheduler::FutureJob.set(queue: @queue_name, wait_until: time)
35
+ .perform_later(task.params, time.to_i)
31
36
  end
32
37
  end
33
38
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleScheduler
2
- VERSION = "0.3.4".freeze
2
+ VERSION = "1.0.0".freeze
3
3
  end
@@ -1,12 +1,12 @@
1
1
  desc "Queue future jobs defined using Simple Scheduler"
2
- task :simple_scheduler, [:config_path] => [:environment] do |_, args|
3
- SimpleScheduler::SchedulerJob.perform_now(args[:config_path])
2
+ task simple_scheduler: :environment do
3
+ SimpleScheduler::SchedulerJob.perform_now
4
4
  end
5
5
 
6
6
  namespace :simple_scheduler do
7
7
  desc "Delete existing scheduled jobs and queue them from scratch"
8
- task :reset, [:config_path] => [:environment] do |_, args|
8
+ task reset: :environment do
9
9
  SimpleScheduler::FutureJob.delete_all
10
- SimpleScheduler::SchedulerJob.perform_now(args[:config_path])
10
+ SimpleScheduler::SchedulerJob.perform_now
11
11
  end
12
12
  end
metadata CHANGED
@@ -1,139 +1,139 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_scheduler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 1.0.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-08-04 00:00:00.000000000 Z
11
+ date: 2017-11-17 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
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: codeclimate-test-reporter
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rainbow
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: 2.1.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 2.1.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec-rails
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rubocop
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: simplecov
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - '>='
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - '>='
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: simplecov-rcov
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - '>='
129
+ - - ">="
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - '>='
136
+ - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  description: |2
@@ -146,17 +146,17 @@ executables: []
146
146
  extensions: []
147
147
  extra_rdoc_files: []
148
148
  files:
149
+ - MIT-LICENSE
150
+ - README.md
151
+ - Rakefile
152
+ - lib/simple_scheduler.rb
149
153
  - lib/simple_scheduler/at.rb
150
154
  - lib/simple_scheduler/future_job.rb
151
155
  - lib/simple_scheduler/railtie.rb
152
156
  - lib/simple_scheduler/scheduler_job.rb
153
157
  - lib/simple_scheduler/task.rb
154
158
  - lib/simple_scheduler/version.rb
155
- - lib/simple_scheduler.rb
156
159
  - lib/tasks/simple_scheduler_tasks.rake
157
- - MIT-LICENSE
158
- - Rakefile
159
- - README.md
160
160
  homepage: https://github.com/simplymadeapps/simple_scheduler
161
161
  licenses:
162
162
  - MIT
@@ -167,17 +167,17 @@ require_paths:
167
167
  - lib
168
168
  required_ruby_version: !ruby/object:Gem::Requirement
169
169
  requirements:
170
- - - '>='
170
+ - - ">="
171
171
  - !ruby/object:Gem::Version
172
172
  version: '0'
173
173
  required_rubygems_version: !ruby/object:Gem::Requirement
174
174
  requirements:
175
- - - '>='
175
+ - - ">="
176
176
  - !ruby/object:Gem::Version
177
177
  version: '0'
178
178
  requirements: []
179
179
  rubyforge_project:
180
- rubygems_version: 2.0.14.1
180
+ rubygems_version: 2.5.2
181
181
  signing_key:
182
182
  specification_version: 4
183
183
  summary: An enhancement for Heroku Scheduler + Sidekiq for scheduling jobs at specific