resque-scheduler 4.0.0 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of resque-scheduler might be problematic. Click here for more details.

@@ -1,5 +1,5 @@
1
1
  <h1>Search Results</h1>
2
- <%= render_partial File.read(File.join(File.dirname(__FILE__), 'server/views/search_form.erb')) %>
2
+ <%= scheduler_view :search_form, layout: false %>
3
3
  <hr>
4
4
  <% delayed = @jobs.select { |j| j['where_at'] == 'delayed' } %>
5
5
  <h1>Delayed jobs</h1>
@@ -70,4 +70,3 @@
70
70
  </table>
71
71
 
72
72
 
73
-
@@ -18,7 +18,7 @@ module Resque
18
18
  signal_queue << sig
19
19
  # break sleep in the primary scheduler thread, alowing
20
20
  # the signal queue to get processed as soon as possible.
21
- @th.wakeup if @th.alive?
21
+ @th.wakeup if @th && @th.alive?
22
22
  end
23
23
  end
24
24
  end
@@ -32,9 +32,7 @@ module Resque
32
32
  end
33
33
 
34
34
  def self.classify(dashed_word)
35
- dashed_word.split('-').each do|part|
36
- part[0] = part[0].chr.upcase
37
- end.join
35
+ dashed_word.split('-').map(&:capitalize).join
38
36
  end
39
37
  end
40
38
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Resque
4
4
  module Scheduler
5
- VERSION = '4.0.0'
5
+ VERSION = '4.1.0'
6
6
  end
7
7
  end
@@ -18,23 +18,25 @@ Gem::Specification.new do |spec|
18
18
  spec.license = 'MIT'
19
19
 
20
20
  spec.files = `git ls-files -z`.split("\0")
21
- spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
22
- spec.test_files = spec.files.grep(/^test\//)
21
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
+ spec.test_files = spec.files.grep(%r{^test/})
23
23
  spec.require_paths = ['lib']
24
24
 
25
25
  spec.add_development_dependency 'bundler'
26
26
  spec.add_development_dependency 'json'
27
27
  spec.add_development_dependency 'kramdown'
28
+ spec.add_development_dependency 'minitest'
28
29
  spec.add_development_dependency 'mocha'
29
30
  spec.add_development_dependency 'pry'
30
31
  spec.add_development_dependency 'rack-test'
31
32
  spec.add_development_dependency 'rake'
32
33
  spec.add_development_dependency 'simplecov'
34
+ spec.add_development_dependency 'test-unit'
33
35
  spec.add_development_dependency 'yard'
34
36
 
35
37
  # We pin rubocop because new cops have a tendency to result in false-y
36
38
  # positives for new contributors, which is not a nice experience.
37
- spec.add_development_dependency 'rubocop', '~> 0.28.0'
39
+ spec.add_development_dependency 'rubocop', '~> 0.35.1'
38
40
 
39
41
  spec.add_runtime_dependency 'mono_logger', '~> 1.0'
40
42
  spec.add_runtime_dependency 'redis', '~> 3.0'
data/test/cli_test.rb CHANGED
@@ -223,4 +223,9 @@ context 'Cli' do
223
223
  Resque::Scheduler.expects(:run)
224
224
  Resque::Scheduler::Cli.run!([], {})
225
225
  end
226
+
227
+ test 'does not create keys for unspecified environment variables' do
228
+ cli = new_cli([], 'DYNAMIC_SCHEDULE' => 'true')
229
+ assert_equal({ dynamic: 'true' }, cli.send(:options))
230
+ end
226
231
  end
@@ -516,6 +516,283 @@ context 'DelayedQueue' do
516
516
  assert_equal(2, Resque.count_all_scheduled_jobs)
517
517
  end
518
518
 
519
+ test 'enqueue_delayed_selection enqueues multiple items matching ' \
520
+ 'arguments at same timestamp' do
521
+ t = Time.now + 120
522
+ Resque.enqueue_at(t, SomeIvarJob, 'bar', 'llama')
523
+ Resque.enqueue_at(t, SomeIvarJob, 'foo')
524
+ Resque.enqueue_at(t, SomeIvarJob, 'bar', 'monkey')
525
+ Resque.enqueue_at(t, SomeIvarJob, 'bar', 'platypus')
526
+ Resque.enqueue_at(t, SomeIvarJob, 'baz')
527
+ Resque.enqueue_at(t, SomeIvarJob, 'bar', 'llama')
528
+ Resque.enqueue_at(t, SomeIvarJob, 'bar', 'llama')
529
+
530
+ assert_equal(5, Resque.enqueue_delayed_selection { |a| a.first == 'bar' })
531
+ assert_equal(2, Resque.count_all_scheduled_jobs)
532
+ end
533
+
534
+ test 'enqueue_delayed_selection enqueues single item matching arguments' do
535
+ t = Time.now + 120
536
+ Resque.enqueue_at(t, SomeIvarJob, 'foo')
537
+ Resque.enqueue_at(t + 1, SomeIvarJob, 'bar')
538
+ Resque.enqueue_at(t + 2, SomeIvarJob, 'bar')
539
+ Resque.enqueue_at(t + 3, SomeIvarJob, 'baz')
540
+
541
+ assert_equal(1, Resque.enqueue_delayed_selection { |a| a.first == 'foo' })
542
+ assert_equal(3, Resque.count_all_scheduled_jobs)
543
+ end
544
+
545
+ test 'enqueue_delayed_selection enqueues multiple items matching arguments' do
546
+ t = Time.now + 120
547
+ Resque.enqueue_at(t, SomeIvarJob, 'foo')
548
+ Resque.enqueue_at(t + 1, SomeIvarJob, 'bar')
549
+ Resque.enqueue_at(t + 2, SomeIvarJob, 'bar')
550
+ Resque.enqueue_at(t + 3, SomeIvarJob, 'baz')
551
+
552
+ assert_equal(2, Resque.enqueue_delayed_selection { |a| a.first == 'bar' })
553
+ assert_equal(2, Resque.count_all_scheduled_jobs)
554
+ end
555
+
556
+ test 'enqueue_delayed_selection enqueues multiple items matching ' \
557
+ 'arguments as hash' do
558
+ t = Time.now + 120
559
+ Resque.enqueue_at(t, SomeIvarJob, foo: 'foo')
560
+ Resque.enqueue_at(t + 1, SomeIvarJob, foo: 'bar')
561
+ Resque.enqueue_at(t + 2, SomeIvarJob, foo: 'bar')
562
+ Resque.enqueue_at(t + 3, SomeIvarJob, foo: 'baz')
563
+
564
+ assert_equal(
565
+ 2, Resque.enqueue_delayed_selection { |a| a.first['foo'] == 'bar' }
566
+ )
567
+ assert_equal(2, Resque.count_all_scheduled_jobs)
568
+ end
569
+
570
+ test 'enqueue_delayed_selection ignores jobs with no arguments' do
571
+ t = Time.now + 120
572
+ Resque.enqueue_at(t, SomeIvarJob)
573
+ Resque.enqueue_at(t + 1, SomeIvarJob)
574
+ Resque.enqueue_at(t + 2, SomeIvarJob)
575
+ Resque.enqueue_at(t + 3, SomeIvarJob)
576
+
577
+ assert_equal(0, Resque.enqueue_delayed_selection { |a| a.first == 'bar' })
578
+ assert_equal(4, Resque.count_all_scheduled_jobs)
579
+ end
580
+
581
+ test "enqueue_delayed_selection doesn't enqueue items it shouldn't" do
582
+ t = Time.now + 120
583
+ Resque.enqueue_at(t, SomeIvarJob, 'foo')
584
+ Resque.enqueue_at(t + 1, SomeIvarJob, 'bar')
585
+ Resque.enqueue_at(t + 2, SomeIvarJob, 'bar')
586
+ Resque.enqueue_at(t + 3, SomeIvarJob, 'baz')
587
+
588
+ assert_equal(0, Resque.enqueue_delayed_selection { |a| a.first == 'qux' })
589
+ assert_equal(4, Resque.count_all_scheduled_jobs)
590
+ end
591
+
592
+ test 'enqueue_delayed_selection ignores last_enqueued_at redis key' do
593
+ t = Time.now + 120
594
+ Resque.enqueue_at(t, SomeIvarJob)
595
+ Resque.last_enqueued_at(SomeIvarJob, t)
596
+
597
+ assert_equal(0, Resque.enqueue_delayed_selection { |a| a.first == 'bar' })
598
+ assert_equal(t.to_s, Resque.get_last_enqueued_at(SomeIvarJob))
599
+ end
600
+
601
+ test 'enqueue_delayed_selection enqueues item by class' do
602
+ t = Time.now + 120
603
+ Resque.enqueue_at(t, SomeIvarJob, 'foo')
604
+ Resque.enqueue_at(t, SomeQuickJob, 'foo')
605
+
606
+ assert_equal(1, Resque.enqueue_delayed_selection(SomeIvarJob) do |a|
607
+ a.first == 'foo'
608
+ end)
609
+ assert_equal(1, Resque.count_all_scheduled_jobs)
610
+ end
611
+
612
+ test 'enqueue_delayed_selection enqueues item by class name as a string' do
613
+ t = Time.now + 120
614
+ Resque.enqueue_at(t, SomeIvarJob, 'foo')
615
+ Resque.enqueue_at(t, SomeQuickJob, 'foo')
616
+
617
+ assert_equal(1, Resque.enqueue_delayed_selection('SomeIvarJob') do |a|
618
+ a.first == 'foo'
619
+ end)
620
+ assert_equal(1, Resque.count_all_scheduled_jobs)
621
+ end
622
+
623
+ test 'enqueue_delayed_selection enqueues item by class name as a symbol' do
624
+ t = Time.now + 120
625
+ Resque.enqueue_at(t, SomeIvarJob, 'foo')
626
+ Resque.enqueue_at(t, SomeQuickJob, 'foo')
627
+
628
+ assert_equal(1, Resque.enqueue_delayed_selection(:SomeIvarJob) do |a|
629
+ a.first == 'foo'
630
+ end)
631
+ assert_equal(1, Resque.count_all_scheduled_jobs)
632
+ end
633
+
634
+ test 'enqueue_delayed_selection enqueues items only from' \
635
+ 'matching job class' do
636
+ t = Time.now + 120
637
+ Resque.enqueue_at(t, SomeIvarJob, 'foo')
638
+ Resque.enqueue_at(t, SomeQuickJob, 'foo')
639
+ Resque.enqueue_at(t + 1, SomeIvarJob, 'bar')
640
+ Resque.enqueue_at(t + 1, SomeQuickJob, 'bar')
641
+ Resque.enqueue_at(t + 1, SomeIvarJob, 'foo')
642
+ Resque.enqueue_at(t + 2, SomeQuickJob, 'foo')
643
+
644
+ assert_equal(2, Resque.enqueue_delayed_selection(SomeIvarJob) do |a|
645
+ a.first == 'foo'
646
+ end)
647
+ assert_equal(4, Resque.count_all_scheduled_jobs)
648
+ end
649
+
650
+ test 'enqueue_delayed_selection enqueues items from matching job class ' \
651
+ 'without params' do
652
+ t = Time.now + 120
653
+ Resque.enqueue_at(t, SomeIvarJob)
654
+ Resque.enqueue_at(t + 1, SomeQuickJob)
655
+ Resque.enqueue_at(t + 2, SomeIvarJob)
656
+ Resque.enqueue_at(t + 3, SomeQuickJob)
657
+
658
+ assert_equal(2, Resque.enqueue_delayed_selection(SomeQuickJob) { true })
659
+ assert_equal(2, Resque.count_all_scheduled_jobs)
660
+ end
661
+
662
+ test 'find_delayed_selection finds multiple items matching ' \
663
+ 'arguments at same timestamp' do
664
+ t = Time.now + 120
665
+ Resque.enqueue_at(t, SomeIvarJob, 'bar', 'llama')
666
+ Resque.enqueue_at(t, SomeIvarJob, 'foo')
667
+ Resque.enqueue_at(t, SomeIvarJob, 'bar', 'monkey')
668
+ Resque.enqueue_at(t, SomeIvarJob, 'bar', 'platypus')
669
+ Resque.enqueue_at(t, SomeIvarJob, 'baz')
670
+ Resque.enqueue_at(t, SomeIvarJob, 'bar', 'llama')
671
+ Resque.enqueue_at(t, SomeIvarJob, 'bar', 'llama')
672
+
673
+ assert_equal(5, (Resque.find_delayed_selection do |a|
674
+ a.first == 'bar'
675
+ end).length)
676
+ end
677
+
678
+ test 'find_delayed_selection finds single item matching arguments' do
679
+ t = Time.now + 120
680
+ Resque.enqueue_at(t, SomeIvarJob, 'foo')
681
+ Resque.enqueue_at(t + 1, SomeIvarJob, 'bar')
682
+ Resque.enqueue_at(t + 2, SomeIvarJob, 'bar')
683
+ Resque.enqueue_at(t + 3, SomeIvarJob, 'baz')
684
+
685
+ assert_equal(1, (Resque.find_delayed_selection do |a|
686
+ a.first == 'foo'
687
+ end).length)
688
+ end
689
+
690
+ test 'find_delayed_selection finds multiple items matching arguments' do
691
+ t = Time.now + 120
692
+ Resque.enqueue_at(t, SomeIvarJob, 'foo')
693
+ Resque.enqueue_at(t + 1, SomeIvarJob, 'bar')
694
+ Resque.enqueue_at(t + 2, SomeIvarJob, 'bar')
695
+ Resque.enqueue_at(t + 3, SomeIvarJob, 'baz')
696
+
697
+ assert_equal(2, (Resque.find_delayed_selection do |a|
698
+ a.first == 'bar'
699
+ end).length)
700
+ end
701
+
702
+ test 'find_delayed_selection finds multiple items matching ' \
703
+ 'arguments as hash' do
704
+ t = Time.now + 120
705
+ Resque.enqueue_at(t, SomeIvarJob, foo: 'foo')
706
+ Resque.enqueue_at(t + 1, SomeIvarJob, foo: 'bar')
707
+ Resque.enqueue_at(t + 2, SomeIvarJob, foo: 'bar')
708
+ Resque.enqueue_at(t + 3, SomeIvarJob, foo: 'baz')
709
+
710
+ len = Resque.find_delayed_selection { |a| a.first['foo'] == 'bar' }.length
711
+ assert_equal(2, len)
712
+ end
713
+
714
+ test 'find_delayed_selection ignores jobs with no arguments' do
715
+ t = Time.now + 120
716
+ Resque.enqueue_at(t, SomeIvarJob)
717
+ Resque.enqueue_at(t + 1, SomeIvarJob)
718
+ Resque.enqueue_at(t + 2, SomeIvarJob)
719
+ Resque.enqueue_at(t + 3, SomeIvarJob)
720
+
721
+ assert_equal(0, (Resque.find_delayed_selection do |a|
722
+ a.first == 'bar'
723
+ end).length)
724
+ end
725
+
726
+ test "find_delayed_selection doesn't find items it shouldn't" do
727
+ t = Time.now + 120
728
+ Resque.enqueue_at(t, SomeIvarJob, 'foo')
729
+ Resque.enqueue_at(t + 1, SomeIvarJob, 'bar')
730
+ Resque.enqueue_at(t + 2, SomeIvarJob, 'bar')
731
+ Resque.enqueue_at(t + 3, SomeIvarJob, 'baz')
732
+
733
+ assert_equal(0, (Resque.find_delayed_selection do |a|
734
+ a.first == 'qux'
735
+ end).length)
736
+ end
737
+
738
+ test 'find_delayed_selection finds item by class' do
739
+ t = Time.now + 120
740
+ Resque.enqueue_at(t, SomeIvarJob, 'foo')
741
+ Resque.enqueue_at(t, SomeQuickJob, 'foo')
742
+
743
+ assert_equal(1, (Resque.find_delayed_selection(SomeIvarJob) do |a|
744
+ a.first == 'foo'
745
+ end).length)
746
+ end
747
+
748
+ test 'find_delayed_selection finds item by class name as a string' do
749
+ t = Time.now + 120
750
+ Resque.enqueue_at(t, SomeIvarJob, 'foo')
751
+ Resque.enqueue_at(t, SomeQuickJob, 'foo')
752
+
753
+ assert_equal(1, (Resque.find_delayed_selection('SomeIvarJob') do |a|
754
+ a.first == 'foo'
755
+ end).length)
756
+ end
757
+
758
+ test 'find_delayed_selection finds item by class name as a symbol' do
759
+ t = Time.now + 120
760
+ Resque.enqueue_at(t, SomeIvarJob, 'foo')
761
+ Resque.enqueue_at(t, SomeQuickJob, 'foo')
762
+
763
+ assert_equal(1, (Resque.find_delayed_selection(:SomeIvarJob) do |a|
764
+ a.first == 'foo'
765
+ end).length)
766
+ end
767
+
768
+ test 'find_delayed_selection finds items only from' \
769
+ 'matching job class' do
770
+ t = Time.now + 120
771
+ Resque.enqueue_at(t, SomeIvarJob, 'foo')
772
+ Resque.enqueue_at(t, SomeQuickJob, 'foo')
773
+ Resque.enqueue_at(t + 1, SomeIvarJob, 'bar')
774
+ Resque.enqueue_at(t + 1, SomeQuickJob, 'bar')
775
+ Resque.enqueue_at(t + 1, SomeIvarJob, 'foo')
776
+ Resque.enqueue_at(t + 2, SomeQuickJob, 'foo')
777
+
778
+ assert_equal(2, (Resque.find_delayed_selection(SomeIvarJob) do |a|
779
+ a.first == 'foo'
780
+ end).length)
781
+ end
782
+
783
+ test 'find_delayed_selection finds items from matching job class ' \
784
+ 'without params' do
785
+ t = Time.now + 120
786
+ Resque.enqueue_at(t, SomeIvarJob)
787
+ Resque.enqueue_at(t + 1, SomeQuickJob)
788
+ Resque.enqueue_at(t + 2, SomeIvarJob)
789
+ Resque.enqueue_at(t + 3, SomeQuickJob)
790
+
791
+ assert_equal(
792
+ 2, (Resque.find_delayed_selection(SomeQuickJob) { true }).length
793
+ )
794
+ end
795
+
519
796
  test 'remove_delayed_job_from_timestamp removes instances of jobs ' \
520
797
  'at a given timestamp' do
521
798
  t = Time.now + 120
@@ -87,9 +87,15 @@ context 'Resque::Scheduler' do
87
87
  assert Resque::Scheduler.scheduled_jobs.include?('some_ivar_job')
88
88
 
89
89
  Resque.redis.del(:schedules)
90
- Resque.redis.hset(:schedules, 'some_ivar_job2', Resque.encode(
91
- 'cron' => '* * * * *', 'class' => 'SomeIvarJob', 'args' => '/tmp/2'
92
- ))
90
+ Resque.redis.hset(
91
+ :schedules,
92
+ 'some_ivar_job2',
93
+ Resque.encode(
94
+ 'cron' => '* * * * *',
95
+ 'class' => 'SomeIvarJob',
96
+ 'args' => '/tmp/2'
97
+ )
98
+ )
93
99
 
94
100
  Resque::Scheduler.reload_schedule!
95
101
 
@@ -366,9 +372,15 @@ context 'Resque::Scheduler' do
366
372
  end
367
373
 
368
374
  test 'fetch_schedule returns a schedule' do
369
- Resque.redis.hset(:schedules, 'some_ivar_job2', Resque.encode(
370
- 'cron' => '* * * * *', 'class' => 'SomeIvarJob', 'args' => '/tmp/33'
371
- ))
375
+ Resque.redis.hset(
376
+ :schedules,
377
+ 'some_ivar_job2',
378
+ Resque.encode(
379
+ 'cron' => '* * * * *',
380
+ 'class' => 'SomeIvarJob',
381
+ 'args' => '/tmp/33'
382
+ )
383
+ )
372
384
  assert_equal(
373
385
  { 'cron' => '* * * * *', 'class' => 'SomeIvarJob', 'args' => '/tmp/33' },
374
386
  Resque.fetch_schedule('some_ivar_job2')
data/test/test_helper.rb CHANGED
@@ -2,6 +2,7 @@
2
2
  require 'simplecov'
3
3
 
4
4
  require 'test/unit'
5
+ require 'minitest'
5
6
  require 'mocha/setup'
6
7
  require 'rack/test'
7
8
  require 'resque'
@@ -10,15 +11,6 @@ $LOAD_PATH.unshift File.dirname(File.expand_path(__FILE__)) + '/../lib'
10
11
  require 'resque-scheduler'
11
12
  require 'resque/scheduler/server'
12
13
 
13
- unless ENV['RESQUE_SCHEDULER_DISABLE_TEST_REDIS_SERVER']
14
- # Start our own Redis when the tests start. RedisInstance will take care of
15
- # starting and stopping.
16
- require File.expand_path('../support/redis_instance', __FILE__)
17
- RedisInstance.run!
18
- end
19
-
20
- at_exit { exit MiniTest::Unit.new.run(ARGV) || 0 }
21
-
22
14
  ##
23
15
  # test/spec/mini 3
24
16
  # original work: http://gist.github.com/25455
@@ -31,11 +23,14 @@ def context(*args, &block)
31
23
  def self.test(name, &block)
32
24
  define_method("test_#{name.gsub(/\W/, '_')}", &block) if block
33
25
  end
26
+
34
27
  def self.xtest(*_args)
35
28
  end
29
+
36
30
  def self.setup(&block)
37
31
  define_method(:setup, &block)
38
32
  end
33
+
39
34
  def self.teardown(&block)
40
35
  define_method(:teardown, &block)
41
36
  end
@@ -55,16 +50,16 @@ unless defined?(Rails)
55
50
  end
56
51
 
57
52
  class FakeCustomJobClass
58
- def self.scheduled(_queue, _klass, *_args); end
53
+ def self.scheduled(_, _, *_); end
59
54
  end
60
55
 
61
56
  class FakeCustomJobClassEnqueueAt
62
57
  @queue = :test
63
- def self.scheduled(_queue, _klass, *_args); end
58
+ def self.scheduled(_, _, *_); end
64
59
  end
65
60
 
66
61
  class SomeJob
67
- def self.perform(_repo_id, _path)
62
+ def self.perform(_, _)
68
63
  end
69
64
  end
70
65