Class: Procrastinator::Scheduler::UpdateProxy
- Inherits:
-
Object
- Object
- Procrastinator::Scheduler::UpdateProxy
- Defined in:
- lib/procrastinator/scheduler.rb
Overview
Provides a more natural syntax for rescheduling tasks
Instance Method Summary collapse
-
#initialize(queue, identifier:) ⇒ UpdateProxy
constructor
A new instance of UpdateProxy.
-
#to(run_at: nil, expire_at: nil) ⇒ Object
(also: #at)
Updates the task found by the identifier to run at and/or expire at the new provided time.
Constructor Details
#initialize(queue, identifier:) ⇒ UpdateProxy
Returns a new instance of UpdateProxy.
90 91 92 93 |
# File 'lib/procrastinator/scheduler.rb', line 90 def initialize(queue, identifier:) @queue = queue @identifier = identifier.merge(queue: queue.name.to_sym) end |
Instance Method Details
#to(run_at: nil, expire_at: nil) ⇒ Object Also known as: at
Updates the task found by the identifier to run at and/or expire at the new provided time.
100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/procrastinator/scheduler.rb', line 100 def to(run_at: nil, expire_at: nil) task = @queue.fetch_task(@identifier) raise ArgumentError, 'you must provide at least :run_at or :expire_at' if run_at.nil? && expire_at.nil? task.reschedule(expire_at: expire_at) if expire_at task.reschedule(run_at: run_at) if run_at new_data = task.to_h new_data.delete(:queue) new_data.delete(:data) @queue.update(new_data.delete(:id), new_data) end |