mirror of
https://github.com/endofunky/sidetiq.git
synced 2022-11-09 13:53:30 -05:00
Allow jobs to be scheduled immediately via the web extension.
This commit is contained in:
parent
f90d6308f2
commit
c8faeadb82
3 changed files with 45 additions and 10 deletions
|
@ -12,12 +12,13 @@ header.row
|
|||
- @schedules.each do |worker, schedule|
|
||||
tr
|
||||
td
|
||||
= worker.name
|
||||
a href="#{root_path}sidetiq/#{worker.name}"= worker.name
|
||||
td= worker.get_sidekiq_options['queue']
|
||||
td
|
||||
== relative_time(schedule.next_occurrence(@time))
|
||||
td
|
||||
a href="#{root_path}sidetiq/#{worker.name}" Details
|
||||
form action="#{root_path}sidetiq/#{worker.name}/trigger" method="post"
|
||||
input.btn.btn-danger.btn-small type="submit" name="trigger" value="Trigger" data-confirm="Are you sure you want to trigger this job?"
|
||||
- else
|
||||
.alert.alert-success No recurring jobs found.
|
||||
|
||||
|
|
|
@ -5,27 +5,45 @@ module Sidetiq
|
|||
VIEWS = File.expand_path('views', File.dirname(__FILE__))
|
||||
|
||||
def self.registered(app)
|
||||
app.helpers do
|
||||
def sidetiq_clock
|
||||
Sidetiq::Clock.instance
|
||||
end
|
||||
|
||||
def sidetiq_schedules
|
||||
sidetiq_clock.schedules
|
||||
end
|
||||
end
|
||||
|
||||
app.get "/sidetiq" do
|
||||
clock = Sidetiq::Clock.instance
|
||||
@schedules = clock.schedules
|
||||
@time = clock.gettime
|
||||
@schedules = sidetiq_schedules
|
||||
@time = sidetiq_clock.gettime
|
||||
slim File.read(File.join(VIEWS, 'sidetiq.slim'))
|
||||
end
|
||||
|
||||
app.get "/sidetiq/:name" do
|
||||
halt 404 unless (name = params[:name])
|
||||
|
||||
clock = Sidetiq::Clock.instance
|
||||
schedules = clock.schedules
|
||||
@time = sidetiq_clock.gettime
|
||||
|
||||
@time = clock.gettime
|
||||
|
||||
@worker, @schedule = schedules.select do |worker, schedule|
|
||||
@worker, @schedule = sidetiq_schedules.select do |worker, schedule|
|
||||
worker.name == name
|
||||
end.flatten
|
||||
|
||||
slim File.read(File.join(VIEWS, 'sidetiq_details.slim'))
|
||||
end
|
||||
|
||||
app.post "/sidetiq/:name/trigger" do
|
||||
halt 404 unless (name = params[:name])
|
||||
|
||||
worker, _ = sidetiq_schedules.select do |worker, schedule|
|
||||
worker.name == name
|
||||
end.flatten
|
||||
|
||||
worker.perform_async
|
||||
|
||||
redirect "#{root_path}sidetiq"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,6 +20,15 @@ class TestWeb < Sidetiq::TestCase
|
|||
Sidekiq::Web
|
||||
end
|
||||
|
||||
def host
|
||||
last_request.host
|
||||
end
|
||||
|
||||
def setup
|
||||
super
|
||||
Worker.jobs.clear
|
||||
end
|
||||
|
||||
def test_home_tab
|
||||
get '/'
|
||||
assert_equal 200, last_response.status
|
||||
|
@ -54,5 +63,12 @@ class TestWeb < Sidetiq::TestCase
|
|||
assert_match /#{time.getutc.to_s}/, last_response.body
|
||||
end
|
||||
end
|
||||
|
||||
def test_trigger
|
||||
post "/sidetiq/#{Worker.name}/trigger"
|
||||
assert_equal 302, last_response.status
|
||||
assert_equal "http://#{host}/sidetiq", last_response.location
|
||||
assert_equal 1, Worker.jobs.size
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue