ductwork 0.1.0

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.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +5 -0
  3. data/LICENSE.txt +168 -0
  4. data/README.md +154 -0
  5. data/Rakefile +10 -0
  6. data/app/models/ductwork/availability.rb +9 -0
  7. data/app/models/ductwork/execution.rb +13 -0
  8. data/app/models/ductwork/job.rb +181 -0
  9. data/app/models/ductwork/pipeline.rb +195 -0
  10. data/app/models/ductwork/process.rb +19 -0
  11. data/app/models/ductwork/record.rb +15 -0
  12. data/app/models/ductwork/result.rb +13 -0
  13. data/app/models/ductwork/run.rb +9 -0
  14. data/app/models/ductwork/step.rb +27 -0
  15. data/lib/ductwork/cli.rb +48 -0
  16. data/lib/ductwork/configuration.rb +145 -0
  17. data/lib/ductwork/dsl/branch_builder.rb +102 -0
  18. data/lib/ductwork/dsl/definition_builder.rb +153 -0
  19. data/lib/ductwork/engine.rb +14 -0
  20. data/lib/ductwork/machine_identifier.rb +11 -0
  21. data/lib/ductwork/processes/job_worker.rb +71 -0
  22. data/lib/ductwork/processes/job_worker_runner.rb +164 -0
  23. data/lib/ductwork/processes/pipeline_advancer.rb +91 -0
  24. data/lib/ductwork/processes/pipeline_advancer_runner.rb +169 -0
  25. data/lib/ductwork/processes/supervisor.rb +160 -0
  26. data/lib/ductwork/processes/supervisor_runner.rb +35 -0
  27. data/lib/ductwork/running_context.rb +22 -0
  28. data/lib/ductwork/testing/helpers.rb +18 -0
  29. data/lib/ductwork/testing/minitest.rb +8 -0
  30. data/lib/ductwork/testing/rspec.rb +63 -0
  31. data/lib/ductwork/testing.rb +15 -0
  32. data/lib/ductwork/version.rb +5 -0
  33. data/lib/ductwork.rb +77 -0
  34. data/lib/generators/ductwork/install/USAGE +11 -0
  35. data/lib/generators/ductwork/install/install_generator.rb +36 -0
  36. data/lib/generators/ductwork/install/templates/bin/ductwork +8 -0
  37. data/lib/generators/ductwork/install/templates/config/ductwork.yml +25 -0
  38. data/lib/generators/ductwork/install/templates/db/create_ductwork_availabilities.rb +16 -0
  39. data/lib/generators/ductwork/install/templates/db/create_ductwork_executions.rb +14 -0
  40. data/lib/generators/ductwork/install/templates/db/create_ductwork_jobs.rb +17 -0
  41. data/lib/generators/ductwork/install/templates/db/create_ductwork_pipelines.rb +19 -0
  42. data/lib/generators/ductwork/install/templates/db/create_ductwork_processes.rb +14 -0
  43. data/lib/generators/ductwork/install/templates/db/create_ductwork_results.rb +14 -0
  44. data/lib/generators/ductwork/install/templates/db/create_ductwork_runs.rb +12 -0
  45. data/lib/generators/ductwork/install/templates/db/create_ductwork_steps.rb +17 -0
  46. metadata +165 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 252ad8643950e6ea9e5024d0e63885aea8c3c7020bef1586faf0b414b41206f0
4
+ data.tar.gz: 1133562c0ff6c84c6a91c87e3d73f734e01626842b42c31e49d87127aa25cd7d
5
+ SHA512:
6
+ metadata.gz: 36460be6d4d35656be5ce2cc0006eaa539f00992c6b32f0c07610d42bc889ea0e198e17d9c405bdfca73469895f9d3076fda4335aea6ad7e6dc5011de4e41612
7
+ data.tar.gz: ddb569815f9ac837881fa08b13541084a5048a34fceafe718026fc228966b35377d16af56edddd5dd74a8cf210a76a3b0986e40644a0d3d3d4efb2db91b475f6
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Ductwork Changelog
2
+
3
+ ## [0.1.0]
4
+
5
+ - Initial release - see [documentation](https://docs.getductwork.io/) for details
data/LICENSE.txt ADDED
@@ -0,0 +1,168 @@
1
+ Ductwork is an Open Source project licensed under the terms of
2
+ the LGPLv3.0 license. Please see below for license text:
3
+
4
+ GNU LESSER GENERAL PUBLIC LICENSE
5
+ Version 3, 29 June 2007
6
+
7
+ Copyright (c) 2024-2025 Tyler Ewing
8
+ Everyone is permitted to copy and distribute verbatim copies
9
+ of this license document, but changing it is not allowed.
10
+
11
+
12
+ This version of the GNU Lesser General Public License incorporates
13
+ the terms and conditions of version 3 of the GNU General Public
14
+ License, supplemented by the additional permissions listed below.
15
+
16
+ 0. Additional Definitions.
17
+
18
+ As used herein, "this License" refers to version 3 of the GNU Lesser
19
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
20
+ General Public License.
21
+
22
+ "The Library" refers to a covered work governed by this License,
23
+ other than an Application or a Combined Work as defined below.
24
+
25
+ An "Application" is any work that makes use of an interface provided
26
+ by the Library, but which is not otherwise based on the Library.
27
+ Defining a subclass of a class defined by the Library is deemed a mode
28
+ of using an interface provided by the Library.
29
+
30
+ A "Combined Work" is a work produced by combining or linking an
31
+ Application with the Library. The particular version of the Library
32
+ with which the Combined Work was made is also called the "Linked
33
+ Version".
34
+
35
+ The "Minimal Corresponding Source" for a Combined Work means the
36
+ Corresponding Source for the Combined Work, excluding any source code
37
+ for portions of the Combined Work that, considered in isolation, are
38
+ based on the Application, and not on the Linked Version.
39
+
40
+ The "Corresponding Application Code" for a Combined Work means the
41
+ object code and/or source code for the Application, including any data
42
+ and utility programs needed for reproducing the Combined Work from the
43
+ Application, but excluding the System Libraries of the Combined Work.
44
+
45
+ 1. Exception to Section 3 of the GNU GPL.
46
+
47
+ You may convey a covered work under sections 3 and 4 of this License
48
+ without being bound by section 3 of the GNU GPL.
49
+
50
+ 2. Conveying Modified Versions.
51
+
52
+ If you modify a copy of the Library, and, in your modifications, a
53
+ facility refers to a function or data to be supplied by an Application
54
+ that uses the facility (other than as an argument passed when the
55
+ facility is invoked), then you may convey a copy of the modified
56
+ version:
57
+
58
+ a) under this License, provided that you make a good faith effort to
59
+ ensure that, in the event an Application does not supply the
60
+ function or data, the facility still operates, and performs
61
+ whatever part of its purpose remains meaningful, or
62
+
63
+ b) under the GNU GPL, with none of the additional permissions of
64
+ this License applicable to that copy.
65
+
66
+ 3. Object Code Incorporating Material from Library Header Files.
67
+
68
+ The object code form of an Application may incorporate material from
69
+ a header file that is part of the Library. You may convey such object
70
+ code under terms of your choice, provided that, if the incorporated
71
+ material is not limited to numerical parameters, data structure
72
+ layouts and accessors, or small macros, inline functions and templates
73
+ (ten or fewer lines in length), you do both of the following:
74
+
75
+ a) Give prominent notice with each copy of the object code that the
76
+ Library is used in it and that the Library and its use are
77
+ covered by this License.
78
+
79
+ b) Accompany the object code with a copy of the GNU GPL and this license
80
+ document.
81
+
82
+ 4. Combined Works.
83
+
84
+ You may convey a Combined Work under terms of your choice that,
85
+ taken together, effectively do not restrict modification of the
86
+ portions of the Library contained in the Combined Work and reverse
87
+ engineering for debugging such modifications, if you also do each of
88
+ the following:
89
+
90
+ a) Give prominent notice with each copy of the Combined Work that
91
+ the Library is used in it and that the Library and its use are
92
+ covered by this License.
93
+
94
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
95
+ document.
96
+
97
+ c) For a Combined Work that displays copyright notices during
98
+ execution, include the copyright notice for the Library among
99
+ these notices, as well as a reference directing the user to the
100
+ copies of the GNU GPL and this license document.
101
+
102
+ d) Do one of the following:
103
+
104
+ 0) Convey the Minimal Corresponding Source under the terms of this
105
+ License, and the Corresponding Application Code in a form
106
+ suitable for, and under terms that permit, the user to
107
+ recombine or relink the Application with a modified version of
108
+ the Linked Version to produce a modified Combined Work, in the
109
+ manner specified by section 6 of the GNU GPL for conveying
110
+ Corresponding Source.
111
+
112
+ 1) Use a suitable shared library mechanism for linking with the
113
+ Library. A suitable mechanism is one that (a) uses at run time
114
+ a copy of the Library already present on the user's computer
115
+ system, and (b) will operate properly with a modified version
116
+ of the Library that is interface-compatible with the Linked
117
+ Version.
118
+
119
+ e) Provide Installation Information, but only if you would otherwise
120
+ be required to provide such information under section 6 of the
121
+ GNU GPL, and only to the extent that such information is
122
+ necessary to install and execute a modified version of the
123
+ Combined Work produced by recombining or relinking the
124
+ Application with a modified version of the Linked Version. (If
125
+ you use option 4d0, the Installation Information must accompany
126
+ the Minimal Corresponding Source and Corresponding Application
127
+ Code. If you use option 4d1, you must provide the Installation
128
+ Information in the manner specified by section 6 of the GNU GPL
129
+ for conveying Corresponding Source.)
130
+
131
+ 5. Combined Libraries.
132
+
133
+ You may place library facilities that are a work based on the
134
+ Library side by side in a single library together with other library
135
+ facilities that are not Applications and are not covered by this
136
+ License, and convey such a combined library under terms of your
137
+ choice, if you do both of the following:
138
+
139
+ a) Accompany the combined library with a copy of the same work based
140
+ on the Library, uncombined with any other library facilities,
141
+ conveyed under the terms of this License.
142
+
143
+ b) Give prominent notice with the combined library that part of it
144
+ is a work based on the Library, and explaining where to find the
145
+ accompanying uncombined form of the same work.
146
+
147
+ 6. Revised Versions of the GNU Lesser General Public License.
148
+
149
+ The Free Software Foundation may publish revised and/or new versions
150
+ of the GNU Lesser General Public License from time to time. Such new
151
+ versions will be similar in spirit to the present version, but may
152
+ differ in detail to address new problems or concerns.
153
+
154
+ Each version is given a distinguishing version number. If the
155
+ Library as you received it specifies that a certain numbered version
156
+ of the GNU Lesser General Public License "or any later version"
157
+ applies to it, you have the option of following the terms and
158
+ conditions either of that published version or of any later version
159
+ published by the Free Software Foundation. If the Library as you
160
+ received it does not specify a version number of the GNU Lesser
161
+ General Public License, you may choose any version of the GNU Lesser
162
+ General Public License ever published by the Free Software Foundation.
163
+
164
+ If the Library as you received it specifies that a proxy can decide
165
+ whether future versions of the GNU Lesser General Public License shall
166
+ apply, that proxy's public statement of acceptance of any version is
167
+ permanent authorization for you to choose that version for the
168
+ Library.
data/README.md ADDED
@@ -0,0 +1,154 @@
1
+ # Ductwork
2
+
3
+ A Ruby pipeline framework.
4
+
5
+ Ductwork lets you build complex pipelines quickly and easily using intuitive Ruby tooling and a natural DSL. No need to learn complicated unified object models or stand up separate runner instances—just write Ruby code and let Ductwork handle the orchestration.
6
+
7
+ **[Full Documentation](https://docs.getductwork.io/)**
8
+
9
+ ## Installation
10
+
11
+ Add Ductwork to your application's Gemfile:
12
+
13
+ ```bash
14
+ bundle add ductwork
15
+ ```
16
+
17
+ Run the Rails generator to create the binstub, configuration file, and migrations:
18
+
19
+ ```bash
20
+ bin/rails generate ductwork:install
21
+ ```
22
+
23
+ Run migrations and you're ready to start building pipelines!
24
+
25
+ ## Configuration
26
+
27
+
28
+ The only required configuration is specifying which pipelines to run. Edit the default configuration file `config/ductwork.yml`:
29
+
30
+ ```yaml
31
+ default: &default
32
+ pipelines:
33
+ - EnrichUserDataPipeline
34
+ - SendMonthlyStatusReportsPipeline
35
+ ```
36
+
37
+ Or use the wildcard to run all pipelines (use cautiously—this can consume significant resources):
38
+
39
+ ```yaml
40
+ default: &default
41
+ pipelines: "*"
42
+ ```
43
+
44
+ See the [Configuration Guide](https://docs.getductwork.io/advanced/configuration.html) for all available options including thread counts, timeouts, and database settings.
45
+
46
+ ## Usage
47
+
48
+ ### 1. Create a Pipeline Class
49
+
50
+ Pipeline classes live in `app/pipelines` and inherit from `Ductwork::Pipeline`. While the "Pipeline" suffix is optional, it can help avoid naming collisions:
51
+
52
+ ```ruby
53
+ # app/pipelines/enrich_user_data_pipeline.rb
54
+ class EnrichUserDataPipeline < Ductwork::Pipeline
55
+ end
56
+ ```
57
+
58
+ ### 2. Define Steps
59
+
60
+ Steps are Plain Old Ruby Objects (POROs) that implement two methods:
61
+ - `initialize` - accepts parameters from the trigger call or previous step's return value
62
+ - `execute` - performs the work and returns data for the next step
63
+
64
+ Steps live in `app/steps`:
65
+
66
+ ```ruby
67
+ # app/steps/users_requiring_enrichment.rb
68
+ class UsersRequiringEnrichment
69
+ def initialize(days_outdated)
70
+ @days_outdated = days_outdated
71
+ end
72
+
73
+ def execute
74
+ ids = User.where("data_last_refreshed_at < ?", @days_outdated.days.ago).ids
75
+ Rails.logger.info("Enriching #{ids.length} users' data")
76
+
77
+ # Return value becomes input to the next step
78
+ ids
79
+ end
80
+ end
81
+ ```
82
+
83
+ ### 3. Define Transitions
84
+
85
+ Connect steps together using Ductwork's fluent interface DSL. The key principle: **each step's return value becomes the next step's input**.
86
+
87
+ ```ruby
88
+ class EnrichUserDataPipeline < Ductwork::Pipeline
89
+ define do |pipeline|
90
+ pipeline.start(UsersRequiringEnrichment) # Start with a single step
91
+ .expand(to: LoadUserData) # Fan out to multiple steps
92
+ .divide(to: [FetchDataFromSourceA, # Split into parallel branches
93
+ FetchDataFromSourceB])
94
+ .combine(into: CollateUserData) # Merge branches back together
95
+ .chain(UpdateUserData) # Sequential processing
96
+ .collapse(into: ReportSuccess) # Gather expanded steps
97
+ end
98
+ end
99
+ ```
100
+
101
+ **Important:** Return values must be JSON-serializable.
102
+
103
+ See [Defining Pipelines](https://docs.getductwork.io/getting_started/defining-pipelines.html) for detailed documentation.
104
+
105
+ ### 4. Run Ductwork
106
+
107
+ Start the Ductwork supervisor, which manages pipeline advancers and job workers for each configured pipeline:
108
+
109
+ ```bash
110
+ bin/ductwork
111
+ ```
112
+
113
+ Use a custom configuration file if needed:
114
+
115
+ ```bash
116
+ bin/ductwork -c config/ductwork.0.yml
117
+ ```
118
+
119
+ ### 5. Trigger Your Pipeline
120
+
121
+ Trigger pipelines from anywhere in your Rails application. The `trigger` method returns a `Ductwork::Pipeline` instance for monitoring:
122
+
123
+ ```ruby
124
+ # In a Rake task
125
+ task enrich_user_data: :environment do
126
+ pipeline = EnrichUserDataPipeline.trigger(7)
127
+ puts "Pipeline #{pipeline.id} started"
128
+ end
129
+
130
+ # In a controller
131
+ def create
132
+ pipeline = EnrichUserDataPipeline.trigger(params[:days_outdated])
133
+
134
+ render json: { pipeline_id: pipeline.id, status: pipeline.status }
135
+ end
136
+ ```
137
+
138
+ ## Development
139
+
140
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
141
+
142
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
143
+
144
+ ## Contributing
145
+
146
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ductwork/ductwork. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/ductwork/ductwork/blob/main/CODE_OF_CONDUCT.md).
147
+
148
+ ## License
149
+
150
+ The gem is available as open source under the terms of the [LGPLv3.0 License](https://github.com/ductwork/ductwork/blob/main/LICENSE.txt).
151
+
152
+ ## Code of Conduct
153
+
154
+ Everyone interacting in the Ductwork project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ductwork/ductwork/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+ require "rubocop/rake_task"
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+ RuboCop::RakeTask.new
9
+
10
+ task default: %i[spec rubocop]
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ductwork
4
+ class Availability < Ductwork::Record
5
+ belongs_to :execution, class_name: "Ductwork::Execution"
6
+
7
+ validates :started_at, presence: true
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ductwork
4
+ class Execution < Ductwork::Record
5
+ belongs_to :job, class_name: "Ductwork::Job"
6
+ has_one :availability, class_name: "Ductwork::Availability", foreign_key: "execution_id"
7
+ has_one :run, class_name: "Ductwork::Run", foreign_key: "execution_id"
8
+ has_one :result, class_name: "Ductwork::Result", foreign_key: "execution_id"
9
+
10
+ validates :retry_count, presence: true
11
+ validates :started_at, presence: true
12
+ end
13
+ end
@@ -0,0 +1,181 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ductwork
4
+ class Job < Ductwork::Record
5
+ belongs_to :step, class_name: "Ductwork::Step"
6
+ has_many :executions, class_name: "Ductwork::Execution", foreign_key: "job_id", dependent: :destroy
7
+
8
+ validates :klass, presence: true
9
+ validates :started_at, presence: true
10
+ validates :input_args, presence: true
11
+
12
+ FAILED_EXECUTION_TIMEOUT = 10.seconds
13
+
14
+ def self.claim_latest(klass) # rubocop:todo Metrics/MethodLength
15
+ process_id = ::Process.pid
16
+ id = Ductwork::Availability
17
+ .joins(execution: { job: { step: :pipeline } })
18
+ .where("ductwork_availabilities.started_at <= ?", Time.current)
19
+ .where(completed_at: nil)
20
+ .where(ductwork_pipelines: { klass: })
21
+ .order(:created_at)
22
+ .limit(1)
23
+ .pluck(:id)
24
+ .first
25
+
26
+ if id.present?
27
+ # TODO: probably makes sense to use SQL here instead of relying
28
+ # on ActiveRecord to construct the correct `UPDATE` query
29
+ rows_updated = nil
30
+ Ductwork::Record.transaction do
31
+ rows_updated = Ductwork::Availability
32
+ .where(id: id, completed_at: nil)
33
+ .update_all(completed_at: Time.current, process_id: process_id)
34
+ Ductwork::Execution
35
+ .joins(:availability)
36
+ .where(completed_at: nil)
37
+ .where(ductwork_availabilities: { id: })
38
+ .update_all(process_id:)
39
+ end
40
+
41
+ if rows_updated == 1
42
+ Ductwork.configuration.logger.debug(
43
+ msg: "Job claimed",
44
+ role: :job_worker,
45
+ process_id: process_id,
46
+ availability_id: id
47
+ )
48
+ Ductwork::Job
49
+ .joins(executions: :availability)
50
+ .find_by(ductwork_availabilities: { id:, process_id: })
51
+ else
52
+ Ductwork.configuration.logger.debug(
53
+ msg: "Did not claim job, avoided race condition",
54
+ role: :job_worker,
55
+ process_id: process_id,
56
+ availability_id: id
57
+ )
58
+ nil
59
+ end
60
+ end
61
+ end
62
+
63
+ def self.enqueue(step, *args)
64
+ Ductwork::Record.transaction do
65
+ job = step.create_job!(
66
+ klass: step.klass,
67
+ started_at: Time.current,
68
+ input_args: JSON.dump({ args: })
69
+ )
70
+ execution = job.executions.create!(
71
+ started_at: Time.current,
72
+ retry_count: 0
73
+ )
74
+ execution.create_availability!(
75
+ started_at: Time.current
76
+ )
77
+
78
+ job
79
+ end
80
+ end
81
+
82
+ def execute(pipeline)
83
+ # i don't _really_ like this, but it should be fine for now...
84
+ execution = executions.order(:created_at).last
85
+ logger.debug(
86
+ msg: "Executing job",
87
+ role: :job_worker,
88
+ pipeline: pipeline,
89
+ job_klass: klass
90
+ )
91
+ args = JSON.parse(input_args)["args"]
92
+ instance = Object.const_get(klass).new(*args)
93
+ run = execution.create_run!(
94
+ started_at: Time.current
95
+ )
96
+ result = nil
97
+
98
+ begin
99
+ output_payload = instance.execute
100
+ execution_succeeded!(execution, run, output_payload)
101
+ result = "success"
102
+ rescue StandardError => e
103
+ execution_failed!(execution, run, e)
104
+ result = "failure"
105
+ ensure
106
+ logger.debug(
107
+ msg: "Executed job",
108
+ role: :job_worker,
109
+ pipeline: pipeline,
110
+ job_klass: klass,
111
+ result: result
112
+ )
113
+ end
114
+ end
115
+
116
+ def return_value
117
+ if output_payload.present?
118
+ JSON.parse(output_payload).fetch("payload", nil)
119
+ end
120
+ end
121
+
122
+ private
123
+
124
+ def logger
125
+ Ductwork.configuration.logger
126
+ end
127
+
128
+ def execution_succeeded!(execution, run, output_payload)
129
+ payload = JSON.dump({ payload: output_payload })
130
+
131
+ Ductwork::Record.transaction do
132
+ update!(output_payload: payload, completed_at: Time.current)
133
+ execution.update!(completed_at: Time.current)
134
+ run.update!(completed_at: Time.current)
135
+ execution.create_result!(result_type: "success")
136
+ step.update!(status: :advancing)
137
+ end
138
+ end
139
+
140
+ def execution_failed!(execution, run, error) # rubocop:disable Metrics/AbcSize
141
+ halted = false
142
+ pipeline = step.pipeline
143
+
144
+ Ductwork::Record.transaction do
145
+ execution.update!(completed_at: Time.current)
146
+ run.update!(completed_at: Time.current)
147
+ execution.create_result!(
148
+ result_type: "failure",
149
+ error_klass: error.class.to_s,
150
+ error_message: error.message,
151
+ error_backtrace: error.backtrace
152
+ )
153
+
154
+ if execution.retry_count < Ductwork.configuration.job_worker_max_retry
155
+ new_execution = executions.create!(
156
+ retry_count: execution.retry_count + 1,
157
+ started_at: FAILED_EXECUTION_TIMEOUT.from_now
158
+ )
159
+ new_execution.create_availability!(
160
+ started_at: FAILED_EXECUTION_TIMEOUT.from_now
161
+ )
162
+ elsif execution.retry_count >= Ductwork.configuration.job_worker_max_retry
163
+ halted = true
164
+
165
+ step.update!(status: :failed)
166
+ pipeline.halted!
167
+ end
168
+ end
169
+
170
+ # NOTE: perform lifecycle hook execution outside of the transaction as
171
+ # to not unnecessarily hold it open
172
+ if halted
173
+ klass = JSON.parse(pipeline.definition).dig("metadata", "on_halt", "klass")
174
+
175
+ if klass.present?
176
+ Object.const_get(klass).new(error).execute
177
+ end
178
+ end
179
+ end
180
+ end
181
+ end