Class: SolidQueue::Dispatcher::RecurringTask
- Inherits:
-
Object
- Object
- SolidQueue::Dispatcher::RecurringTask
- Defined in:
- lib/solid_queue/dispatcher/recurring_task.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#class_name ⇒ Object
readonly
Returns the value of attribute class_name.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#schedule ⇒ Object
readonly
Returns the value of attribute schedule.
Class Method Summary collapse
Instance Method Summary collapse
- #delay_from_now ⇒ Object
- #enqueue(at:) ⇒ Object
-
#initialize(key, class_name:, schedule:, arguments: nil) ⇒ RecurringTask
constructor
A new instance of RecurringTask.
- #next_time ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(key, class_name:, schedule:, arguments: nil) ⇒ RecurringTask
Returns a new instance of RecurringTask.
17 18 19 20 21 22 |
# File 'lib/solid_queue/dispatcher/recurring_task.rb', line 17 def initialize(key, class_name:, schedule:, arguments: nil) @key = key @class_name = class_name @schedule = schedule @arguments = Array(arguments) end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
15 16 17 |
# File 'lib/solid_queue/dispatcher/recurring_task.rb', line 15 def arguments @arguments end |
#class_name ⇒ Object (readonly)
Returns the value of attribute class_name.
15 16 17 |
# File 'lib/solid_queue/dispatcher/recurring_task.rb', line 15 def class_name @class_name end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
15 16 17 |
# File 'lib/solid_queue/dispatcher/recurring_task.rb', line 15 def key @key end |
#schedule ⇒ Object (readonly)
Returns the value of attribute schedule.
15 16 17 |
# File 'lib/solid_queue/dispatcher/recurring_task.rb', line 15 def schedule @schedule end |
Class Method Details
.from_configuration(key, **options) ⇒ Object
10 11 12 |
# File 'lib/solid_queue/dispatcher/recurring_task.rb', line 10 def from_configuration(key, **) new(key, class_name: [:class], schedule: [:schedule], arguments: [:args]) end |
.wrap(args) ⇒ Object
6 7 8 |
# File 'lib/solid_queue/dispatcher/recurring_task.rb', line 6 def wrap(args) args.is_a?(self) ? args : from_configuration(args.first, **args.second) end |
Instance Method Details
#delay_from_now ⇒ Object
24 25 26 |
# File 'lib/solid_queue/dispatcher/recurring_task.rb', line 24 def delay_from_now [ (next_time - Time.current).to_f, 0 ].max end |
#enqueue(at:) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/solid_queue/dispatcher/recurring_task.rb', line 32 def enqueue(at:) SolidQueue.instrument(:enqueue_recurring_task, task: key, at: at) do |payload| active_job = if using_solid_queue_adapter? perform_later_and_record(run_at: at) else payload[:other_adapter] = true perform_later do |job| unless job.successfully_enqueued? payload[:enqueue_error] = job.enqueue_error&. end end end payload[:active_job_id] = active_job.job_id if active_job rescue RecurringExecution::AlreadyRecorded payload[:skipped] = true rescue Job::EnqueueError => error payload[:enqueue_error] = error. end end |
#next_time ⇒ Object
28 29 30 |
# File 'lib/solid_queue/dispatcher/recurring_task.rb', line 28 def next_time parsed_schedule.next_time.utc end |
#to_h ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/solid_queue/dispatcher/recurring_task.rb', line 62 def to_h { schedule: schedule, class_name: class_name, arguments: arguments } end |
#to_s ⇒ Object
58 59 60 |
# File 'lib/solid_queue/dispatcher/recurring_task.rb', line 58 def to_s "#{class_name}.perform_later(#{arguments.map(&:inspect).join(",")}) [ #{parsed_schedule.original} ]" end |
#valid? ⇒ Boolean
54 55 56 |
# File 'lib/solid_queue/dispatcher/recurring_task.rb', line 54 def valid? parsed_schedule.instance_of?(Fugit::Cron) end |