Class: SimpleScheduler::FutureJob

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
lib/simple_scheduler/future_job.rb

Overview

Active Job class that wraps the scheduled job and determines if the job should still be run based on the scheduled time and when the job expires.

Defined Under Namespace

Classes: Expired

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.delete_allObject

Delete all future jobs created by Simple Scheduler from the ‘Sidekiq::ScheduledSet`.



31
32
33
34
35
# File 'lib/simple_scheduler/future_job.rb', line 31

def self.delete_all
  Task.scheduled_set.each do |job|
    job.delete if job.display_class == "SimpleScheduler::FutureJob"
  end
end

Instance Method Details

#perform(task_params, scheduled_time) ⇒ Object

Perform the future job as defined by the task.

Parameters:

  • task_params (Hash)

    The params from the scheduled task

  • scheduled_time (Integer)

    The epoch time for when the job was scheduled to be run

Raises:



22
23
24
25
26
27
28
# File 'lib/simple_scheduler/future_job.rb', line 22

def perform(task_params, scheduled_time)
  @task = Task.new(task_params)
  @scheduled_time = Time.at(scheduled_time).in_time_zone(@task.time_zone)
  raise Expired if expired?

  queue_task
end