Class: RailsExecution::Services::CreateScheduledJob
- Inherits:
-
Object
- Object
- RailsExecution::Services::CreateScheduledJob
- Defined in:
- lib/rails_execution/services/create_scheduled_job.rb
Constant Summary collapse
- NUMBER_OF_MONTHS =
12
Instance Method Summary collapse
- #calculate_next_time_at ⇒ Object
- #call ⇒ Object
-
#initialize(task) ⇒ CreateScheduledJob
constructor
A new instance of CreateScheduledJob.
Constructor Details
#initialize(task) ⇒ CreateScheduledJob
Returns a new instance of CreateScheduledJob.
6 7 8 |
# File 'lib/rails_execution/services/create_scheduled_job.rb', line 6 def initialize(task) @task = task end |
Instance Method Details
#calculate_next_time_at ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rails_execution/services/create_scheduled_job.rb', line 15 def calculate_next_time_at return task.scheduled_at unless task.repeatable? next_time_at = task.scheduled_at if task.repeat_weekdays? next_time_at += 1.day until next_time_at.future? && next_time_at.wday.between?(1, 5) else i = 1 while next_time_at.past? next_time_at = task.scheduled_at + i.public_send(repeat_time_intervals[task.repeat_mode.to_sym]) i += 1 end end return next_time_at end |
#call ⇒ Object
10 11 12 13 |
# File 'lib/rails_execution/services/create_scheduled_job.rb', line 10 def call calculate_next_time_at create_schedule_job if next_time_at.future? end |