sidekiq-scheduler 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 743371bafeb924ead436bf1af7be4a04d1643c34
4
- data.tar.gz: 51dd55ce2e46e04c9a7f5ff682f7efb7edb1215d
3
+ metadata.gz: e6fb5253c21173ba4c38ff783846ebf9f7e66f80
4
+ data.tar.gz: d5a0226a5ca48169389447ba69e4f3d1b2d61a8e
5
5
  SHA512:
6
- metadata.gz: 3a6c82f077edeeee2700ad78fcf0890e5ebfe7f67f649aca84c98de5b0eaa2310bf24438f0d8e4e1f3dc1aaba1b735db5d063a5e61945eab5a4ebef8d59aa15e
7
- data.tar.gz: 1928654824078d46092657a1e6f3b8033066e889119438afc7c2e48ba7b5c0611dd113c868fa9225274f67f1b26c88125f1531bbbcf603a811464127c66ea176
6
+ metadata.gz: e09e5fda75f41ad8ceefdc6fe37940e4a678abd56422015004cab1b88741e945178b1f79ee3c23749d5c04610529a9fde600804e28c601b6f9fb96050c404c30
7
+ data.tar.gz: 4130fbe4f5a93b7030f0822c78e2e8e99c8a5d71064127a97ee7ed6c4def928691bdb5cef4609ce7c2304b859a62950224397d4d78240723e13433b2c3d4d071
@@ -1,5 +1,5 @@
1
1
  module SidekiqScheduler
2
2
 
3
- VERSION = '2.0.1'
3
+ VERSION = '2.0.2'
4
4
 
5
5
  end
@@ -10,6 +10,12 @@ module SidekiqScheduler
10
10
 
11
11
  erb File.read(File.join(VIEW_PATH, 'recurring_jobs.erb'))
12
12
  end
13
+
14
+ app.get '/recurring-jobs/:name/enqueue' do
15
+ schedule = Sidekiq.get_schedule(params[:name])
16
+ Sidekiq::Scheduler.enqueue_job(schedule)
17
+ redirect to('/recurring-jobs')
18
+ end
13
19
  end
14
20
  end
15
21
  end
@@ -104,7 +104,7 @@ module Sidekiq
104
104
  @@scheduled_jobs[name] = self.rufus_scheduler.send(interval_type, *args, opts) do
105
105
  logger.info "queueing #{config['class']} (#{name})"
106
106
  config.delete(interval_type)
107
- self.handle_errors { self.enqueue_from_config(config) }
107
+ self.handle_errors { self.enqueue_job(config) }
108
108
  end
109
109
 
110
110
  interval_defined = true
@@ -134,17 +134,17 @@ module Sidekiq
134
134
  end
135
135
 
136
136
  # Enqueue a job based on a config hash
137
- def self.enqueue_from_config(job_config)
137
+ def self.enqueue_job(job_config)
138
138
  config = job_config.dup
139
139
 
140
- config['class'] = if config['class'].is_a?(String)
141
- config['class'].constantize
142
- else
143
- config['class']
144
- end
140
+ config['class'] = config['class'].constantize if config['class'].is_a?(String)
145
141
  config['args'] = Array(config['args'])
146
142
 
147
- Sidekiq::Client.push(config)
143
+ if defined?(ActiveJob) && config['class'].included_modules.include?(ActiveJob::Enqueuing)
144
+ config['class'].new.enqueue(config)
145
+ else
146
+ Sidekiq::Client.push(config)
147
+ end
148
148
  end
149
149
 
150
150
  def self.rufus_scheduler_options
@@ -47,10 +47,10 @@ class ManagerTest < Minitest::Test
47
47
  'args' => ['/tmp']
48
48
  }
49
49
  )
50
- Sidekiq::Scheduler.enqueue_from_config(config)
50
+ Sidekiq::Scheduler.enqueue_job(config)
51
51
  end
52
52
 
53
- it 'enqueue_from_config respects queue params' do
53
+ it 'enqueue_job respects queue params' do
54
54
  config = {
55
55
  'cron' => '* * * * *',
56
56
  'class' => 'SomeIvarJob',
@@ -66,7 +66,7 @@ class ManagerTest < Minitest::Test
66
66
  }
67
67
  )
68
68
 
69
- Sidekiq::Scheduler.enqueue_from_config(config)
69
+ Sidekiq::Scheduler.enqueue_job(config)
70
70
  end
71
71
 
72
72
  it 'config makes it into the rufus_scheduler' do
@@ -158,7 +158,8 @@ class ManagerTest < Minitest::Test
158
158
  }
159
159
  )
160
160
 
161
- sleep(7)
161
+ Timecop.travel(7 * 60)
162
+ sleep 0.1
162
163
 
163
164
  assert Sidekiq::Scheduler.scheduled_jobs.include?('some_ivar_job')
164
165
  assert Sidekiq::Scheduler.scheduled_jobs.include?('some_ivar_job2')
@@ -10,11 +10,8 @@ class WebTest < MiniTest::Test
10
10
  Sidekiq::Web
11
11
  end
12
12
 
13
- before do
14
- # Sidekiq::WebHelpers expects the Redis client to return an id
15
- Sidekiq.redis { |conn| conn.client.stubs(:id).returns('redis://127.0.0.1:1234/0') }
16
-
17
- Sidekiq.schedule = {
13
+ let(:jobs) do
14
+ {
18
15
  'Foo Job' => {
19
16
  'class' => 'FooClass',
20
17
  'cron' => '0 * * * * US/Eastern',
@@ -31,9 +28,18 @@ class WebTest < MiniTest::Test
31
28
  }
32
29
  end
33
30
 
31
+ before do
32
+ # Sidekiq::WebHelpers expects the Redis client to return an id
33
+ Sidekiq.redis { |conn| conn.client.stubs(:id).returns('redis://127.0.0.1:1234/0') }
34
+
35
+ Sidekiq.schedule = jobs
36
+ end
37
+
34
38
  it 'shows schedule' do
35
39
  get '/recurring-jobs'
36
40
 
41
+ assert(last_response.ok?)
42
+
37
43
  assert_match(/Foo Job/, last_response.body)
38
44
  assert_match(/FooClass/, last_response.body)
39
45
  assert_match(/0 \* \* \* \* US\/Eastern/, last_response.body)
@@ -46,6 +52,21 @@ class WebTest < MiniTest::Test
46
52
  assert_match(/1h/, last_response.body)
47
53
  assert_match(/special/, last_response.body)
48
54
  assert_match(/\[\"foo\", \"bar\"\]/, last_response.body)
55
+
56
+ assert_match(/Enqueue now/, last_response.body)
57
+ end
58
+
59
+ it 'enqueues particular job' do
60
+ job_name = jobs.keys.first
61
+ job = jobs[job_name]
62
+
63
+ Sidekiq::Scheduler.expects(:enqueue_job).with(job)
64
+
65
+ get "/recurring-jobs/#{URI.escape(job_name)}/enqueue"
66
+
67
+ assert(last_response.redirect?)
68
+ follow_redirect!
69
+ assert_equal(last_request.path, '/recurring-jobs')
49
70
  end
50
71
  end
51
72
  end
@@ -11,6 +11,7 @@ require 'sidekiq-scheduler'
11
11
  require 'mocha/setup'
12
12
  require 'multi_json'
13
13
  require 'mock_redis'
14
+ require 'timecop'
14
15
 
15
16
  require 'sidekiq'
16
17
  require 'sidekiq/util'
@@ -10,6 +10,7 @@
10
10
  <th>Class</th>
11
11
  <th>Queue</th>
12
12
  <th>Arguments</th>
13
+ <th></th>
13
14
  </tr>
14
15
  </thead>
15
16
 
@@ -24,8 +25,13 @@
24
25
  <a href="<%= root_path %>queues/<%= job_spec.fetch('queue', 'default') %>"><%= job_spec.fetch('queue', 'default') %></a>
25
26
  </td>
26
27
  <td><%= job_spec['args'] %></td>
28
+ <td class="text-center">
29
+ <a class="btn btn-warn btn-xs" href="<%= root_path %>recurring-jobs/<%= URI.escape(name) %>/enqueue">
30
+ Enqueue now
31
+ </a>
32
+ </td>
27
33
  </tr>
28
34
  <% end %>
29
35
  </tbody>
30
36
  </table>
31
- </div>
37
+ </div>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-scheduler
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Morton Jonuschat
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-12-20 00:00:00.000000000 Z
12
+ date: 2016-01-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sidekiq