/
models.rb
101 lines (80 loc) · 1.77 KB
/
models.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
class StubStage < Pipeline::Stage::Base
def run
@executed = true
end
def executed?
!!@executed
end
end
class FirstStage < StubStage; end
class SecondStage < StubStage; end
class FailedStage < StubStage
def run
super
raise StandardError.new
end
end
class IrrecoverableStage < StubStage
def run
super
raise Pipeline::IrrecoverableError.new("message")
end
end
class RecoverableInputRequiredStage < StubStage
def run
super
raise Pipeline::RecoverableError.new("message", true)
end
end
class RecoverableStage < StubStage
def run
super
raise Pipeline::RecoverableError.new("message")
end
end
class GenericErrorStage < StubStage
def run
super
raise Exception.new
end
end
class SamplePipeline < Pipeline::Base
define_stages FirstStage >> SecondStage
before_pipeline :before_pipeline_callback
after_pipeline :after_pipeline_callback
private
def before_pipeline_callback; end
def after_pipeline_callback; end
end
class SampleStage < Pipeline::Stage::Base
before_stage :before_stage_callback
after_stage :after_stage_callback
def run
# nothing...
end
private
def before_stage_callback; end
def after_stage_callback; end
end
class SampleStageWithCallback < Pipeline::Stage::Base
attr_writer :before_stage_executed, :after_stage_executed
before_stage do |stage|
puts "called"
stage.before_stage_executed += 1
end
after_stage do |stage|
stage.after_stage_executed += 1
end
def run
# nothing...
end
def before_stage_executed
@before_stage_executed ||= 0
end
def after_stage_executed
@after_stage_executed ||= 0
end
end
class SamplePipelineWithCallbacks < Pipeline::Base
define_stages SampleStageWithCallback >> SampleStage
end