resque-scheduler 1.9.6 → 1.9.7

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 1.9.7 (2010-11-09)
2
+
3
+ * Support for rufus-scheduler "every" syntax (fallwith)
4
+ * Ability to pass a Time to handle_delayed_items for testing/staging (rcarver)
5
+
1
6
  ## 1.9.6 (2010-10-08)
2
7
 
3
8
  * Support for custom job classes (like resque-status) (mattetti)
@@ -60,13 +60,20 @@ module Resque
60
60
  # to.
61
61
  if config['rails_env'].nil? || rails_env_matches?(config)
62
62
  log! "Scheduling #{name} "
63
- if !config['cron'].nil? && config['cron'].length > 0
64
- rufus_scheduler.cron config['cron'] do
65
- log! "queuing #{config['class']} (#{name})"
66
- enqueue_from_config(config)
63
+ interval_defined = false
64
+ interval_types = %w{cron every}
65
+ interval_types.each do |interval_type|
66
+ if !config[interval_type].nil? && config[interval_type].length > 0
67
+ rufus_scheduler.send(interval_type, config[interval_type]) do
68
+ log! "queueing #{config['class']} (#{name})"
69
+ enqueue_from_config(config)
70
+ end
71
+ interval_defined = true
72
+ break
67
73
  end
68
- else
69
- log! "no cron found for #{config['class']} (#{name}) - skipping"
74
+ end
75
+ unless interval_defined
76
+ log! "no #{interval_types.join(' / ')} found for #{config['class']} (#{name}) - skipping"
70
77
  end
71
78
  end
72
79
  end
@@ -79,10 +86,11 @@ module Resque
79
86
  end
80
87
 
81
88
  # Handles queueing delayed items
82
- def handle_delayed_items
83
- item = nil
89
+ # at_time - Time to start scheduling items (default: now).
90
+ def handle_delayed_items(at_time=nil)
91
+ timestamp = nil
84
92
  begin
85
- if timestamp = Resque.next_delayed_timestamp
93
+ if timestamp = Resque.next_delayed_timestamp(at_time)
86
94
  enqueue_delayed_items_for_timestamp(timestamp)
87
95
  end
88
96
  # continue processing until there are no more ready timestamps
@@ -18,6 +18,8 @@ module ResqueScheduler
18
18
  #
19
19
  # :name can be anything and is used only to describe the scheduled job
20
20
  # :cron can be any cron scheduling string :job can be any resque job class
21
+ # :every can be used in lieu of :cron. see rufus-scheduler's 'every' usage for
22
+ # valid syntax. If :cron is present it will take precedence over :every.
21
23
  # :class must be a resque worker class
22
24
  # :args can be any yaml which will be converted to a ruby literal and passed
23
25
  # in a params. (optional)
@@ -89,8 +91,8 @@ module ResqueScheduler
89
91
 
90
92
  # Returns the next delayed queue timestamp
91
93
  # (don't call directly)
92
- def next_delayed_timestamp
93
- items = redis.zrangebyscore :delayed_queue_schedule, '-inf', Time.now.to_i, :limit => [0, 1]
94
+ def next_delayed_timestamp(at_time=nil)
95
+ items = redis.zrangebyscore :delayed_queue_schedule, '-inf', (at_time || Time.now).to_i, :limit => [0, 1]
94
96
  timestamp = items.nil? ? nil : Array(items).first
95
97
  timestamp.to_i unless timestamp.nil?
96
98
  end
@@ -10,7 +10,7 @@
10
10
  <th></th>
11
11
  <th>Name</th>
12
12
  <th>Description</th>
13
- <th>Cron</th>
13
+ <th>Interval</th>
14
14
  <th>Class</th>
15
15
  <th>Queue</th>
16
16
  <th>Arguments</th>
@@ -26,7 +26,9 @@
26
26
  </td>
27
27
  <td><%= h name %></td>
28
28
  <td><%= h config['description'] %></td>
29
- <td style="white-space:nowrap"><%= h config['cron'] %></td>
29
+ <td style="white-space:nowrap"><%= (config['cron'].nil? && !config['every'].nil?) ?
30
+ h('every: ' + config['every']) :
31
+ h('cron: ' + config['cron']) %></td>
30
32
  <td><%= h config['class'] %></td>
31
33
  <td><%= h config['queue'] || queue_from_class_name(config['class']) %></td>
32
34
  <td><%= h config['args'].inspect %></td>
@@ -1,3 +1,3 @@
1
1
  module ResqueScheduler
2
- Version = '1.9.6'
2
+ Version = '1.9.7'
3
3
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{resque-scheduler}
8
- s.version = "1.9.6"
8
+ s.version = "1.9.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ben VandenBos"]
12
- s.date = %q{2010-10-08}
12
+ s.date = %q{2010-11-10}
13
13
  s.description = %q{Light weight job scheduling on top of Resque.
14
14
  Adds methods enqueue_at/enqueue_in to schedule jobs in the future.
15
15
  Also supports queueing jobs on a fixed, cron-like schedule.}
@@ -50,6 +50,16 @@ class Resque::DelayedQueueTest < Test::Unit::TestCase
50
50
  assert_nil(read_timestamp, "No timestamps should be ready for queueing")
51
51
  end
52
52
 
53
+ def test_something_in_the_future_comes_out_if_you_want_it_to
54
+ timestamp = Time.now + 600 # 10 minutes from now
55
+
56
+ Resque.enqueue_at(timestamp, SomeIvarJob, "path")
57
+
58
+ read_timestamp = Resque.next_delayed_timestamp(timestamp)
59
+
60
+ assert_equal(timestamp.to_i, read_timestamp, "The timestamp we pull out of redis should match the one we put in")
61
+ end
62
+
53
63
  def test_enqueue_at_and_enqueue_in_are_equivelent
54
64
  timestamp = Time.now + 60
55
65
 
@@ -120,6 +130,17 @@ class Resque::DelayedQueueTest < Test::Unit::TestCase
120
130
  Resque.expects(:queue_from_class).never # Should NOT need to load the class
121
131
  Resque::Scheduler.handle_delayed_items
122
132
  end
133
+
134
+ def test_handle_delayed_items_with_items_in_the_future
135
+ t = Time.now + 60 # in the future
136
+ Resque.enqueue_at(t, SomeIvarJob)
137
+ Resque.enqueue_at(t, SomeIvarJob)
138
+
139
+ # 2 SomeIvarJob jobs should be created in the "ivar" queue
140
+ Resque::Job.expects(:create).twice.with('ivar', 'SomeIvarJob', nil)
141
+ Resque.expects(:queue_from_class).never # Should NOT need to load the class
142
+ Resque::Scheduler.handle_delayed_items(t)
143
+ end
123
144
 
124
145
  def test_enqueue_delayed_items_for_timestamp
125
146
  t = Time.now + 60
@@ -14,7 +14,12 @@ class Resque::SchedulerTest < Test::Unit::TestCase
14
14
  Resque::Job.stubs(:create).once.returns(true).with('joes_queue', 'BigJoesJob', '/tmp')
15
15
  Resque::Scheduler.enqueue_from_config('cron' => "* * * * *", 'class' => 'BigJoesJob', 'args' => "/tmp", 'queue' => 'joes_queue')
16
16
  end
17
-
17
+
18
+ def test_enqueue_from_config_with_every_syntax
19
+ Resque::Job.stubs(:create).once.returns(true).with('james_queue', 'JamesJob', '/tmp')
20
+ Resque::Scheduler.enqueue_from_config('every' => '1m', 'class' => 'JamesJob', 'args' => '/tmp', 'queue' => 'james_queue')
21
+ end
22
+
18
23
  def test_enqueue_from_config_puts_stuff_in_the_resque_queue
19
24
  Resque::Job.stubs(:create).once.returns(true).with(:ivar, 'SomeIvarJob', '/tmp')
20
25
  Resque::Scheduler.enqueue_from_config('cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp")
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque-scheduler
3
3
  version: !ruby/object:Gem::Version
4
- hash: 63
4
+ hash: 61
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 9
9
- - 6
10
- version: 1.9.6
9
+ - 7
10
+ version: 1.9.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ben VandenBos
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-08 00:00:00 -07:00
18
+ date: 2010-11-10 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency