Module: Delayed::Task
- Defined in:
- lib/delayed/recurring_job.rb
Overview
RecurringJob
Class Method Summary collapse
-
.new(name, options, &block) ⇒ Object
Creates a new class wrapper around a block of code to be scheduled.
-
.schedule(name_or_options = {}, options = {}, &block) ⇒ Object
Schedule a block of code on-the-fly.
Class Method Details
.new(name, options, &block) ⇒ Object
Creates a new class wrapper around a block of code to be scheduled.
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/delayed/recurring_job.rb', line 199 def self.new(name, , &block) task_class = Class.new task_class.class_eval do include Delayed::RecurringJob def display_name self.class.name end def perform block.call end end Object.const_set(name, task_class) if name task_class.schedule() return task_class end |
.schedule(name_or_options = {}, options = {}, &block) ⇒ Object
Schedule a block of code on-the-fly. This is a friendly wrapper for using Task.new without an explicit constant assignment. Delayed::Task.schedule(‘MyNewTask’, run_every: 10.minutes, run_at: 1.minute.from_now)do_some_stuff_here or Delayed::Task.schedule(run_every: 10.minutes, run_at: 1.minute.from_now)do_some_stuff_here
223 224 225 226 227 228 229 230 231 232 |
# File 'lib/delayed/recurring_job.rb', line 223 def self.schedule(={}, ={}, &block) case when Hash name, = nil, else name = end self.new name, , &block end |