yawl 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,6 +4,7 @@ module Yawl
4
4
  # Your code goes here...
5
5
  end
6
6
 
7
+ require "yawl/utils"
7
8
  require "yawl/config"
8
9
  require "yawl/log"
9
10
 
@@ -57,7 +57,7 @@ module Yawl
57
57
  def object
58
58
  return unless values[:object_id] && object_type
59
59
 
60
- klass = Object.const_get(object_type)
60
+ klass = Utils.constantize(object_type)
61
61
  klass[ values[:object_id] ]
62
62
  end
63
63
 
@@ -20,6 +20,8 @@ module Yawl
20
20
  String :request_id, :text=>true
21
21
  String :object_type
22
22
  Integer :object_id
23
+
24
+ index [:name], :unique => true
23
25
  end
24
26
 
25
27
  create_table(:steps) do
@@ -79,25 +79,33 @@ module Yawl
79
79
  attempt.update(:output => real_step.output, :completed_at => Time.now)
80
80
  update(:state => "completed")
81
81
  process.step_finished
82
- rescue Step::Fatal, Step::Tired, StandardError, SignalException => e
83
- log(:fn => "execute", :at => "caught_exception", :class => e.class, :message => e.message)
84
- attempt.update(:output => "#{real_step.output}\n\n---\nCAUGHT ERROR: #{e}\n#{e.backtrace.join("\n")}\n", :completed_at => Time.now)
85
82
 
86
- if out_of_attempts? || e.is_a?(Step::Fatal)
87
- update(:state => "failed")
88
- process.step_failed
89
- raise
90
- elsif SignalException === e && e.signm == "SIGTERM" # we are shutting down
91
- update(:state => "interrupted")
92
- raise
93
- else
94
- update(:state => "pending")
95
- start_after_delay
96
- end
83
+ rescue Step::Tired => e
84
+ log(:fn => "execute", :at => "sleep")
85
+ attempt.update(:output => "#{real_step.output}\n\n---\n#{e}\n", :completed_at => Time.now)
86
+ handle_error(e)
87
+ rescue Step::Fatal, StandardError, SignalException => e
88
+ attempt.update(:output => "#{real_step.output}\n\n---\nCAUGHT ERROR: #{e}\n#{e.backtrace.join("\n")}\n", :completed_at => Time.now)
89
+ log(:fn => "execute", :at => "caught_exception", :class => e.class, :message => e.message)
90
+ handle_error(e)
97
91
  end
98
92
  end
99
93
  end
100
94
 
95
+ def handle_error(e)
96
+ if out_of_attempts? || e.is_a?(Step::Fatal)
97
+ update(:state => "failed")
98
+ process.step_failed
99
+ raise
100
+ elsif SignalException === e && e.signm == "SIGTERM" # we are shutting down
101
+ update(:state => "interrupted")
102
+ raise
103
+ else
104
+ update(:state => "pending")
105
+ start_after_delay
106
+ end
107
+ end
108
+
101
109
  def to_public_h
102
110
  {
103
111
  "seq" => seq,
@@ -1,5 +1,4 @@
1
1
  require "stringio"
2
- require "forwardable"
3
2
 
4
3
  module Yawl
5
4
  module Steps
@@ -59,8 +58,6 @@ module Yawl
59
58
  end
60
59
 
61
60
  class Base
62
- extend Forwardable
63
-
64
61
  def self.all_steps
65
62
  @all_steps ||= {}
66
63
  end
@@ -0,0 +1,17 @@
1
+ module Yawl
2
+ module Utils
3
+ extend self
4
+
5
+ # from activesupport
6
+ def constantize(camel_cased_word)
7
+ names = camel_cased_word.split('::')
8
+ names.shift if names.empty? || names.first.empty?
9
+
10
+ constant = Object
11
+ names.each do |name|
12
+ constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
13
+ end
14
+ constant
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module Yawl
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -325,7 +325,7 @@ describe Yawl::Step do
325
325
  it "captures output" do
326
326
  step.execute
327
327
 
328
- step.attempts.first.output.should =~ /\AI started\n\n\n---\nCAUGHT ERROR: Step slept\n.*:in `.*'/ # backtrace
328
+ step.attempts.first.output.should =~ /\AI started\n\n\n---\nStep slept\n\Z/
329
329
  end
330
330
  end
331
331
 
@@ -361,7 +361,7 @@ describe Yawl::Step do
361
361
  it "captures output" do
362
362
  expect { step.execute }.to raise_error
363
363
 
364
- step.attempts.first.output.should =~ /\AI started\n\n\n---\nCAUGHT ERROR: Step slept\n.*:in `.*'/ # backtrace
364
+ step.attempts.first.output.should =~ /\AI started\n\n\n---\nStep slept\n\Z/
365
365
  end
366
366
  end
367
367
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yawl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-25 00:00:00.000000000 Z
12
+ date: 2014-04-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sequel
@@ -149,10 +149,9 @@ files:
149
149
  - lib/yawl/step.rb
150
150
  - lib/yawl/step_attempt.rb
151
151
  - lib/yawl/steps/base.rb
152
+ - lib/yawl/utils.rb
152
153
  - lib/yawl/version.rb
153
154
  - lib/yawl/worker.rb
154
- - migrations/01_setup_tables.rb
155
- - migrations/02_setup_queue_classic.rb
156
155
  - spec/lib/process_spec.rb
157
156
  - spec/lib/step_spec.rb
158
157
  - spec/spec_helper.rb
@@ -172,7 +171,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
172
171
  version: '0'
173
172
  segments:
174
173
  - 0
175
- hash: 4036851427644308036
174
+ hash: -3845304480906963772
176
175
  required_rubygems_version: !ruby/object:Gem::Requirement
177
176
  none: false
178
177
  requirements:
@@ -181,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
180
  version: '0'
182
181
  segments:
183
182
  - 0
184
- hash: 4036851427644308036
183
+ hash: -3845304480906963772
185
184
  requirements: []
186
185
  rubyforge_project:
187
186
  rubygems_version: 1.8.23
@@ -1,34 +0,0 @@
1
- Sequel.migration do
2
- change do
3
- create_table(:processes) do
4
- primary_key :id
5
- String :desired_state, :text=>true, :null=>false
6
- String :state, :default=>"pending", :text=>true, :null=>false
7
- DateTime :created_at
8
- String :name, :text=>true
9
- String :config
10
- String :request_id, :text=>true
11
- String :specified_attributes
12
- end
13
-
14
- create_table(:steps) do
15
- primary_key :id
16
- Integer :process_id, :null=>false
17
- Integer :seq, :null=>false
18
- String :name, :text=>true, :null=>false
19
- String :state, :default=>"pending", :text=>true, :null=>false
20
-
21
- index [:process_id]
22
- end
23
-
24
- create_table(:step_attempts) do
25
- primary_key :id
26
- Integer :step_id, :null=>false
27
- File :output
28
- DateTime :started_at
29
- DateTime :completed_at
30
-
31
- index [:step_id]
32
- end
33
- end
34
- end
@@ -1,14 +0,0 @@
1
- require "queue_classic"
2
- require "queue_classic/later"
3
-
4
- Sequel.migration do
5
- down do
6
- QC::Setup.drop
7
- QC::Later::Setup.drop
8
- end
9
-
10
- up do
11
- QC::Setup.create
12
- QC::Later::Setup.create
13
- end
14
- end