Module: Resque::Scheduler::Server::ServerMethods

Defined in:
lib/resque/scheduler/server.rb

Instance Method Summary collapse

Instance Method Details

#delayedObject


83
84
85
# File 'lib/resque/scheduler/server.rb', line 83

def delayed
  erb scheduler_template('delayed')
end

#delayed_cancel_nowObject


125
126
127
128
129
130
131
# File 'lib/resque/scheduler/server.rb', line 125

def delayed_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 u('/delayed')
end

#delayed_clearObject


133
134
135
136
# File 'lib/resque/scheduler/server.rb', line 133

def delayed_clear
  Resque.reset_delayed_queue
  redirect u('delayed')
end

#delayed_jobs_klassObject


87
88
89
90
91
92
93
94
95
96
97
# File 'lib/resque/scheduler/server.rb', line 87

def delayed_jobs_klass
  begin
    klass = Resque::Scheduler::Util.constantize(params[:klass])
    @args = JSON.load(URI.decode(params[:args]))
    @timestamps = Resque.scheduled_at(klass, *@args)
  rescue
    @timestamps = []
  end

  erb scheduler_template('delayed_schedules')
end

#delayed_queue_nowObject


108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/resque/scheduler/server.rb', line 108

def delayed_queue_now
  timestamp = params['timestamp'].to_i
  formatted_time = Time.at(timestamp).strftime(
    ::Resque::Scheduler::Server::TIMESTAMP_FORMAT
  )

  if timestamp > 0
    unless Resque::Scheduler.enqueue_next_item(timestamp)
      @error_message = "Unable to remove item at #{formatted_time}"
    end
  else
    @error_message = "Incorrect timestamp #{formatted_time}"
  end

  erb scheduler_template('delayed')
end

#delayed_searchObject


99
100
101
102
# File 'lib/resque/scheduler/server.rb', line 99

def delayed_search
  @jobs = find_job(params[:search])
  erb scheduler_template('search')
end

#delayed_timestampObject


104
105
106
# File 'lib/resque/scheduler/server.rb', line 104

def delayed_timestamp
  erb scheduler_template('delayed_timestamp')
end

#delete_scheduleObject


75
76
77
78
79
80
81
# File 'lib/resque/scheduler/server.rb', line 75

def delete_schedule
  if Resque::Scheduler.dynamic
    job_name = params['job_name'] || params[:job_name]
    Resque.remove_schedule(job_name)
  end
  redirect u('/schedule')
end

#scheduleObject


39
40
41
42
# File 'lib/resque/scheduler/server.rb', line 39

def schedule
  Resque.reload_schedule! if Resque::Scheduler.dynamic
  erb scheduler_template('scheduler')
end

#schedule_requeueObject


44
45
46
47
48
49
50
51
52
53
54
# File 'lib/resque/scheduler/server.rb', line 44

def schedule_requeue
  @job_name = params['job_name'] || params[:job_name]
  config = Resque.schedule[@job_name]
  @parameters = config['parameters'] || config[:parameters]
  if @parameters
    erb scheduler_template('requeue-params')
  else
    Resque::Scheduler.enqueue_from_config(config)
    redirect u('/overview')
  end
end

#schedule_requeue_with_paramsObject


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/resque/scheduler/server.rb', line 56

def schedule_requeue_with_params
  job_name = params['job_name'] || params[:job_name]
  config = Resque.schedule[job_name]
  # Build args hash from post data (removing the job name)
   = params.reject do |key, _value|
    key == 'job_name' || key == :job_name
  end

  # Merge constructed args hash with existing args hash for
  # the job, if it exists
  config_args = config['args'] || config[:args] || {}
  config_args = config_args.merge()

  # Insert the args hash into config and queue the resque job
  config = config.merge('args' => config_args)
  Resque::Scheduler.enqueue_from_config(config)
  redirect u('/overview')
end