duties 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 58c199bfac0f918469da8f3cd3ac3efdde00e725
4
- data.tar.gz: 8f2c956d07738c6f47d6a45c37e74d1720d50fc0
3
+ metadata.gz: c16135defc8a376ddd750c3c472871114dd33026
4
+ data.tar.gz: dc244747cf9e295f6ea85013765be92ee88b9b44
5
5
  SHA512:
6
- metadata.gz: 23d892e0109a2c5cdc1d0adcefcffa1c569d50e157fb34a22c4f2e06f3e56437f7934d642c27102b5c9bab4f44679b0651726fe9fffc8720d3b668cc54a88b04
7
- data.tar.gz: 4abb6fa7809ef118ad6cc6561984fb309d3574a13b0b5ac13fa79908d1277634db42616f794612eb906a24b0889a4eb3c86373e7b5498d19ae0799369b1a6437
6
+ metadata.gz: 8753e2f67c5dca66359e92ace124b3ee94f89efeed00f64b068ea13a4cc6cc27c7ab8b76cdef87c5280a1458d8a40a0bebb01914329686de3ee3a56f001e2de0
7
+ data.tar.gz: 32a7e38308648b74798e5d6a81338157602810da3069a8c465fa452bcc3d0fa732d9d12018bf53c6947f4d06dba66f93dbc16181fdf67fde51da432af35a2947
data/README.md CHANGED
@@ -9,7 +9,7 @@ Duties are composed of one or more activities. These activities have positions,
9
9
  Add this line to your application's Gemfile:
10
10
 
11
11
  ```ruby
12
- gem 'duties', '0.0.2'
12
+ gem 'duties', '0.0.3'
13
13
  ```
14
14
 
15
15
  ## Usage
@@ -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.2'
4
+ spec.version = '0.0.3'
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}
@@ -11,3 +11,4 @@ require 'duties/duty_job'
11
11
  require 'duties/engine'
12
12
  require 'duties/next'
13
13
  require 'duties/status'
14
+ require 'duties/subscriber'
@@ -1,13 +1,23 @@
1
1
  class Duties::Activity
2
2
  def self.call(record)
3
- new(record).call
3
+ instrument 'activity', activity: record do
4
+ instrument 'starting_activity', activity: record
5
+
6
+ new(record).call
7
+ end
4
8
 
5
9
  record.status = record.failures.any? ? 'failure' : 'success'
6
10
  record.save!
7
11
 
12
+ instrument 'finished_activity', activity: record
13
+
8
14
  Duties::Next.call record.duty_record, record.position
9
15
  end
10
16
 
17
+ def self.instrument(event, options, &block)
18
+ ActiveSupport::Notifications.instrument "#{event}.duties", options, &block
19
+ end
20
+
11
21
  def initialize(activity)
12
22
  @activity = activity
13
23
  end
@@ -16,6 +26,6 @@ class Duties::Activity
16
26
 
17
27
  attr_reader :activity
18
28
 
19
- delegate :duty, to: :activity
20
- delegate :data, to: :duty
29
+ delegate :duty_record, to: :activity
30
+ delegate :data, to: :duty_record
21
31
  end
@@ -6,6 +6,7 @@ class Duties::Status
6
6
  def status
7
7
  return 'failure' if statuses.include?('failure')
8
8
  return 'pending' if statuses.include?('pending')
9
+ return 'pending' if record.activity_records.length.zero?
9
10
 
10
11
  'success'
11
12
  end
@@ -0,0 +1,29 @@
1
+ class Duties::Subscriber < ActiveSupport::LogSubscriber
2
+ def activity(event)
3
+ identifier = color 'Duties (%.1fms)' % event.duration, GREEN, true
4
+ debug " #{identifier} Running #{activity_message event}"
5
+ end
6
+
7
+ def starting_activity(event)
8
+ identifier = color 'Duties', GREEN, true
9
+ debug " #{identifier} Starting #{activity_message event}"
10
+ end
11
+
12
+ def finished_activity(event)
13
+ identifier = color 'Duties', GREEN, true
14
+ activity = event.payload[:activity]
15
+ debug [" #{identifier} ",
16
+ "Finished #{activity_message event} (#{activity.status})"].join('')
17
+ end
18
+
19
+ private
20
+
21
+ def activity_message(event)
22
+ activity = event.payload[:activity]
23
+ [activity.duty_record, activity].collect { |object|
24
+ "#{object.name} (#{object.id})"
25
+ }.join(' / ')
26
+ end
27
+ end
28
+
29
+ Duties::Subscriber.attach_to :duties
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duties
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Allan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-26 00:00:00.000000000 Z
11
+ date: 2014-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -121,6 +121,7 @@ files:
121
121
  - lib/duties/engine.rb
122
122
  - lib/duties/next.rb
123
123
  - lib/duties/status.rb
124
+ - lib/duties/subscriber.rb
124
125
  - spec/acceptance/running_duties_spec.rb
125
126
  - spec/internal/config/database.yml
126
127
  - spec/internal/config/routes.rb