resque-scheduler-web 0.0.4 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0e0d9ae424811136f0f35b1c596f174b5e452d56
4
- data.tar.gz: 558a1cc70f5fb9262acc90eae0977f6e15917f88
3
+ metadata.gz: b22c9cd715e57dce44caa7853e7e08d4e350d2f4
4
+ data.tar.gz: 7373cef2f98ff902b01525ecd803d89cd800028a
5
5
  SHA512:
6
- metadata.gz: 4a179c41dd6f5c3a9f8366e00adf05956006adcf0b1d9be60587b61607bf4c9da9deb435362d0903fb1ebf52c976003799b8b07f4ddd9ec9cc14ba523ce8ed80
7
- data.tar.gz: 1a064fb3d53f6a127e95001a2284f165920a627b8b9d2d91ce69366afaa8030a252b8060e5d14e8f7b32eef300b99af7f8703f839c9a407dcf65c2ed10904fe1
6
+ metadata.gz: bc136875c3fe92e0bfd7901f64aa172fa3618126fe2eb0837475bbb920c4811ff5dc6a72db848d1873db0b56ebdeb14026668d1145582e044adee4e23275cf33
7
+ data.tar.gz: 73c33314f777d50f0a0c390f8bd59befa2430e0bccab88ab6b6488a14d355c607d6b3475304b07c54b203046514afc460a6c45158a7d7d4e94473b1f46d2152c
data/README.md CHANGED
@@ -7,9 +7,22 @@
7
7
  [![Dependency Status](https://gemnasium.com/mattgibson/resque-scheduler-web.svg)](https://gemnasium.com/mattgibson/resque-scheduler-web)
8
8
  [![Build Status](https://travis-ci.org/mattgibson/resque-scheduler-web.svg?branch=master)](https://travis-ci.org/mattgibson/resque-scheduler-web)
9
9
 
10
- This gem provides tabs in [Resque Web](https://github.com/resque/resque-web)
11
- for managing [Resque Scheduler](https://github.com/resque/resque-scheduler). It uses the
12
- new Rails Engine approach, rather than the old Sinatra one.
10
+ This gem provides tabs in [Resque Web](https://github.com/resque/resque-web) for managing
11
+ [Resque Scheduler](https://github.com/resque/resque-scheduler).
12
+
13
+ It works with any version
14
+ of Resque and Resque Scheduler, but requires the [Resque Web gem](https://github.com/resque/resque-web),
15
+ rather than the older [Resque Web Sinatra interface](https://github.com/resque/resque/tree/1-x-stable#the-front-end)
16
+ that comes bundled with Resque 1.x.
17
+
18
+ This gem is a port of the old Sinatra code to the new REsque Web plugin architecture and has better test coverage
19
+ and a number of bug fixes compared to the older Resque Scheduler Sinatra code
20
+ which it is based on. The only reason to use the old Sinatra interface right now is if you have other
21
+ Resque plugins that have web interfaces that you need, but which have not been upgraded for the new Resque Web gem yet.
22
+
23
+ The Sinatra interface will be deprecated when Resque 2 is released, so if you want
24
+ to get ahead of the curve, you can start using the latest Resque Web gem today.
25
+
13
26
 
14
27
  ## Installation
15
28
 
@@ -21,19 +21,9 @@ module ResqueWeb
21
21
  klass = Resque::Scheduler::Util.constantize(params[:klass])
22
22
  @args = params[:args] ? JSON.load(URI.decode(params[:args])) : []
23
23
 
24
- # ActiveJob hack. The wrapper class does not know what queue the
25
- # wrapped class wants to use, so we need to tell Resque Scheduler
26
- # the queue, rather than have it use Resque's internal guessing
27
- # mechanism.
28
- if klass.to_s == 'ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper'
29
- queue_name = @args.first['queue_name']
30
- hashed_job = Resque.send :job_to_hash_with_queue, queue_name, klass, @args
31
- search = Resque.send :encode, hashed_job
32
- @timestamps = Resque.instance_eval do
33
- redis.smembers("timestamps:#{search}").map do |key|
34
- key.tr('delayed:', '').to_i
35
- end
36
- end
24
+ if this_is_the_activejob_wrapper(klass)
25
+ # @timestamps = get_timestamps_for_activejob_wrapper(klass)
26
+ @timestamps = ActiveJobWrapperTimestampFinder.new(@args).perform
37
27
  else
38
28
  @timestamps = Resque.scheduled_at(klass, *@args)
39
29
  end
@@ -82,6 +72,12 @@ module ResqueWeb
82
72
  @size = Resque.delayed_timestamp_size(@timestamp)
83
73
  @jobs = Resque.delayed_timestamp_peek(@timestamp, @start, 20)
84
74
  end
75
+
76
+ protected
77
+
78
+ def this_is_the_activejob_wrapper(klass)
79
+ klass.to_s == 'ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper'
80
+ end
85
81
  end
86
82
  end
87
83
  end
@@ -12,27 +12,18 @@ module ResqueWeb
12
12
  # GET /schedule
13
13
  def index
14
14
  Resque.reload_schedule! if Resque::Scheduler.dynamic
15
- jobs_in_this_env = Resque.schedule.select do |name|
16
- scheduled_in_this_env?(name)
17
- end
18
- keys = jobs_in_this_env.keys.sort
19
- @scheduled_jobs = keys.inject({}) do |jobs, job_name|
20
- jobs.merge(job_name => Resque.schedule[job_name])
21
- end
15
+ @scheduled_jobs = scheduled_jobs_in_alphabetical_order
22
16
  end
23
17
 
24
18
  # DELETE /schedule
25
19
  def destroy
26
- if Resque::Scheduler.dynamic
27
- job_name = params['job_name'] || params[:job_name]
28
- Resque.remove_schedule(job_name)
29
- end
20
+ Resque.remove_schedule(params[:job_name]) if Resque::Scheduler.dynamic
30
21
  redirect_to Engine.app.url_helpers.schedules_path
31
22
  end
32
23
 
33
24
  # POST /schedule/requeue
34
25
  def requeue
35
- @job_name = params['job_name'] || params[:job_name]
26
+ @job_name = params[:job_name]
36
27
  config = Resque.schedule[@job_name]
37
28
  @parameters = config['parameters'] || config[:parameters]
38
29
  if @parameters
@@ -46,20 +37,34 @@ module ResqueWeb
46
37
  # POST /schedule/requeue_with_params
47
38
  def requeue_with_params
48
39
  config = Resque.schedule[params[:job_name]]
49
- # Build args hash from post data (removing the job name)
50
- submitted_args = params.reject do |key, _value|
40
+ new_config = original_config_merged_with_submitted_params(config)
41
+ Resque::Scheduler.enqueue_from_config(new_config)
42
+ redirect_to ResqueWeb::Engine.app.url_helpers.overview_path
43
+ end
44
+
45
+ protected
46
+
47
+ def original_config_merged_with_submitted_params(config)
48
+ existing_config_args = config['args'] || config[:args] || {}
49
+ new_config_args = existing_config_args.merge(submitted_params_for_job)
50
+ config.merge('args' => new_config_args)
51
+ end
52
+
53
+ # Build args hash from post data (removing the job name)
54
+ def submitted_params_for_job
55
+ params.reject do |key, _value|
51
56
  %w(job_name action controller).include?(key)
52
57
  end
58
+ end
53
59
 
54
- # Merge constructed args hash with existing args hash for
55
- # the job, if it exists
56
- existing_config_args = config['args'] || config[:args] || {}
57
- new_config_args = existing_config_args.merge(submitted_args)
60
+ def jobs_in_this_env
61
+ Resque.schedule.select { |name| scheduled_in_this_env?(name) }
62
+ end
58
63
 
59
- # Insert the args hash into config and queue the resque job
60
- config = config.merge('args' => new_config_args)
61
- Resque::Scheduler.enqueue_from_config(config)
62
- redirect_to ResqueWeb::Engine.app.url_helpers.overview_path
64
+ def scheduled_jobs_in_alphabetical_order
65
+ jobs_in_this_env.keys.sort.inject({}) do |jobs, job_name|
66
+ jobs.merge(job_name => Resque.schedule[job_name])
67
+ end
63
68
  end
64
69
  end
65
70
  end
@@ -0,0 +1,44 @@
1
+ module ResqueWeb
2
+ module Plugins
3
+ module ResqueScheduler
4
+ # The way ActiveJob works breaks Resque Scheduler's method for finding
5
+ # the timestamps when jobs have been scheduled. This is because the
6
+ # queue name is stored as a parameter and is not accessible as an instance
7
+ # variable or via a class method. This class is used by the controller
8
+ # to handle the special case.
9
+ class ActiveJobWrapperTimestampFinder
10
+ def initialize(args)
11
+ @args = args
12
+ end
13
+
14
+ def perform
15
+ search_string = "timestamps:#{encoded_search_string}"
16
+ Resque.instance_eval do
17
+ redis.smembers(search_string).map do |key|
18
+ key.tr('delayed:', '').to_i
19
+ end
20
+ end
21
+ end
22
+
23
+ def encoded_search_string
24
+ Resque.send :encode, hashed_job
25
+ end
26
+
27
+ def hashed_job
28
+ Resque.send :job_to_hash_with_queue,
29
+ queue_name,
30
+ active_job_wrapper_class_name,
31
+ @args
32
+ end
33
+
34
+ def queue_name
35
+ @args.first['queue_name']
36
+ end
37
+
38
+ def active_job_wrapper_class_name
39
+ 'ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper'
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -1,7 +1,7 @@
1
1
  module Resque
2
2
  module Scheduler
3
3
  module Web
4
- VERSION = '0.0.4'
4
+ VERSION = '1.0.0'
5
5
  end
6
6
  end
7
7
  end
@@ -17,16 +17,17 @@ Gem::Specification.new do |spec|
17
17
  'Resque 1.x'
18
18
  spec.homepage = 'https://github.com/mattgibson/resque-scheduler-web'
19
19
  spec.license = 'MIT'
20
+ spec.required_ruby_version = '>= 1.9.3'
20
21
 
21
22
  spec.files = `git ls-files -z`.split("\x0")
22
23
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
23
24
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
24
25
  spec.require_paths = ['lib']
25
26
 
26
- spec.add_runtime_dependency 'resque-web', '~> 0'
27
+ spec.add_runtime_dependency 'resque-web', '~> 0.0.8'
27
28
  spec.add_runtime_dependency 'resque-scheduler', '~> 4.0'
28
29
 
29
- spec.add_development_dependency 'bundler', '~> 1.6'
30
+ spec.add_development_dependency 'bundler', '~> 1.9'
30
31
  spec.add_development_dependency 'rake', '~> 10.0'
31
32
  spec.add_development_dependency 'rails', '~> 4.2'
32
33
  spec.add_development_dependency 'sqlite3', '~> 1.3'
@@ -35,7 +36,7 @@ Gem::Specification.new do |spec|
35
36
  spec.add_development_dependency 'codeclimate-test-reporter', '~> 0'
36
37
  spec.add_development_dependency 'rubocop', '~> 0'
37
38
  spec.add_development_dependency 'rubocop-rspec', '~> 1.0'
38
- spec.add_development_dependency 'launchy', '~> 0'
39
+ spec.add_development_dependency 'launchy', '~> 2.4'
39
40
  # Avoids non-thread-safe error.
40
41
  spec.add_development_dependency 'sass', '~> 3.4'
41
42
  end
@@ -1,7 +1,6 @@
1
1
  require 'rails_helper'
2
2
 
3
3
  feature 'cancelling a delayed job' do
4
-
5
4
  include SharedFunctionsForFeatures
6
5
 
7
6
  scenario 'cancelling the job from the search page' do
@@ -25,4 +24,4 @@ feature 'cancelling a delayed job' do
25
24
  def and_the_job_should_not_be_present_on_the_page
26
25
  expect(page).to_not have_content 'SomeIvarJob'
27
26
  end
28
- end
27
+ end
@@ -1,7 +1,6 @@
1
1
  require 'rails_helper'
2
2
 
3
3
  feature 'clearing all of the delayed jobs' do
4
-
5
4
  include SharedFunctionsForFeatures
6
5
 
7
6
  scenario 'clearing the jobs from the delayed index' do
@@ -20,5 +19,4 @@ feature 'clearing all of the delayed jobs' do
20
19
  def and_i_click_the_clear_all_jobs_button
21
20
  click_button 'Clear All Delayed Jobs'
22
21
  end
23
-
24
- end
22
+ end
@@ -1,7 +1,6 @@
1
1
  require 'rails_helper'
2
2
 
3
3
  feature 'seeing all the delayed jobs on the index page' do
4
-
5
4
  include SharedFunctionsForFeatures
6
5
 
7
6
  scenario 'delayed jobs show up on the page when at different times' do
@@ -1,7 +1,6 @@
1
1
  require 'rails_helper'
2
2
 
3
3
  feature 'seeing all of the timestamps where a class is delayed' do
4
-
5
4
  include SharedFunctionsForFeatures
6
5
 
7
6
  scenario 'viewing the timestamps page with no params' do
@@ -26,11 +25,15 @@ feature 'seeing all of the timestamps where a class is delayed' do
26
25
  end
27
26
 
28
27
  def then_i_should_be_on_the_delayed_class_page
29
- expect(current_path).to eq resque_scheduler_engine_routes.delayed_job_class_path klass: 'SomeIvarJob'
28
+ path_params = {klass: 'SomeIvarJob'}
29
+ path = resque_scheduler_engine_routes.delayed_job_class_path path_params
30
+ expect(current_path).to eq path
30
31
  end
31
32
 
32
33
  def then_i_should_be_on_the_delayed_class_page_with_params
33
- expect(current_path).to eq resque_scheduler_engine_routes.delayed_job_class_path klass: 'JobWithParams'
34
+ path_params = {klass: 'JobWithParams'}
35
+ path = resque_scheduler_engine_routes.delayed_job_class_path path_params
36
+ expect(current_path).to eq path
34
37
  end
35
38
 
36
39
  def and_i_should_see_the_timestamp_on_the_page
@@ -38,7 +41,9 @@ feature 'seeing all of the timestamps where a class is delayed' do
38
41
  end
39
42
 
40
43
  def given_there_is_a_delayed_job_with_params
41
- Resque.enqueue_at(some_time_in_the_future, JobWithParams, argument: 'thingy')
44
+ Resque.enqueue_at(some_time_in_the_future,
45
+ JobWithParams,
46
+ argument: 'thingy')
42
47
  end
43
48
 
44
49
  def given_there_is_a_delayed_job_with_active_job
@@ -50,6 +55,8 @@ feature 'seeing all of the timestamps where a class is delayed' do
50
55
  end
51
56
 
52
57
  def then_i_should_be_on_the_timestamp_page
53
- expect(current_path).to eq resque_scheduler_engine_routes.timestamp_path timestamp: some_time_in_the_future.to_i
58
+ path_params = { timestamp: some_time_in_the_future.to_i }
59
+ path = resque_scheduler_engine_routes.timestamp_path path_params
60
+ expect(current_path).to eq path
54
61
  end
55
62
  end
@@ -1,7 +1,6 @@
1
1
  require 'rails_helper'
2
2
 
3
3
  feature 'Sending a delayed job to the queue for immediate execution' do
4
-
5
4
  include SharedFunctionsForFeatures
6
5
 
7
6
  let(:queue_name) { 'ivar' }
@@ -26,4 +25,4 @@ feature 'Sending a delayed job to the queue for immediate execution' do
26
25
  def then_i_should_not_see_any_delayed_jobs
27
26
  expect(page).to have_content 'There are no delayed jobs'
28
27
  end
29
- end
28
+ end
@@ -32,5 +32,4 @@ feature 'the tabs added to the resque web interface work correctly' do
32
32
  def then_i_should_be_on_the_delayed_page
33
33
  expect(current_path).to eq resque_scheduler_engine_routes.delayed_path
34
34
  end
35
-
36
35
  end
@@ -1,6 +1,6 @@
1
1
  require 'rails_helper'
2
- feature 'deleting a job from the dynamic schedule' do
3
2
 
3
+ feature 'deleting a job from the dynamic schedule' do
4
4
  include SharedFunctionsForFeatures
5
5
 
6
6
  scenario 'the delete button is not present when the schedule is static' do
@@ -1,7 +1,6 @@
1
1
  require 'rails_helper'
2
2
 
3
3
  feature 'deleting a job from the dynamic schedule' do
4
-
5
4
  include SharedFunctionsForFeatures
6
5
 
7
6
  before do
@@ -1,7 +1,6 @@
1
1
  require 'rails_helper'
2
2
 
3
3
  feature 'requeuing a job that has defined params' do
4
-
5
4
  include SharedFunctionsForFeatures
6
5
 
7
6
  before do
@@ -1,7 +1,6 @@
1
1
  require 'rails_helper'
2
2
 
3
3
  feature 'requeuing a job that has no params' do
4
-
5
4
  include SharedFunctionsForFeatures
6
5
 
7
6
  before do
@@ -42,6 +41,4 @@ feature 'requeuing a job that has no params' do
42
41
  def and_i_requeue_the_job
43
42
  click_button "requeue_job_#{job_name}"
44
43
  end
45
-
46
-
47
44
  end
@@ -1,7 +1,6 @@
1
1
  require 'rails_helper'
2
2
 
3
3
  feature 'Viewing the schedule page and interacting with it' do
4
-
5
4
  include SharedFunctionsForFeatures
6
5
 
7
6
  before do
@@ -90,5 +89,4 @@ feature 'Viewing the schedule page and interacting with it' do
90
89
  def when_i_visit_the_scheduler_page
91
90
  visit resque_scheduler_engine_routes.schedules_path
92
91
  end
93
-
94
92
  end
data/spec/spec_helper.rb CHANGED
@@ -8,7 +8,6 @@ require 'resque-scheduler'
8
8
  require_relative 'support/functions'
9
9
  require_relative 'support/shared_steps'
10
10
 
11
-
12
11
  Resque::Scheduler.configure do |c|
13
12
  c.quiet = true
14
13
  end
@@ -95,4 +94,3 @@ end
95
94
  def resque_scheduler_engine_routes
96
95
  ResqueWeb::Plugins::ResqueScheduler::Engine.app.url_helpers
97
96
  end
98
-
@@ -4,4 +4,4 @@ def reset_the_resque_schedule
4
4
  Resque.schedule = {}
5
5
  Resque::Scheduler.load_schedule!
6
6
  Resque::Scheduler.env = 'test'
7
- end
7
+ end
@@ -1,5 +1,7 @@
1
+ # This should be mixed in to all of the Rspec feature specs so that we can
2
+ # avoid duplication of common functions and can be sure that Resque and the
3
+ # queues will be reset cleanly after each scenario.
1
4
  module SharedFunctionsForFeatures
2
-
3
5
  def self.included(base)
4
6
  base.instance_eval do
5
7
  let(:some_time_in_the_future) { Time.now + 3600 }
@@ -44,4 +46,3 @@ module SharedFunctionsForFeatures
44
46
  expect(page).to have_content job_class
45
47
  end
46
48
  end
47
-
@@ -48,6 +48,8 @@ JobWithoutParams = Class.new(JobWithParams) do
48
48
  @queue = :quick
49
49
  end
50
50
 
51
+ # Allows us to test whether jobs added via the ActiveJob wrapper are correctly
52
+ # handled.
51
53
  class ActiveJobTest < ActiveJob::Base
52
54
  queue_as :test_queue
53
55
 
@@ -56,7 +58,6 @@ class ActiveJobTest < ActiveJob::Base
56
58
  end
57
59
 
58
60
  def perform
59
-
60
61
  end
61
62
  end
62
63
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque-scheduler-web
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Gibson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-02 00:00:00.000000000 Z
11
+ date: 2016-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: resque-web
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 0.0.8
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 0.0.8
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: resque-scheduler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.6'
47
+ version: '1.9'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.6'
54
+ version: '1.9'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -170,14 +170,14 @@ dependencies:
170
170
  requirements:
171
171
  - - "~>"
172
172
  - !ruby/object:Gem::Version
173
- version: '0'
173
+ version: '2.4'
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - "~>"
179
179
  - !ruby/object:Gem::Version
180
- version: '0'
180
+ version: '2.4'
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: sass
183
183
  requirement: !ruby/object:Gem::Requirement
@@ -216,6 +216,7 @@ files:
216
216
  - app/controllers/resque_web/plugins/resque_scheduler/schedules_controller.rb
217
217
  - app/helpers/resque_web/plugins/resque_scheduler/delayed_helper.rb
218
218
  - app/helpers/resque_web/plugins/resque_scheduler/schedules_helper.rb
219
+ - app/models/resque_web/plugins/resque_scheduler/active_job_wrapper_timestamp_finder.rb
219
220
  - app/models/resque_web/plugins/resque_scheduler/job_finder.rb
220
221
  - app/models/resque_web/plugins/resque_scheduler/job_finder/working_job_finder.rb
221
222
  - app/views/resque_web/plugins/resque_scheduler/delayed/_next_more.erb
@@ -309,7 +310,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
309
310
  requirements:
310
311
  - - ">="
311
312
  - !ruby/object:Gem::Version
312
- version: '0'
313
+ version: 1.9.3
313
314
  required_rubygems_version: !ruby/object:Gem::Requirement
314
315
  requirements:
315
316
  - - ">="
@@ -317,7 +318,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
317
318
  version: '0'
318
319
  requirements: []
319
320
  rubyforge_project:
320
- rubygems_version: 2.4.6
321
+ rubygems_version: 2.4.8
321
322
  signing_key:
322
323
  specification_version: 4
323
324
  summary: This gem provides tabs in Resque Web for managing Resque Scheduler.