actionable 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/actionable.gemspec +2 -1
- data/lib/actionable.rb +1 -0
- data/lib/actionable/resque.rb +6 -5
- data/lib/actionable/version.rb +1 -1
- data/spec/job_spec.rb +3 -3
- data/spec/recurrence_spec.rb +80 -68
- data/spec/sweep_spec.rb +3 -3
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b187586cc793a33104a2f5c1710daefae5d25023
|
4
|
+
data.tar.gz: 77797479469c0474aa59cc8c545160086ba50033
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 535ef546df907bbdc4eb4b1564bf8272185cd8724842394f216f25c98f0dd77c65111add75475a412ebc88f945453f2e4a11d39659da394d3b144472a7479ec1
|
7
|
+
data.tar.gz: dd8b4beee3770047d760f8f126907358407931d072e9eca60825b2cc43d177e5c229ca2d7ab90b50e6e5a40eca5e7ac481f1cc388f17b4e9f9aa0e9b5c15ddcb
|
data/Gemfile
CHANGED
data/actionable.gemspec
CHANGED
@@ -27,7 +27,8 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_development_dependency "rb-fsevent"
|
28
28
|
spec.add_development_dependency "terminal-notifier-guard"
|
29
29
|
|
30
|
-
spec.add_dependency "
|
30
|
+
spec.add_dependency "activesupport", "~> 4.0.0"
|
31
|
+
spec.add_dependency "resque", "~> 1.24.1"
|
31
32
|
spec.add_dependency "mongoid", "~> 4.0.0"
|
32
33
|
spec.add_dependency "rufus-scheduler"
|
33
34
|
|
data/lib/actionable.rb
CHANGED
data/lib/actionable/resque.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
require 'actionable/sweep'
|
2
2
|
|
3
3
|
module Resque
|
4
|
-
class
|
5
|
-
|
6
|
-
alias :default_poll :poll
|
4
|
+
class Worker
|
7
5
|
|
8
|
-
|
9
|
-
|
6
|
+
alias :default_reserve :reserve
|
7
|
+
|
8
|
+
def reserve
|
9
|
+
default_reserve || sweep
|
10
10
|
end
|
11
11
|
|
12
12
|
def sweep
|
13
13
|
Resque.enqueue(Actionable::Sweep)
|
14
|
+
nil
|
14
15
|
end
|
15
16
|
|
16
17
|
end
|
data/lib/actionable/version.rb
CHANGED
data/spec/job_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
class TestWorker
|
4
|
-
|
4
|
+
|
5
5
|
attr_accessor :pid
|
6
6
|
|
7
7
|
def spawn
|
@@ -40,7 +40,7 @@ describe Actionable::Job do
|
|
40
40
|
}
|
41
41
|
|
42
42
|
before do
|
43
|
-
target.schedule_actionable(1.minute.ago,TestJob,{number:2})
|
43
|
+
target.schedule_actionable(1.minute.ago,TestJob,{number:2})
|
44
44
|
end
|
45
45
|
|
46
46
|
it "should be executed by a worker manually" do
|
@@ -61,4 +61,4 @@ describe Actionable::Job do
|
|
61
61
|
|
62
62
|
end
|
63
63
|
|
64
|
-
end
|
64
|
+
end
|
data/spec/recurrence_spec.rb
CHANGED
@@ -2,98 +2,110 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Actionable::Recurrence do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
{ recurrence_string:every_five, job_class: RecurringTestJob }
|
8
|
-
}
|
9
|
-
|
10
|
-
let(:recurrence) {
|
11
|
-
Actionable::Recurrence.create(new_args)
|
12
|
-
}
|
13
|
-
|
14
|
-
it "should be instantiated with a recurrence string and a job class" do
|
15
|
-
r = Actionable::Recurrence.new(new_args)
|
16
|
-
expect(r).to be_valid
|
17
|
-
end
|
5
|
+
context "every day at 2:00 AM" do
|
6
|
+
let(:every_day_at_2){ "0 2 * * *" }
|
18
7
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
expect(r).to_not be_valid
|
8
|
+
it "should parse good" do
|
9
|
+
recurrence = Rufus::CronLine.new(every_day_at_2)
|
10
|
+
end
|
23
11
|
end
|
24
12
|
|
25
|
-
|
26
|
-
new_args[:job_class] = "NonExistentJob"
|
27
|
-
r = Actionable::Recurrence.new(new_args)
|
28
|
-
expect(r).to_not be_valid
|
29
|
-
end
|
13
|
+
context "every five minutes" do
|
30
14
|
|
15
|
+
let(:every_five){ "*/5 * * * *" }
|
16
|
+
let(:new_args){
|
17
|
+
{ recurrence_string:every_five, job_class: RecurringTestJob }
|
18
|
+
}
|
31
19
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
20
|
+
let(:recurrence) {
|
21
|
+
Actionable::Recurrence.create(new_args)
|
22
|
+
}
|
36
23
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
24
|
+
it "should be instantiated with a recurrence string and a job class" do
|
25
|
+
r = Actionable::Recurrence.new(new_args)
|
26
|
+
expect(r).to be_valid
|
27
|
+
end
|
42
28
|
|
43
|
-
|
44
|
-
|
45
|
-
|
29
|
+
it "should refuse to save with a bad recurrence string" do
|
30
|
+
new_args[:recurrence_string] = '* D * L * . *'
|
31
|
+
r = Actionable::Recurrence.new(new_args)
|
32
|
+
expect(r).to_not be_valid
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should refuse to save with a non-existent class" do
|
36
|
+
new_args[:job_class] = "NonExistentJob"
|
37
|
+
r = Actionable::Recurrence.new(new_args)
|
38
|
+
expect(r).to_not be_valid
|
39
|
+
end
|
46
40
|
|
47
|
-
it "should create an actionable upon creation" do
|
48
|
-
expect(Actionable::Action.count).to eq(0)
|
49
|
-
Actionable::Recurrence.create(new_args)
|
50
|
-
expect(Actionable::Action.count).to eq(1)
|
51
|
-
end
|
52
41
|
|
53
|
-
|
42
|
+
it "should not add to the database until saved" do
|
43
|
+
r = Actionable::Recurrence.new(new_args)
|
44
|
+
expect(Actionable::Recurrence.count).to eq(0)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should add to the database afer being committed" do
|
48
|
+
r = Actionable::Recurrence.new(new_args)
|
49
|
+
r.save
|
50
|
+
expect(Actionable::Recurrence.count).to eq(1)
|
51
|
+
end
|
54
52
|
|
55
|
-
|
56
|
-
|
57
|
-
recurrence.valid?
|
58
|
-
Timecop.travel(5.minutes.from_now)
|
53
|
+
it "should know its job class" do
|
54
|
+
expect(recurrence.send(:job_class)).to eq(RecurringTestJob)
|
59
55
|
end
|
60
|
-
|
61
|
-
it "should
|
56
|
+
|
57
|
+
it "should create an actionable upon creation" do
|
58
|
+
expect(Actionable::Action.count).to eq(0)
|
59
|
+
Actionable::Recurrence.create(new_args)
|
62
60
|
expect(Actionable::Action.count).to eq(1)
|
63
|
-
Actionable::Sweep.perform
|
64
|
-
expect(Actionable::Action.count).to eq(2)
|
65
61
|
end
|
66
62
|
|
67
|
-
|
63
|
+
context "when time passes" do
|
68
64
|
|
69
|
-
|
65
|
+
before do
|
66
|
+
Resque.inline = true
|
67
|
+
recurrence.valid?
|
68
|
+
Timecop.travel(5.minutes.from_now)
|
69
|
+
end
|
70
70
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
71
|
+
it "should run the first action and create a new one on sweep" do
|
72
|
+
expect(Actionable::Action.count).to eq(1)
|
73
|
+
2.times { Actionable::Sweep.perform }
|
74
|
+
expect(Actionable::Action.count).to eq(2)
|
75
|
+
end
|
75
76
|
|
76
|
-
it "should not run the first action or create a new one" do
|
77
|
-
expect(Actionable::Action.count).to eq(1)
|
78
|
-
Actionable::Sweep.perform
|
79
|
-
expect(Actionable::Action.count).to eq(1)
|
80
77
|
end
|
81
78
|
|
82
|
-
|
79
|
+
context "when no time passes" do
|
83
80
|
|
84
|
-
|
81
|
+
before do
|
82
|
+
Resque.inline = true
|
83
|
+
recurrence.valid?
|
84
|
+
end
|
85
85
|
|
86
|
-
|
87
|
-
|
88
|
-
Timecop.travel(1.hour.from_now.change(minutes:0))
|
89
|
-
recurrence.valid?
|
90
|
-
60.times do
|
86
|
+
it "should not run the first action or create a new one" do
|
87
|
+
expect(Actionable::Action.count).to eq(1)
|
91
88
|
Actionable::Sweep.perform
|
92
|
-
|
89
|
+
expect(Actionable::Action.count).to eq(1)
|
93
90
|
end
|
94
|
-
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
context "over the course of an hour" do
|
95
|
+
|
96
|
+
it "should create and perform the job 11 times" do
|
97
|
+
RecurringTestJob.should_receive(:go).at_least(11).times
|
98
|
+
Timecop.travel(1.hour.from_now.change(minutes:0))
|
99
|
+
recurrence.valid?
|
100
|
+
60.times do
|
101
|
+
Actionable::Sweep.perform
|
102
|
+
Timecop.travel(1.minute.from_now)
|
103
|
+
end
|
104
|
+
expect(Actionable::Action.count).to be_within(1).of(12)
|
105
|
+
end
|
106
|
+
|
95
107
|
end
|
96
108
|
|
97
109
|
end
|
98
110
|
|
99
|
-
end
|
111
|
+
end
|
data/spec/sweep_spec.rb
CHANGED
@@ -26,15 +26,15 @@ describe Actionable::Sweep do
|
|
26
26
|
|
27
27
|
it "should enqueue a job that knows the id for its target" do
|
28
28
|
Actionable::Sweep.perform
|
29
|
-
expect(Resque.
|
29
|
+
expect(Resque.pop('actionable')['args'].first).to eq(target.actionables.first.id.to_s)
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should update the actionable's status to 'enqueued'" do
|
33
|
-
expect(target.actionables.first.status).to eq(:late)
|
33
|
+
expect(target.actionables.first.status).to eq(:late)
|
34
34
|
Actionable::Sweep.perform
|
35
35
|
expect(target.actionables.first.status).to eq(:enqueued)
|
36
36
|
end
|
37
37
|
|
38
38
|
end
|
39
39
|
|
40
|
-
end
|
40
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: actionable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Luxemburg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -122,20 +122,34 @@ dependencies:
|
|
122
122
|
- - '>='
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: activesupport
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ~>
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 4.0.0
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ~>
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 4.0.0
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
140
|
name: resque
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
128
142
|
requirements:
|
129
143
|
- - ~>
|
130
144
|
- !ruby/object:Gem::Version
|
131
|
-
version:
|
145
|
+
version: 1.24.1
|
132
146
|
type: :runtime
|
133
147
|
prerelease: false
|
134
148
|
version_requirements: !ruby/object:Gem::Requirement
|
135
149
|
requirements:
|
136
150
|
- - ~>
|
137
151
|
- !ruby/object:Gem::Version
|
138
|
-
version:
|
152
|
+
version: 1.24.1
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
154
|
name: mongoid
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|