actionable 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/actionable/job.rb +6 -12
- data/lib/actionable/mongoid_store/action.rb +19 -3
- data/lib/actionable/target.rb +1 -1
- data/lib/actionable/version.rb +1 -1
- data/spec/sweep_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 037f786d6b7377660c22f4173edd7bf83cfe0133
|
4
|
+
data.tar.gz: 74c9df4178629aacd95d80b252014435a4224ad1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 950e7d98d5fcc7cd685385b95beb4bd520a67106e71d2a02cb0aa1753dd938c53256136d6f997687268fc2060dc5673dd14767d4d501fdae85102a8069f2ee16
|
7
|
+
data.tar.gz: be1d4c15adcc51311175ecb0538405b3549ef0506ace8489da12f9b4e12fa1a8a8d1a28c8c6bef175483d5005227ebe7bc052628855366bab52a1a3a522ef27b
|
data/lib/actionable/job.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Actionable
|
2
2
|
class Job
|
3
3
|
|
4
|
-
attr_reader :actionable
|
4
|
+
attr_reader :actionable, :target, :payload
|
5
5
|
|
6
6
|
def self.queue
|
7
7
|
@queue ||= 'actionable'
|
@@ -15,21 +15,15 @@ module Actionable
|
|
15
15
|
def self.perform(id)
|
16
16
|
actionable = Actionable::Action.find(id)
|
17
17
|
actionable.update_attributes(status: :working)
|
18
|
-
new(actionable).perform
|
18
|
+
new(actionable.target,actionable.payload,actionable).perform
|
19
19
|
actionable.update_attributes(status: :complete)
|
20
20
|
end
|
21
21
|
|
22
|
-
def initialize(actionable)
|
22
|
+
def initialize(target,payload={},actionable=nil)
|
23
|
+
@target = target
|
23
24
|
@actionable = actionable
|
25
|
+
@payload = HashWithIndifferentAccess.new(payload)
|
24
26
|
end
|
25
|
-
|
26
|
-
def target
|
27
|
-
@target ||= actionable.target
|
28
|
-
end
|
29
|
-
|
30
|
-
def payload
|
31
|
-
@payload ||= HashWithIndifferentAccess.new(actionable.payload)
|
32
|
-
end
|
33
|
-
|
27
|
+
|
34
28
|
end
|
35
29
|
end
|
@@ -7,8 +7,10 @@ module Actionable
|
|
7
7
|
include Mongoid::Document
|
8
8
|
|
9
9
|
store_in(collection: 'actionables')
|
10
|
+
|
11
|
+
after_initialize :flag_late
|
10
12
|
|
11
|
-
field :execution_time, type:
|
13
|
+
field :execution_time, type: Time
|
12
14
|
field :payload, type: Hash
|
13
15
|
field :job_class_name, type: String
|
14
16
|
field :status, type: Symbol, default: :new
|
@@ -22,13 +24,27 @@ module Actionable
|
|
22
24
|
|
23
25
|
scope :with_job_class, ->(klass) { where(job_class_name: klass.to_s.classify)}
|
24
26
|
|
25
|
-
[:scheduled,:
|
27
|
+
scope :scheduled_or_late, where(:status.in => [:scheduled,:late])
|
28
|
+
|
29
|
+
[:scheduled,:enqueued,:working,:complete,:canceled,:failed,:overdue].each do |status|
|
26
30
|
scope status, where(status: status)
|
27
31
|
define_method(:"#{status}?") { self.status == status }
|
28
32
|
end
|
29
33
|
|
30
34
|
def self.to_do
|
31
|
-
|
35
|
+
scheduled_or_late.scheduled_for_before(to_do_time)
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.to_do_time
|
39
|
+
DateTime.now.utc
|
40
|
+
end
|
41
|
+
|
42
|
+
def late?
|
43
|
+
execution_time.present? && execution_time < 1.minute.from_now && scheduled?
|
44
|
+
end
|
45
|
+
|
46
|
+
def flag_late
|
47
|
+
update_attribute(:status,:late) if late?
|
32
48
|
end
|
33
49
|
|
34
50
|
end
|
data/lib/actionable/target.rb
CHANGED
data/lib/actionable/version.rb
CHANGED
data/spec/sweep_spec.rb
CHANGED
@@ -30,7 +30,7 @@ describe Actionable::Sweep do
|
|
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(:
|
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
|
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.0.4
|
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-04-
|
11
|
+
date: 2013-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|