duties 0.0.1 → 0.0.2
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 +4 -4
- data/README.md +1 -1
- data/app/models/duties/activity_record.rb +1 -0
- data/db/migrate/2_add_errors_to_activities.rb +5 -0
- data/duties.gemspec +1 -1
- data/lib/duties/activity.rb +5 -8
- data/lib/duties/status.rb +36 -0
- data/lib/duties.rb +1 -0
- data/spec/acceptance/running_duties_spec.rb +21 -0
- data/spec/internal/db/combustion_test.sqlite +0 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58c199bfac0f918469da8f3cd3ac3efdde00e725
|
4
|
+
data.tar.gz: 8f2c956d07738c6f47d6a45c37e74d1720d50fc0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23d892e0109a2c5cdc1d0adcefcffa1c569d50e157fb34a22c4f2e06f3e56437f7934d642c27102b5c9bab4f44679b0651726fe9fffc8720d3b668cc54a88b04
|
7
|
+
data.tar.gz: 4abb6fa7809ef118ad6cc6561984fb309d3574a13b0b5ac13fa79908d1277634db42616f794612eb906a24b0889a4eb3c86373e7b5498d19ae0799369b1a6437
|
data/README.md
CHANGED
data/duties.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
Gem::Specification.new do |spec|
|
3
3
|
spec.name = 'duties'
|
4
|
-
spec.version = '0.0.
|
4
|
+
spec.version = '0.0.2'
|
5
5
|
spec.authors = ['Pat Allan']
|
6
6
|
spec.email = ['pat@freelancing-gods.com']
|
7
7
|
spec.summary = %q{Run activities related to a duty in a specific order}
|
data/lib/duties/activity.rb
CHANGED
@@ -1,14 +1,11 @@
|
|
1
1
|
class Duties::Activity
|
2
2
|
def self.call(record)
|
3
|
-
|
4
|
-
begin
|
5
|
-
activity.call
|
6
|
-
record.update_attributes status: 'success'
|
3
|
+
new(record).call
|
7
4
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
record.status = record.failures.any? ? 'failure' : 'success'
|
6
|
+
record.save!
|
7
|
+
|
8
|
+
Duties::Next.call record.duty_record, record.position
|
12
9
|
end
|
13
10
|
|
14
11
|
def initialize(activity)
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class Duties::Status
|
2
|
+
def initialize(id)
|
3
|
+
@record = Duties::DutyRecord.find id
|
4
|
+
end
|
5
|
+
|
6
|
+
def status
|
7
|
+
return 'failure' if statuses.include?('failure')
|
8
|
+
return 'pending' if statuses.include?('pending')
|
9
|
+
|
10
|
+
'success'
|
11
|
+
end
|
12
|
+
|
13
|
+
def failure?
|
14
|
+
status == 'failure'
|
15
|
+
end
|
16
|
+
|
17
|
+
def failures
|
18
|
+
record.activity_records.pluck(:failures).flatten
|
19
|
+
end
|
20
|
+
|
21
|
+
def pending?
|
22
|
+
status == 'pending'
|
23
|
+
end
|
24
|
+
|
25
|
+
def success?
|
26
|
+
status == 'success'
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
attr_reader :record
|
32
|
+
|
33
|
+
def statuses
|
34
|
+
@statuses ||= record.activity_records.pluck :status
|
35
|
+
end
|
36
|
+
end
|
data/lib/duties.rb
CHANGED
@@ -8,6 +8,13 @@ module Running
|
|
8
8
|
enqueue_activity 'success_two', at: 2
|
9
9
|
end
|
10
10
|
end
|
11
|
+
|
12
|
+
class ExampleTwo < ::Duties::Duty
|
13
|
+
def enqueue_activities
|
14
|
+
enqueue_activity 'fail_one', at: 1
|
15
|
+
enqueue_activity 'success_one', at: 2
|
16
|
+
end
|
17
|
+
end
|
11
18
|
end
|
12
19
|
|
13
20
|
module Activities
|
@@ -22,6 +29,12 @@ module Running
|
|
22
29
|
#
|
23
30
|
end
|
24
31
|
end
|
32
|
+
|
33
|
+
class FailOne < ::Duties::Activity
|
34
|
+
def call
|
35
|
+
activity.failures << 'nope'
|
36
|
+
end
|
37
|
+
end
|
25
38
|
end
|
26
39
|
end
|
27
40
|
|
@@ -38,4 +51,12 @@ describe 'Running duties' do
|
|
38
51
|
expect(duty.activity_records.length).to eq(2)
|
39
52
|
expect(duty.activity_records.pluck(:status)).to eq(['success', 'success'])
|
40
53
|
end
|
54
|
+
|
55
|
+
it 'stores errors' do
|
56
|
+
id = Duties::Duty.enqueue 'example_two'
|
57
|
+
status = Duties::Status.new id
|
58
|
+
|
59
|
+
expect(status).to be_failure
|
60
|
+
expect(status.failures).to eq(['nope'])
|
61
|
+
end
|
41
62
|
end
|
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: duties
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pat Allan
|
@@ -111,6 +111,7 @@ files:
|
|
111
111
|
- app/models/duties/duty_record.rb
|
112
112
|
- config.ru
|
113
113
|
- db/migrate/1_create_duties_and_activities.rb
|
114
|
+
- db/migrate/2_add_errors_to_activities.rb
|
114
115
|
- duties.gemspec
|
115
116
|
- lib/duties.rb
|
116
117
|
- lib/duties/activity.rb
|
@@ -119,6 +120,7 @@ files:
|
|
119
120
|
- lib/duties/duty_job.rb
|
120
121
|
- lib/duties/engine.rb
|
121
122
|
- lib/duties/next.rb
|
123
|
+
- lib/duties/status.rb
|
122
124
|
- spec/acceptance/running_duties_spec.rb
|
123
125
|
- spec/internal/config/database.yml
|
124
126
|
- spec/internal/config/routes.rb
|