Class: Gouda::Scheduler::Entry
- Inherits:
-
Struct
- Object
- Struct
- Gouda::Scheduler::Entry
- Defined in:
- lib/gouda/scheduler.rb
Overview
A timer entry is either a Cron pattern or an interval duration, and configures which job needs to be scheduled and when
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#cron ⇒ Object
Returns the value of attribute cron.
-
#interval_seconds ⇒ Object
Returns the value of attribute interval_seconds.
-
#job_class ⇒ Object
Returns the value of attribute job_class.
-
#kwargs ⇒ Object
Returns the value of attribute kwargs.
-
#name ⇒ Object
Returns the value of attribute name.
-
#set ⇒ Object
Returns the value of attribute set.
Instance Method Summary collapse
-
#build_active_job ⇒ ActiveJob::Base
Builds the ActiveJob which can be enqueued for this entry.
-
#next_at ⇒ Time
Tells when this particular task should next run.
- #scheduler_key ⇒ Object
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args
9 10 11 |
# File 'lib/gouda/scheduler.rb', line 9 def args @args end |
#cron ⇒ Object
Returns the value of attribute cron
9 10 11 |
# File 'lib/gouda/scheduler.rb', line 9 def cron @cron end |
#interval_seconds ⇒ Object
Returns the value of attribute interval_seconds
9 10 11 |
# File 'lib/gouda/scheduler.rb', line 9 def interval_seconds @interval_seconds end |
#job_class ⇒ Object
Returns the value of attribute job_class
9 10 11 |
# File 'lib/gouda/scheduler.rb', line 9 def job_class @job_class end |
#kwargs ⇒ Object
Returns the value of attribute kwargs
9 10 11 |
# File 'lib/gouda/scheduler.rb', line 9 def kwargs @kwargs end |
#name ⇒ Object
Returns the value of attribute name
9 10 11 |
# File 'lib/gouda/scheduler.rb', line 9 def name @name end |
#set ⇒ Object
Returns the value of attribute set
9 10 11 |
# File 'lib/gouda/scheduler.rb', line 9 def set @set end |
Instance Method Details
#build_active_job ⇒ ActiveJob::Base
Builds the ActiveJob which can be enqueued for this entry
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/gouda/scheduler.rb', line 31 def build_active_job next_at = self.next_at return unless next_at job_class = self.job_class.constantize active_job = kwargs_value.present? ? job_class.new(*args_value, **kwargs_value) : job_class.new(*args_value) # This method supports ruby2_keywords active_job.scheduled_at = next_at active_job.scheduler_key = scheduler_key set_value.present? ? active_job.set(set_value) : active_job end |
#next_at ⇒ Time
Tells when this particular task should next run
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/gouda/scheduler.rb', line 17 def next_at if interval_seconds first_existing = Gouda::Workload.where(scheduler_key: scheduler_key).where("scheduled_at > NOW()").order("scheduled_at DESC").pluck(:scheduled_at).first (first_existing || Time.now.utc) + interval_seconds elsif cron fugit = Fugit::Cron.parse(cron) raise ArgumentError, "Unable to parse cron pattern #{cron.inspect}" unless fugit Time.at(fugit.next_time.to_i).utc end end |
#scheduler_key ⇒ Object
10 11 12 |
# File 'lib/gouda/scheduler.rb', line 10 def scheduler_key [name, interval_seconds, cron, job_class].compact.join("_") end |