Class: ResqueWeb::Plugins::ResqueScheduler::DelayedController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/resque_web/plugins/resque_scheduler/delayed_controller.rb

Overview

Controller for delayed jobs. These have been added to the queue by the application, so here, they can be run immediately, deleted from the queue, or rescheduled.

Instance Method Summary collapse

Instance Method Details

#cancel_nowObject

POST /delayed/cancel_now cancels a specific job based on klass, timestamp and args.



43
44
45
46
47
48
49
# File 'app/controllers/resque_web/plugins/resque_scheduler/delayed_controller.rb', line 43

def cancel_now
  klass = Resque::Scheduler::Util.constantize(params['klass'])
  timestamp = params['timestamp']
  args = Resque.decode params['args']
  Resque.remove_delayed_job_from_timestamp(timestamp, klass, *args)
  redirect_to Engine.app.url_helpers.delayed_path
end

#clearObject

POST /delayed/clear



52
53
54
55
# File 'app/controllers/resque_web/plugins/resque_scheduler/delayed_controller.rb', line 52

def clear
  Resque.reset_delayed_queue
  redirect_to Engine.app.url_helpers.delayed_path
end

#indexObject

GET /delayed



9
10
11
12
13
14
# File 'app/controllers/resque_web/plugins/resque_scheduler/delayed_controller.rb', line 9

def index
  @start = params[:start].to_i
  @number_to_show = 20
  @total_number_of_delayed_jobs = Resque.delayed_queue_schedule_size
  @timestamps = Resque.delayed_queue_peek(@start, @number_to_show)
end

#jobs_klassObject

GET /delayed/jobs/:klass Shows us all of the timestamps where jobs of this type, with these args are currently scheduled as delayed jobs. Accessed by clicking the ‘All schedules’ link next to a delayed job.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/resque_web/plugins/resque_scheduler/delayed_controller.rb', line 20

def jobs_klass
  klass = Resque::Scheduler::Util.constantize(params[:klass])
  @args = params[:args] ? JSON.load(URI.decode(params[:args])) : []

  if this_is_the_activejob_wrapper(klass)
    # @timestamps = get_timestamps_for_activejob_wrapper(klass)
    @timestamps = ActiveJobWrapperTimestampFinder.new(@args).perform
  else
    @timestamps = Resque.scheduled_at(klass, *@args)
  end
rescue
  # Should this be a rescue? Seems to cover the case of the params
  # not validating or something.
  @timestamps = []
end

#queue_nowObject

POST /delayed/queue_now Sends ALL of the delayed jobs at a particular timestamp to the queue, regardless of their details.



60
61
62
63
64
65
66
# File 'app/controllers/resque_web/plugins/resque_scheduler/delayed_controller.rb', line 60

def queue_now
  timestamp = params['timestamp'].to_i
  if timestamp > 0
    Resque::Scheduler.enqueue_delayed_items_for_timestamp(timestamp)
  end
  redirect_to ResqueWeb::Engine.app.url_helpers.overview_path
end

#searchObject

POST /delayed/search



37
38
39
# File 'app/controllers/resque_web/plugins/resque_scheduler/delayed_controller.rb', line 37

def search
  @jobs = JobFinder.new(params[:search]).find_jobs
end

#timestampObject

GET /delayed/:timestamp



69
70
71
72
73
74
# File 'app/controllers/resque_web/plugins/resque_scheduler/delayed_controller.rb', line 69

def timestamp
  @timestamp = params[:timestamp].to_i
  @start = params[:start].to_i
  @size = Resque.delayed_timestamp_size(@timestamp)
  @jobs = Resque.delayed_timestamp_peek(@timestamp, @start, 20)
end