actionable 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 59ea314ec2b4a5a5e5e9264c4c3a62b7ab012b4d
4
- data.tar.gz: d05dda313d5413911dd9885811bd7863c33fd2f6
3
+ metadata.gz: 037f786d6b7377660c22f4173edd7bf83cfe0133
4
+ data.tar.gz: 74c9df4178629aacd95d80b252014435a4224ad1
5
5
  SHA512:
6
- metadata.gz: a1af58fdea6f80e3be686f0423da148114462437276ae3f6c6df6abd42b27bbc60a86da5c89451ec6f69d618c4fc689043af926967fcff96531fd447ba49e458
7
- data.tar.gz: a4e40d2e4426f2996741369d14aa5226468dafbea37f9442a6be168890e9bf645b0342c897816fa0f485807c15d57f0e0ee9a376340e3cf15f2e2cc2fa914894
6
+ metadata.gz: 950e7d98d5fcc7cd685385b95beb4bd520a67106e71d2a02cb0aa1753dd938c53256136d6f997687268fc2060dc5673dd14767d4d501fdae85102a8069f2ee16
7
+ data.tar.gz: be1d4c15adcc51311175ecb0538405b3549ef0506ace8489da12f9b4e12fa1a8a8d1a28c8c6bef175483d5005227ebe7bc052628855366bab52a1a3a522ef27b
@@ -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: DateTime
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,:enqueued,:working,:complete,:canceled,:failed].each do |status|
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
- scheduled.scheduled_for_before(Time.now.to_datetime)
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
@@ -27,7 +27,7 @@ module Actionable
27
27
  target_id:id,
28
28
  target_class_name: self.class.to_s,
29
29
  payload: payload,
30
- execution_time: execution_time,
30
+ execution_time: execution_time.to_datetime.utc,
31
31
  job_class_name: job_class_name
32
32
  )
33
33
 
@@ -1,3 +1,3 @@
1
1
  module Actionable
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -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(:scheduled)
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.3
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-09 00:00:00.000000000 Z
11
+ date: 2013-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler