round_robin 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +19 -1
- data/lib/round_robin/job.rb +7 -1
- data/lib/round_robin/worker.rb +1 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -30,11 +30,29 @@ Now fire up two workers with:
|
|
30
30
|
|
31
31
|
COUNT=2 rake round_robin:workers
|
32
32
|
|
33
|
-
The two workers workers will take one job at a time each and process them in
|
33
|
+
The two workers workers will take one job at a time each and process them in
|
34
|
+
order.
|
34
35
|
|
35
36
|
The workers will be persisted and will be kept even after a restart of the
|
36
37
|
server. Typically in a Rails project a `RoundRobin.add` can be called in an
|
37
38
|
`after_create` callback and similarly a `RoundRobin.remove` may be called
|
38
39
|
`after_destroy`.
|
39
40
|
|
41
|
+
The RoundRobin.add call returns a RoundRobin::Job, that descends from
|
42
|
+
ActiveRecord::Base. That record has the following attributes of interest,
|
43
|
+
|
44
|
+
started_at, finished_at: datetime
|
45
|
+
|
46
|
+
When the job was started and finished most recently.
|
47
|
+
|
48
|
+
every_n_hours: integer
|
49
|
+
|
50
|
+
Whether to skip to job unless it was atleast n hours since it was run last
|
51
|
+
time. Use this to avoid running a job more often than preferred. By default
|
52
|
+
set to nil. Nil and zero means as often as possible.
|
53
|
+
|
54
|
+
skip: boolean
|
55
|
+
|
56
|
+
Whether the job should be skipped in the future. By default set to false.
|
57
|
+
|
40
58
|
Round Robin is inspired by Resque and DelayedJob.
|
data/lib/round_robin/job.rb
CHANGED
@@ -5,8 +5,10 @@ module RoundRobin
|
|
5
5
|
self.table_name = 'round_robin_jobs'
|
6
6
|
|
7
7
|
def invoke_job
|
8
|
+
update_attribute :invoked_at, Time.now
|
9
|
+
return unless runnable?
|
8
10
|
begin
|
9
|
-
update_attributes(:started_at =>
|
11
|
+
update_attributes(:started_at => Time.now, :finished_at => nil)
|
10
12
|
klass = Module.const_get(parsed_handler["class"])
|
11
13
|
args = parsed_handler["args"]
|
12
14
|
klass.perform(*args)
|
@@ -17,8 +19,12 @@ module RoundRobin
|
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
22
|
+
def runnable?
|
23
|
+
!skip && (every_n_hours.nil? || every_n_hours == 0 || invoked_at.nil? || invoked_at < every_n_hours.hours.ago)
|
24
|
+
end
|
20
25
|
|
21
26
|
private
|
27
|
+
|
22
28
|
def parsed_handler
|
23
29
|
@parsed_handler ||= JSON.parse(handler)
|
24
30
|
end
|
data/lib/round_robin/worker.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: round_robin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-05-09 00:00:00.000000000Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
17
|
-
requirement: &
|
17
|
+
requirement: &70162860081960 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,7 +22,7 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70162860081960
|
26
26
|
description: ''
|
27
27
|
email:
|
28
28
|
- jan.andersson@gmail.com
|