Module: Delayed::Task

Defined in:
lib/delayed/recurring_job.rb

Overview

RecurringJob

Class Method Summary collapse

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, options, &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(options)
  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(name_or_options={}, options={}, &block)
  case name_or_options
  when Hash
    name, options = nil, name_or_options
  else
    name = name_or_options
  end

  self.new name, options, &block
end