sidetiq 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ 0.1.5
2
+ -----
3
+
4
+ - Allow jobs to be scheduled for immediate runs via the web extension.
data/README.md CHANGED
@@ -110,23 +110,23 @@ Sidetiq.configure do |config|
110
110
  end
111
111
  ```
112
112
 
113
- ## WEB EXTENSION
113
+ ## NOTES
114
114
 
115
- Sidetiq includes an extension for Sidekiq's web interface. It will not be
116
- loaded by default, so it will have to be required manually:
115
+ By default Sidekiq uses a 15 second polling interval to check if scheduled
116
+ jobs are due. If a recurring job has to run more often than that you should
117
+ lower this value.
117
118
 
118
119
  ```ruby
119
- require 'sidetiq/web'
120
+ Sidekiq.options[:poll_interval] = 1
120
121
  ```
121
122
 
122
- ### NOTES
123
+ ## WEB EXTENSION
123
124
 
124
- By default Sidekiq uses a 15 second polling interval to check if scheduled
125
- jobs are due. If a recurring job has to run more often than that you should
126
- lower this value.
125
+ Sidetiq includes an extension for Sidekiq's web interface. It will not be
126
+ loaded by default, so it will have to be required manually:
127
127
 
128
128
  ```ruby
129
- Sidekiq.options[:poll_interval] = 1
129
+ require 'sidetiq/web'
130
130
  ```
131
131
 
132
132
  ### SCREENSHOT
@@ -8,7 +8,7 @@ module Sidetiq
8
8
  MINOR = 1
9
9
 
10
10
  # Public: Sidetiq patch level.
11
- PATCH = 4
11
+ PATCH = 5
12
12
 
13
13
  # Public: String representation of the current Sidetiq version.
14
14
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
@@ -12,12 +12,13 @@ header.row
12
12
  - @schedules.each do |worker, schedule|
13
13
  tr
14
14
  td
15
- = worker.name
15
+ a href="#{root_path}sidetiq/#{worker.name}"= worker.name
16
16
  td= worker.get_sidekiq_options['queue']
17
17
  td
18
18
  == relative_time(schedule.next_occurrence(@time))
19
19
  td
20
- a href="#{root_path}sidetiq/#{worker.name}" Details
20
+ form action="#{root_path}sidetiq/#{worker.name}/trigger" method="post"
21
+ input.btn.btn-danger.btn-small type="submit" name="trigger" value="Trigger" data-confirm="Are you sure you want to trigger this job?"
21
22
  - else
22
23
  .alert.alert-success No recurring jobs found.
23
24
 
data/lib/sidetiq/web.rb CHANGED
@@ -5,27 +5,45 @@ module Sidetiq
5
5
  VIEWS = File.expand_path('views', File.dirname(__FILE__))
6
6
 
7
7
  def self.registered(app)
8
+ app.helpers do
9
+ def sidetiq_clock
10
+ Sidetiq::Clock.instance
11
+ end
12
+
13
+ def sidetiq_schedules
14
+ sidetiq_clock.schedules
15
+ end
16
+ end
17
+
8
18
  app.get "/sidetiq" do
9
- clock = Sidetiq::Clock.instance
10
- @schedules = clock.schedules
11
- @time = clock.gettime
19
+ @schedules = sidetiq_schedules
20
+ @time = sidetiq_clock.gettime
12
21
  slim File.read(File.join(VIEWS, 'sidetiq.slim'))
13
22
  end
14
23
 
15
24
  app.get "/sidetiq/:name" do
16
25
  halt 404 unless (name = params[:name])
17
26
 
18
- clock = Sidetiq::Clock.instance
19
- schedules = clock.schedules
20
-
21
- @time = clock.gettime
27
+ @time = sidetiq_clock.gettime
22
28
 
23
- @worker, @schedule = schedules.select do |worker, schedule|
29
+ @worker, @schedule = sidetiq_schedules.select do |worker, schedule|
24
30
  worker.name == name
25
31
  end.flatten
26
32
 
27
33
  slim File.read(File.join(VIEWS, 'sidetiq_details.slim'))
28
34
  end
35
+
36
+ app.post "/sidetiq/:name/trigger" do
37
+ halt 404 unless (name = params[:name])
38
+
39
+ worker, _ = sidetiq_schedules.select do |worker, schedule|
40
+ worker.name == name
41
+ end.flatten
42
+
43
+ worker.perform_async
44
+
45
+ redirect "#{root_path}sidetiq"
46
+ end
29
47
  end
30
48
  end
31
49
  end
data/test/test_web.rb CHANGED
@@ -20,6 +20,15 @@ class TestWeb < Sidetiq::TestCase
20
20
  Sidekiq::Web
21
21
  end
22
22
 
23
+ def host
24
+ last_request.host
25
+ end
26
+
27
+ def setup
28
+ super
29
+ Worker.jobs.clear
30
+ end
31
+
23
32
  def test_home_tab
24
33
  get '/'
25
34
  assert_equal 200, last_response.status
@@ -54,5 +63,12 @@ class TestWeb < Sidetiq::TestCase
54
63
  assert_match /#{time.getutc.to_s}/, last_response.body
55
64
  end
56
65
  end
66
+
67
+ def test_trigger
68
+ post "/sidetiq/#{Worker.name}/trigger"
69
+ assert_equal 302, last_response.status
70
+ assert_equal "http://#{host}/sidetiq", last_response.location
71
+ assert_equal 1, Worker.jobs.size
72
+ end
57
73
  end
58
74
 
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: sidetiq
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.4
5
+ version: 0.1.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Tobias Svensson
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-04 00:00:00.000000000 Z
12
+ date: 2013-02-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  version_requirements: !ruby/object:Gem::Requirement
@@ -53,6 +53,7 @@ extra_rdoc_files: []
53
53
  files:
54
54
  - .gitignore
55
55
  - .travis.yml
56
+ - CHANGELOG.md
56
57
  - Gemfile
57
58
  - LICENSE
58
59
  - README.md