updater 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
data/bin/updater CHANGED
@@ -12,8 +12,7 @@ dbconfig = YAML.load_file('config/database.yml')
12
12
 
13
13
  DataMapper.setup(dbconfig['development'])
14
14
 
15
-
16
-
15
+ Worker.new.start
17
16
 
18
17
 
19
18
 
@@ -208,6 +208,9 @@ module Updater
208
208
  #Gets a single gob form the queue, locks and runs it.
209
209
  def work_off(worker)
210
210
  updates = worker_set
211
+ if updates.empty?
212
+ return queue_time
213
+ end
211
214
 
212
215
  #concept copied form delayed_job. If there are a number of
213
216
  #different processes working on the queue, the niave approch
@@ -24,8 +24,9 @@ module Updater
24
24
  delay = Update.work_off(self)
25
25
  break if $exit
26
26
  sleep delay
27
- break if exit
27
+ break if $exit
28
28
  end
29
+ clear_locks
29
30
  end
30
31
 
31
32
  trap('TERM') { terminate_with t }
@@ -44,6 +45,10 @@ module Updater
44
45
  logger.info text if logger
45
46
  end
46
47
 
48
+ def clear_locks
49
+ Update.all(:lock_name=>@name).update(:lock_name=>nil)
50
+ end
51
+
47
52
  private
48
53
 
49
54
  def terminate_with(t)
@@ -51,11 +56,9 @@ module Updater
51
56
  $exit = true
52
57
  t.run
53
58
  say "Forcing Shutdown" unless status = t.join(15) #Nasty inline assignment
54
- Update.clear_locks(self)
59
+ clear_locks
55
60
  exit status ? 0 : 1
56
61
  end
57
-
58
-
59
62
  end
60
63
 
61
64
  end
data/spec/lock_spec.rb CHANGED
@@ -68,6 +68,14 @@ describe "Update Locking:" do
68
68
 
69
69
  end
70
70
 
71
- it "#clear_locks should lear all locks from a worker"
71
+ it "#clear_locks should clear all locks from a worker" do
72
+ @v = Update.immidiate(Foo,:bar,[:arg1,:arg2])
73
+ @u.lock(@w)
74
+ @v.lock(@w)
75
+ @u.locked?.should be_true
76
+ @w.clear_locks
77
+ @u.reload.locked?.should be_false
78
+ @v.reload.locked?.should be_false
79
+ end
72
80
 
73
81
  end
data/spec/worker_spec.rb CHANGED
@@ -60,7 +60,11 @@ describe "working off jobs:" do
60
60
  Update.work_off(Worker.new(:name=>"first", :quiet=>true)).should == 0
61
61
  end
62
62
 
63
- it "should return the number of seconds till the next job if there are no jobs to be run"
63
+ it "should return the number of seconds till the next job if there are no jobs to be run" do
64
+ Timecop.freeze(Time.now)
65
+ u1 = Update.at(Time.now + 30, Foo,:bar,[:arg1])
66
+ Update.work_off(Worker.new(:name=>"first", :quiet=>true)).should == 30
67
+ end
64
68
 
65
69
  it "should return nil if the job queue is empty" do
66
70
  u1 = Update.immidiate(Foo,:bar,[:arg1])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: updater
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John F. Miller
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-09 00:00:00 -07:00
12
+ date: 2009-10-21 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency