Class: Yawl::Process
- Inherits:
-
Sequel::Model
- Object
- Sequel::Model
- Yawl::Process
show all
- Defined in:
- lib/yawl/process.rb
Defined Under Namespace
Classes: ConcurrencyError, RequestIdAttributeMismatch
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.clean_attributes(attributes) ⇒ Object
30
31
32
|
# File 'lib/yawl/process.rb', line 30
def self.clean_attributes(attributes)
attributes.reject {|k, v| !web_only_attributes.include?(k.to_s) }
end
|
.existing_by_request_id_and_attributes(request_id, attributes) ⇒ Object
22
23
24
|
# File 'lib/yawl/process.rb', line 22
def self.existing_by_request_id_and_attributes(request_id, attributes)
return nil unless request_id
end
|
.log(data, &block) ⇒ Object
14
15
16
|
# File 'lib/yawl/process.rb', line 14
def self.log(data, &block)
Log.log({ ns: "yawl-process" }.merge(data), &block)
end
|
.web_only_attributes ⇒ Object
26
27
28
|
# File 'lib/yawl/process.rb', line 26
def self.web_only_attributes
%w[config desired_state request_id]
end
|
Instance Method Details
#add_step(data = {}) ⇒ Object
98
99
100
101
|
# File 'lib/yawl/process.rb', line 98
def add_step(data = {})
data[:seq] ||= next_step_seq
super(data)
end
|
#before_validation ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/yawl/process.rb', line 34
def before_validation
super
if new?
self.name = SecureRandom.uuid
self.created_at = Time.now
end
end
|
#callback_payload ⇒ Object
110
111
112
113
114
|
# File 'lib/yawl/process.rb', line 110
def callback_payload
{
"process" => to_public_h.merge("url" => Urls.process(self))
}
end
|
#current? ⇒ Boolean
64
65
66
|
# File 'lib/yawl/process.rb', line 64
def current?
self.id == self.class.filter(:object_type => object_type, :object_id => values[:object_id]).order(:id).reverse.get(:id)
end
|
#default_config ⇒ Object
120
121
122
123
124
125
126
|
# File 'lib/yawl/process.rb', line 120
def default_config
{
"ion_branch" => "master",
"manifesto_source_manifest" => "production",
"manifesto_releases" => {}
}
end
|
#end_state_reached ⇒ Object
107
108
|
# File 'lib/yawl/process.rb', line 107
def end_state_reached
end
|
#log(data, &block) ⇒ Object
18
19
20
|
# File 'lib/yawl/process.rb', line 18
def log(data, &block)
self.class.log({ process_id: id, desired_state: desired_state }.merge(data), &block)
end
|
#merged_config ⇒ Object
116
117
118
|
# File 'lib/yawl/process.rb', line 116
def merged_config
default_config.deep_merge(config || {})
end
|
#next_step_seq ⇒ Object
94
95
96
|
# File 'lib/yawl/process.rb', line 94
def next_step_seq
steps_dataset.count == 0 ? 1 : steps_dataset.last.seq + 1
end
|
#object ⇒ Object
57
58
59
60
61
62
|
# File 'lib/yawl/process.rb', line 57
def object
return unless values[:object_id] && object_type
klass = Utils.constantize(object_type)
klass[ values[:object_id] ]
end
|
#realize_process_definition ⇒ Object
128
129
130
131
132
133
|
# File 'lib/yawl/process.rb', line 128
def realize_process_definition
log(fn: "realize_process_definition") do
ProcessDefinitions.realize_on(desired_state, self)
save end
end
|
#running? ⇒ Boolean
53
54
55
|
# File 'lib/yawl/process.rb', line 53
def running?
!%w[completed failed].include?(state)
end
|
#start ⇒ Object
48
49
50
51
|
# File 'lib/yawl/process.rb', line 48
def start
realize_process_definition
start_first_unfinished_step_or_complete
end
|
#start_first_unfinished_step ⇒ Object
76
77
78
79
80
81
82
|
# File 'lib/yawl/process.rb', line 76
def start_first_unfinished_step
if unfinished_step = unfinished_steps.first
update(:state => "executing")
unfinished_step.start
unfinished_step
end
end
|
#start_first_unfinished_step_or_complete ⇒ Object
68
69
70
71
72
73
74
|
# File 'lib/yawl/process.rb', line 68
def start_first_unfinished_step_or_complete
unless start_first_unfinished_step
log(at: "completed")
update(:state => "completed")
end_state_reached
end
end
|
#step_failed ⇒ Object
88
89
90
91
92
|
# File 'lib/yawl/process.rb', line 88
def step_failed
log(at: "failed")
update(:state => "failed")
end_state_reached
end
|
#step_finished ⇒ Object
84
85
86
|
# File 'lib/yawl/process.rb', line 84
def step_finished
start_first_unfinished_step_or_complete
end
|
#to_public_h ⇒ Object
135
136
137
138
139
140
141
142
|
# File 'lib/yawl/process.rb', line 135
def to_public_h
{
"name" => name,
"desired_state" => desired_state,
"state" => state,
"config" => merged_config
}
end
|
#unfinished_steps ⇒ Object
103
104
105
|
# File 'lib/yawl/process.rb', line 103
def unfinished_steps
steps_dataset.where(Sequel.lit("state != 'completed'"))
end
|
#validate ⇒ Object
42
43
44
45
46
|
# File 'lib/yawl/process.rb', line 42
def validate
super
validates_presence :name
validates_includes ProcessDefinitions.all_names, :desired_state
end
|