simple_scheduler 1.2.0 → 2.0.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 +2 -4
- data/Rakefile +2 -0
- data/lib/simple_scheduler/at.rb +29 -27
- data/lib/simple_scheduler/future_job.rb +2 -0
- data/lib/simple_scheduler/railtie.rb +2 -0
- data/lib/simple_scheduler/scheduler_job.rb +3 -1
- data/lib/simple_scheduler/task.rb +3 -1
- data/lib/simple_scheduler/version.rb +3 -1
- data/lib/simple_scheduler.rb +8 -6
- data/lib/tasks/simple_scheduler_tasks.rake +2 -0
- metadata +17 -16
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '04169aa142db6fc63fa654928bc8d7345bc35861e932ca8b9d533bdbd2873fc6'
|
|
4
|
+
data.tar.gz: ee4dd1ebe3aa396c10399e456134c583e133f76a94f316f64c652515d94fb9bc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8b14b423e9cfc343330ddddb38d316e45f6c86a798e4cfd453a32f4ee4078bb54b9d1af289cc8fc76f8d203adf862b4e2ced801aab4843162b3b2ee64cac8be1
|
|
7
|
+
data.tar.gz: 1758f31a3bc57ae0290bca4395d250b07951520aa7b270fdce2f3950be93b37a15bd01248eaa1a15c2dae453da79f2e05f478e53849ba5f87e0351ab88970369
|
data/README.md
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
# Simple Scheduler
|
|
2
2
|
|
|
3
|
-
[](https://codeclimate.com/github/simplymadeapps/simple_scheduler)
|
|
5
|
-
[](https://codeclimate.com/github/simplymadeapps/simple_scheduler/coverage)
|
|
3
|
+
[](https://github.com/simplymadeapps/simple_scheduler/actions/workflows/tests.yml)
|
|
6
4
|
[](http://www.rubydoc.info/github/simplymadeapps/simple_scheduler/)
|
|
7
5
|
|
|
8
6
|
Simple Scheduler is a scheduling add-on that is designed to be used with
|
|
@@ -27,7 +25,7 @@ Every option we evaluated seems to have the same flaw: **If your server is down,
|
|
|
27
25
|
|
|
28
26
|
You must be using:
|
|
29
27
|
|
|
30
|
-
- Rails
|
|
28
|
+
- Rails 7.2+
|
|
31
29
|
- ActiveJob
|
|
32
30
|
- [Sidekiq](http://sidekiq.org)
|
|
33
31
|
- [Heroku Scheduler](https://elements.heroku.com/addons/scheduler)*
|
data/Rakefile
CHANGED
data/lib/simple_scheduler/at.rb
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "delegate"
|
|
4
|
+
|
|
1
5
|
module SimpleScheduler
|
|
2
|
-
# A
|
|
6
|
+
# A delegator that parses the :at option on a task into the first time it should run.
|
|
7
|
+
# Instead of inheriting from Time (which conflicts with ActiveSupport time helpers),
|
|
8
|
+
# this wraps a Time instance and selectively overrides hour/hour? semantics.
|
|
3
9
|
# Time.now
|
|
4
10
|
# # => 2016-12-09 08:24:11 -0600
|
|
5
11
|
# SimpleScheduler::At.new("*:30")
|
|
@@ -8,8 +14,8 @@ module SimpleScheduler
|
|
|
8
14
|
# # => 2016-12-10 01:00:00 -0600
|
|
9
15
|
# SimpleScheduler::At.new("Sun 0:00")
|
|
10
16
|
# # => 2016-12-11 00:00:00 -0600
|
|
11
|
-
class At <
|
|
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
|
|
17
|
+
class At < SimpleDelegator
|
|
18
|
+
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
19
|
DAYS = %w[Sun Mon Tue Wed Thu Fri Sat].freeze
|
|
14
20
|
|
|
15
21
|
# Error class raised when an invalid string is given for the time.
|
|
@@ -25,20 +31,16 @@ module SimpleScheduler
|
|
|
25
31
|
# "[Sun|Mon|Tue|Wed|Thu|Fri|Sat] 00:00"
|
|
26
32
|
# @param at [String] The formatted string for a task's run time
|
|
27
33
|
# @param time_zone [ActiveSupport::TimeZone] The time zone to parse the at time in
|
|
28
|
-
# rubocop:disable Metrics/AbcSize
|
|
29
34
|
def initialize(at, time_zone = nil)
|
|
30
35
|
@at = at
|
|
31
36
|
@time_zone = time_zone || Time.zone
|
|
32
|
-
super(parsed_time
|
|
33
|
-
parsed_time.hour, parsed_time.min, parsed_time.sec, parsed_time.utc_offset)
|
|
37
|
+
super(parsed_time) # Delegate all Time methods to parsed Time instance
|
|
34
38
|
end
|
|
35
|
-
# rubocop:enable Metrics/AbcSize
|
|
36
39
|
|
|
37
|
-
#
|
|
38
|
-
# it returns the hour calculated based on other specified options.
|
|
40
|
+
# Returns the specified hour if present in the at string, else the delegated Time's hour.
|
|
39
41
|
# @return [Integer]
|
|
40
42
|
def hour
|
|
41
|
-
hour? ? at_hour :
|
|
43
|
+
hour? ? at_hour : __getobj__.hour
|
|
42
44
|
end
|
|
43
45
|
|
|
44
46
|
# Returns whether or not the hour was specified in the :at string.
|
|
@@ -51,8 +53,9 @@ module SimpleScheduler
|
|
|
51
53
|
|
|
52
54
|
def at_match
|
|
53
55
|
@at_match ||= begin
|
|
54
|
-
match = AT_PATTERN.match(@at)
|
|
55
56
|
raise InvalidTime, "The `at` option is required." if @at.nil?
|
|
57
|
+
|
|
58
|
+
match = AT_PATTERN.match(@at)
|
|
56
59
|
raise InvalidTime, "The `at` option '#{@at}' is invalid." if match.nil?
|
|
57
60
|
|
|
58
61
|
match
|
|
@@ -77,11 +80,11 @@ module SimpleScheduler
|
|
|
77
80
|
|
|
78
81
|
def next_hour
|
|
79
82
|
@next_hour ||= begin
|
|
80
|
-
|
|
83
|
+
h = at_hour
|
|
81
84
|
# Add an additional hour if a specific hour wasn't given, if the minutes
|
|
82
85
|
# given are less than the current time's minutes.
|
|
83
|
-
|
|
84
|
-
|
|
86
|
+
h += 1 if next_hour?
|
|
87
|
+
h
|
|
85
88
|
end
|
|
86
89
|
end
|
|
87
90
|
|
|
@@ -94,37 +97,36 @@ module SimpleScheduler
|
|
|
94
97
|
end
|
|
95
98
|
|
|
96
99
|
def parsed_day
|
|
97
|
-
|
|
100
|
+
day = now.beginning_of_day
|
|
98
101
|
|
|
99
102
|
# If no day of the week is given, return today
|
|
100
|
-
return
|
|
103
|
+
return day unless at_wday?
|
|
101
104
|
|
|
102
105
|
# Shift to the correct day of the week if given
|
|
103
|
-
add_days = at_wday -
|
|
104
|
-
add_days += 7 if
|
|
105
|
-
|
|
106
|
+
add_days = at_wday - day.wday
|
|
107
|
+
add_days += 7 if day.wday > at_wday
|
|
108
|
+
day + add_days.days
|
|
106
109
|
end
|
|
107
110
|
|
|
108
111
|
# Returns the very first time a job should be run for the scheduled task.
|
|
109
112
|
# @return [Time]
|
|
110
113
|
def parsed_time
|
|
111
|
-
return @parsed_time if @parsed_time
|
|
114
|
+
return @parsed_time if defined?(@parsed_time) && @parsed_time
|
|
112
115
|
|
|
113
|
-
|
|
116
|
+
time_object = parsed_day
|
|
114
117
|
change_hour = next_hour
|
|
115
|
-
|
|
116
118
|
# There is no hour 24, so we need to move to the next day
|
|
117
119
|
if change_hour == 24
|
|
118
|
-
|
|
120
|
+
time_object = 1.day.from_now(time_object)
|
|
119
121
|
change_hour = 0
|
|
120
122
|
end
|
|
121
|
-
|
|
122
|
-
@parsed_time = @parsed_time.change(hour: change_hour, min: at_min)
|
|
123
|
+
time_object = time_object.change(hour: change_hour, min: at_min)
|
|
123
124
|
|
|
124
125
|
# If the parsed time is still before the current time, add an additional day if
|
|
125
126
|
# the week day wasn't specified or add an additional week to get the correct time.
|
|
126
|
-
|
|
127
|
-
|
|
127
|
+
time_object += at_wday? ? 1.week : 1.day if now > time_object
|
|
128
|
+
|
|
129
|
+
@parsed_time = time_object
|
|
128
130
|
end
|
|
129
131
|
end
|
|
130
132
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module SimpleScheduler
|
|
2
4
|
# Active Job class that queues jobs defined in the config file.
|
|
3
5
|
class SchedulerJob < ActiveJob::Base
|
|
@@ -11,7 +13,7 @@ module SimpleScheduler
|
|
|
11
13
|
# Returns the path of the Simple Scheduler configuration file.
|
|
12
14
|
# @return [String]
|
|
13
15
|
def config_path
|
|
14
|
-
ENV
|
|
16
|
+
ENV.fetch("SIMPLE_SCHEDULER_CONFIG", "config/simple_scheduler.yml")
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
# Load the global scheduler config from the YAML file.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module SimpleScheduler
|
|
2
4
|
# Class for parsing each task in the scheduler config YAML file and returning
|
|
3
5
|
# the values needed to schedule the task in the future.
|
|
@@ -66,7 +68,7 @@ module SimpleScheduler
|
|
|
66
68
|
# rubocop:disable Metrics/AbcSize
|
|
67
69
|
def future_run_times
|
|
68
70
|
future_run_times = existing_run_times.dup
|
|
69
|
-
last_run_time = future_run_times.last || at - frequency
|
|
71
|
+
last_run_time = future_run_times.last || (at - frequency)
|
|
70
72
|
last_run_time = last_run_time.in_time_zone(time_zone)
|
|
71
73
|
|
|
72
74
|
# Ensure there are at least two future jobs scheduled and that the queue ahead time is filled
|
data/lib/simple_scheduler.rb
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "active_job"
|
|
2
4
|
require "sidekiq/api"
|
|
3
|
-
require_relative "
|
|
4
|
-
require_relative "
|
|
5
|
-
require_relative "
|
|
6
|
-
require_relative "
|
|
7
|
-
require_relative "
|
|
8
|
-
require_relative "
|
|
5
|
+
require_relative "simple_scheduler/at"
|
|
6
|
+
require_relative "simple_scheduler/future_job"
|
|
7
|
+
require_relative "simple_scheduler/railtie"
|
|
8
|
+
require_relative "simple_scheduler/scheduler_job"
|
|
9
|
+
require_relative "simple_scheduler/task"
|
|
10
|
+
require_relative "simple_scheduler/version"
|
|
9
11
|
|
|
10
12
|
# Module for scheduling jobs at specific times using Sidekiq.
|
|
11
13
|
module SimpleScheduler
|
metadata
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: simple_scheduler
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.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:
|
|
11
|
+
date: 2025-11-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name:
|
|
14
|
+
name: activejob
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
17
|
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
19
|
+
version: '7.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
|
-
version: '
|
|
26
|
+
version: '7.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
|
-
version: '
|
|
33
|
+
version: '7.0'
|
|
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
|
-
version: '
|
|
40
|
+
version: '7.0'
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
42
|
name: appraisal
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -70,30 +70,30 @@ dependencies:
|
|
|
70
70
|
name: rspec-rails
|
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
|
72
72
|
requirements:
|
|
73
|
-
- - "
|
|
73
|
+
- - "~>"
|
|
74
74
|
- !ruby/object:Gem::Version
|
|
75
|
-
version: '
|
|
75
|
+
version: '8'
|
|
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
|
-
version: '
|
|
82
|
+
version: '8'
|
|
83
83
|
- !ruby/object:Gem::Dependency
|
|
84
84
|
name: rubocop
|
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
|
86
86
|
requirements:
|
|
87
87
|
- - "~>"
|
|
88
88
|
- !ruby/object:Gem::Version
|
|
89
|
-
version:
|
|
89
|
+
version: '1.28'
|
|
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
|
-
version:
|
|
96
|
+
version: '1.28'
|
|
97
97
|
- !ruby/object:Gem::Dependency
|
|
98
98
|
name: simplecov
|
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -146,7 +146,8 @@ files:
|
|
|
146
146
|
homepage: https://github.com/simplymadeapps/simple_scheduler
|
|
147
147
|
licenses:
|
|
148
148
|
- MIT
|
|
149
|
-
metadata:
|
|
149
|
+
metadata:
|
|
150
|
+
rubygems_mfa_required: 'true'
|
|
150
151
|
post_install_message:
|
|
151
152
|
rdoc_options: []
|
|
152
153
|
require_paths:
|
|
@@ -155,14 +156,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
155
156
|
requirements:
|
|
156
157
|
- - ">="
|
|
157
158
|
- !ruby/object:Gem::Version
|
|
158
|
-
version:
|
|
159
|
+
version: 3.2.0
|
|
159
160
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
160
161
|
requirements:
|
|
161
162
|
- - ">="
|
|
162
163
|
- !ruby/object:Gem::Version
|
|
163
164
|
version: '0'
|
|
164
165
|
requirements: []
|
|
165
|
-
rubygems_version: 3.0.3
|
|
166
|
+
rubygems_version: 3.0.3.1
|
|
166
167
|
signing_key:
|
|
167
168
|
specification_version: 4
|
|
168
169
|
summary: An enhancement for Heroku Scheduler + Sidekiq for scheduling jobs at specific
|