brianjlandau-resque-scheduler 1.10.5 → 1.10.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -146,6 +146,20 @@ When the scheduler loops it will look for differences between the existing sched
146
146
 
147
147
  To force the scheduler to reload the schedule you just send it the `USR2` signal.
148
148
 
149
+ Convenience methods are provided to add/update, delete, and retrieve individual schedule items from the `schedules` in redis:
150
+
151
+ * `Resque.set_schedule(name, config)`
152
+ * `Resque.get_schedule(name)`
153
+ * `Resque.remove_schedule(name)`
154
+
155
+ For example:
156
+
157
+ Resque.set_schedule("create_fake_leaderboards", {
158
+ :cron => "30 6 * * 1",
159
+ :class => "CreateFakeLeaderboards",
160
+ :queue => scoring
161
+ })
162
+
149
163
  ### Support for customized Job classes
150
164
 
151
165
  Some Resque extensions like [resque-status](http://github.com/quirkey/resque-status) use custom job classes with a slightly different API signature.
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{brianjlandau-resque-scheduler}
8
- s.version = "1.10.5"
8
+ s.version = "1.10.6"
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", "Brian Landau"]
@@ -168,7 +168,7 @@ module Resque
168
168
  end
169
169
 
170
170
  def update_schedule
171
- schedule_from_redis = Resque.get_schedule
171
+ schedule_from_redis = Resque.get_schedules
172
172
  if !schedule_from_redis.nil? && !schedule_from_redis.empty? && schedule_from_redis != Resque.schedule
173
173
  # unload schedules that no longer exist
174
174
  (Resque.schedule.keys - schedule_from_redis.keys).each do |name|
@@ -36,16 +36,32 @@ module ResqueScheduler
36
36
 
37
37
  # reloads the schedule from redis
38
38
  def reload_schedule!
39
- @schedule = get_schedule
39
+ @schedule = get_schedules
40
40
  end
41
41
 
42
- def get_schedule
42
+ # gets the schedule as it exists in redis
43
+ def get_schedules
43
44
  redis.hgetall(:schedules).tap do |h|
44
45
  h.each do |name, config|
45
46
  h[name] = decode(config)
46
47
  end
47
48
  end
48
49
  end
50
+
51
+ # create or update a schedule with the provided name and configuration
52
+ def set_schedule(name, config)
53
+ redis.hset(:schedules, name, encode(config))
54
+ end
55
+
56
+ # retrive the schedule configuration for the given name
57
+ def get_schedule(name)
58
+ decode(redis.hget(:schedules, name))
59
+ end
60
+
61
+ # remove a given schedule by name
62
+ def remove_schedule(name)
63
+ redis.hdel(:schedules, name)
64
+ end
49
65
 
50
66
  # This method is nearly identical to +enqueue+ only it also
51
67
  # takes a timestamp which will be used to schedule the job
@@ -1,3 +1,3 @@
1
1
  module ResqueScheduler
2
- Version = '1.10.5'
2
+ Version = '1.10.6'
3
3
  end
@@ -187,6 +187,30 @@ class Resque::SchedulerTest < Test::Unit::TestCase
187
187
  assert !Resque::Scheduler.scheduled_jobs.keys.include?("another_ivar_job")
188
188
  assert !Resque.schedule.keys.include?("another_ivar_job")
189
189
  end
190
+
191
+ def test_set_schedule
192
+ Resque.set_schedule("some_ivar_job", {
193
+ 'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp/22"
194
+ })
195
+ assert_equal({'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp/22"},
196
+ Resque.decode(Resque.redis.hget(:schedules, "some_ivar_job")))
197
+ end
198
+
199
+ def test_get_schedule
200
+ Resque.redis.hset(:schedules, "some_ivar_job2", Resque.encode(
201
+ {'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp/33"}
202
+ ))
203
+ assert_equal({'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp/33"},
204
+ Resque.get_schedule("some_ivar_job2"))
205
+ end
206
+
207
+ def test_remove_schedule
208
+ Resque.redis.hset(:schedules, "some_ivar_job3", Resque.encode(
209
+ {'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp/44"}
210
+ ))
211
+ Resque.remove_schedule("some_ivar_job3")
212
+ assert_equal nil, Resque.redis.hget(:schedules, "some_ivar_job3")
213
+ end
190
214
 
191
215
  def test_adheres_to_lint
192
216
  assert_nothing_raised do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brianjlandau-resque-scheduler
3
3
  version: !ruby/object:Gem::Version
4
- hash: 53
4
+ hash: 51
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 10
9
- - 5
10
- version: 1.10.5
9
+ - 6
10
+ version: 1.10.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ben VandenBos