cmdx 1.21.0 → 2.0.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +118 -1
- data/README.md +37 -24
- data/lib/cmdx/.DS_Store +0 -0
- data/lib/cmdx/callbacks.rb +179 -0
- data/lib/cmdx/chain.rb +78 -175
- data/lib/cmdx/coercions/array.rb +19 -33
- data/lib/cmdx/coercions/big_decimal.rb +12 -29
- data/lib/cmdx/coercions/boolean.rb +25 -45
- data/lib/cmdx/coercions/coerce.rb +32 -0
- data/lib/cmdx/coercions/complex.rb +12 -27
- data/lib/cmdx/coercions/date.rb +29 -33
- data/lib/cmdx/coercions/date_time.rb +29 -33
- data/lib/cmdx/coercions/float.rb +8 -29
- data/lib/cmdx/coercions/hash.rb +17 -43
- data/lib/cmdx/coercions/integer.rb +8 -32
- data/lib/cmdx/coercions/rational.rb +12 -33
- data/lib/cmdx/coercions/string.rb +6 -24
- data/lib/cmdx/coercions/symbol.rb +12 -26
- data/lib/cmdx/coercions/time.rb +31 -35
- data/lib/cmdx/coercions.rb +174 -0
- data/lib/cmdx/configuration.rb +45 -237
- data/lib/cmdx/context.rb +264 -243
- data/lib/cmdx/deprecation.rb +67 -0
- data/lib/cmdx/deprecators/error.rb +22 -0
- data/lib/cmdx/deprecators/log.rb +22 -0
- data/lib/cmdx/deprecators/warn.rb +21 -0
- data/lib/cmdx/deprecators.rb +101 -0
- data/lib/cmdx/errors.rb +145 -79
- data/lib/cmdx/executors/fiber.rb +42 -0
- data/lib/cmdx/executors/thread.rb +36 -0
- data/lib/cmdx/executors.rb +95 -0
- data/lib/cmdx/fault.rb +85 -78
- data/lib/cmdx/i18n_proxy.rb +104 -0
- data/lib/cmdx/input.rb +294 -0
- data/lib/cmdx/inputs.rb +218 -0
- data/lib/cmdx/log_formatters/json.rb +9 -20
- data/lib/cmdx/log_formatters/key_value.rb +10 -21
- data/lib/cmdx/log_formatters/line.rb +7 -19
- data/lib/cmdx/log_formatters/logstash.rb +8 -21
- data/lib/cmdx/log_formatters/raw.rb +8 -20
- data/lib/cmdx/logger_proxy.rb +30 -0
- data/lib/cmdx/mergers/deep_merge.rb +23 -0
- data/lib/cmdx/mergers/last_write_wins.rb +23 -0
- data/lib/cmdx/mergers/no_merge.rb +20 -0
- data/lib/cmdx/mergers.rb +95 -0
- data/lib/cmdx/middlewares.rb +128 -0
- data/lib/cmdx/output.rb +115 -0
- data/lib/cmdx/outputs.rb +66 -0
- data/lib/cmdx/pipeline.rb +144 -131
- data/lib/cmdx/railtie.rb +10 -36
- data/lib/cmdx/result.rb +247 -524
- data/lib/cmdx/retriers/bounded_random.rb +24 -0
- data/lib/cmdx/retriers/decorrelated_jitter.rb +28 -0
- data/lib/cmdx/retriers/exponential.rb +23 -0
- data/lib/cmdx/retriers/fibonacci.rb +39 -0
- data/lib/cmdx/retriers/full_random.rb +23 -0
- data/lib/cmdx/retriers/half_random.rb +24 -0
- data/lib/cmdx/retriers/linear.rb +23 -0
- data/lib/cmdx/retriers.rb +106 -0
- data/lib/cmdx/retry.rb +117 -138
- data/lib/cmdx/runtime.rb +251 -0
- data/lib/cmdx/settings.rb +68 -200
- data/lib/cmdx/signal.rb +165 -0
- data/lib/cmdx/task.rb +443 -343
- data/lib/cmdx/telemetry.rb +108 -0
- data/lib/cmdx/util.rb +73 -0
- data/lib/cmdx/validators/absence.rb +10 -39
- data/lib/cmdx/validators/exclusion.rb +33 -52
- data/lib/cmdx/validators/format.rb +19 -49
- data/lib/cmdx/validators/inclusion.rb +33 -54
- data/lib/cmdx/validators/length.rb +125 -127
- data/lib/cmdx/validators/numeric.rb +123 -123
- data/lib/cmdx/validators/presence.rb +10 -39
- data/lib/cmdx/validators/validate.rb +31 -0
- data/lib/cmdx/validators.rb +161 -0
- data/lib/cmdx/version.rb +2 -4
- data/lib/cmdx/workflow.rb +71 -96
- data/lib/cmdx.rb +111 -42
- data/lib/generators/cmdx/install_generator.rb +7 -17
- data/lib/generators/cmdx/task_generator.rb +12 -29
- data/lib/generators/cmdx/templates/install.rb +120 -48
- data/lib/generators/cmdx/templates/task.rb.tt +1 -1
- data/lib/generators/cmdx/templates/workflow.rb.tt +1 -2
- data/lib/generators/cmdx/workflow_generator.rb +12 -29
- data/lib/locales/en.yml +8 -7
- data/mkdocs.yml +25 -23
- metadata +39 -138
- data/lib/cmdx/attribute.rb +0 -440
- data/lib/cmdx/attribute_registry.rb +0 -185
- data/lib/cmdx/attribute_value.rb +0 -252
- data/lib/cmdx/callback_registry.rb +0 -169
- data/lib/cmdx/coercion_registry.rb +0 -138
- data/lib/cmdx/deprecator.rb +0 -77
- data/lib/cmdx/exception.rb +0 -46
- data/lib/cmdx/executor.rb +0 -378
- data/lib/cmdx/identifier.rb +0 -30
- data/lib/cmdx/locale.rb +0 -78
- data/lib/cmdx/middleware_registry.rb +0 -148
- data/lib/cmdx/middlewares/correlate.rb +0 -140
- data/lib/cmdx/middlewares/runtime.rb +0 -77
- data/lib/cmdx/middlewares/timeout.rb +0 -78
- data/lib/cmdx/parallelizer.rb +0 -100
- data/lib/cmdx/utils/call.rb +0 -53
- data/lib/cmdx/utils/condition.rb +0 -71
- data/lib/cmdx/utils/format.rb +0 -82
- data/lib/cmdx/utils/normalize.rb +0 -52
- data/lib/cmdx/utils/wrap.rb +0 -38
- data/lib/cmdx/validator_registry.rb +0 -143
- data/lib/generators/cmdx/locale_generator.rb +0 -39
- data/lib/locales/af.yml +0 -55
- data/lib/locales/ar.yml +0 -55
- data/lib/locales/az.yml +0 -55
- data/lib/locales/be.yml +0 -55
- data/lib/locales/bg.yml +0 -55
- data/lib/locales/bn.yml +0 -55
- data/lib/locales/bs.yml +0 -55
- data/lib/locales/ca.yml +0 -55
- data/lib/locales/cnr.yml +0 -55
- data/lib/locales/cs.yml +0 -55
- data/lib/locales/cy.yml +0 -55
- data/lib/locales/da.yml +0 -55
- data/lib/locales/de.yml +0 -55
- data/lib/locales/dz.yml +0 -55
- data/lib/locales/el.yml +0 -55
- data/lib/locales/eo.yml +0 -55
- data/lib/locales/es.yml +0 -55
- data/lib/locales/et.yml +0 -55
- data/lib/locales/eu.yml +0 -55
- data/lib/locales/fa.yml +0 -55
- data/lib/locales/fi.yml +0 -55
- data/lib/locales/fr.yml +0 -55
- data/lib/locales/fy.yml +0 -55
- data/lib/locales/gd.yml +0 -55
- data/lib/locales/gl.yml +0 -55
- data/lib/locales/he.yml +0 -55
- data/lib/locales/hi.yml +0 -55
- data/lib/locales/hr.yml +0 -55
- data/lib/locales/hu.yml +0 -55
- data/lib/locales/hy.yml +0 -55
- data/lib/locales/id.yml +0 -55
- data/lib/locales/is.yml +0 -55
- data/lib/locales/it.yml +0 -55
- data/lib/locales/ja.yml +0 -55
- data/lib/locales/ka.yml +0 -55
- data/lib/locales/kk.yml +0 -55
- data/lib/locales/km.yml +0 -55
- data/lib/locales/kn.yml +0 -55
- data/lib/locales/ko.yml +0 -55
- data/lib/locales/lb.yml +0 -55
- data/lib/locales/lo.yml +0 -55
- data/lib/locales/lt.yml +0 -55
- data/lib/locales/lv.yml +0 -55
- data/lib/locales/mg.yml +0 -55
- data/lib/locales/mk.yml +0 -55
- data/lib/locales/ml.yml +0 -55
- data/lib/locales/mn.yml +0 -55
- data/lib/locales/mr-IN.yml +0 -55
- data/lib/locales/ms.yml +0 -55
- data/lib/locales/nb.yml +0 -55
- data/lib/locales/ne.yml +0 -55
- data/lib/locales/nl.yml +0 -55
- data/lib/locales/nn.yml +0 -55
- data/lib/locales/oc.yml +0 -55
- data/lib/locales/or.yml +0 -55
- data/lib/locales/pa.yml +0 -55
- data/lib/locales/pl.yml +0 -55
- data/lib/locales/pt.yml +0 -55
- data/lib/locales/rm.yml +0 -55
- data/lib/locales/ro.yml +0 -55
- data/lib/locales/ru.yml +0 -55
- data/lib/locales/sc.yml +0 -55
- data/lib/locales/sk.yml +0 -55
- data/lib/locales/sl.yml +0 -55
- data/lib/locales/sq.yml +0 -55
- data/lib/locales/sr.yml +0 -55
- data/lib/locales/st.yml +0 -55
- data/lib/locales/sv.yml +0 -55
- data/lib/locales/sw.yml +0 -55
- data/lib/locales/ta.yml +0 -55
- data/lib/locales/te.yml +0 -55
- data/lib/locales/th.yml +0 -55
- data/lib/locales/tl.yml +0 -55
- data/lib/locales/tr.yml +0 -55
- data/lib/locales/tt.yml +0 -55
- data/lib/locales/ug.yml +0 -55
- data/lib/locales/uk.yml +0 -55
- data/lib/locales/ur.yml +0 -55
- data/lib/locales/uz.yml +0 -55
- data/lib/locales/vi.yml +0 -55
- data/lib/locales/wo.yml +0 -55
- data/lib/locales/zh-CN.yml +0 -55
- data/lib/locales/zh-HK.yml +0 -55
- data/lib/locales/zh-TW.yml +0 -55
- data/lib/locales/zh-YUE.yml +0 -55
data/lib/cmdx/signal.rb
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CMDx
|
|
4
|
+
# Internal halt token thrown by `success!`, `skip!`, `fail!`, and `throw!`
|
|
5
|
+
# from inside a Task's `work`. Runtime catches `Signal::TAG` and converts the
|
|
6
|
+
# payload into a {Result}. Not meant to be raised directly by user code.
|
|
7
|
+
#
|
|
8
|
+
# @see Runtime#perform_work
|
|
9
|
+
# @see Task#success!
|
|
10
|
+
# @see Task#fail!
|
|
11
|
+
class Signal
|
|
12
|
+
|
|
13
|
+
# `catch`/`throw` tag used by Runtime to intercept signal payloads.
|
|
14
|
+
TAG = :cmdx_signal
|
|
15
|
+
|
|
16
|
+
# All valid execution lifecycle states.
|
|
17
|
+
STATES = [
|
|
18
|
+
COMPLETE = "complete",
|
|
19
|
+
INTERRUPTED = "interrupted"
|
|
20
|
+
].freeze
|
|
21
|
+
# All valid outcome statuses.
|
|
22
|
+
STATUSES = [
|
|
23
|
+
SUCCESS = "success",
|
|
24
|
+
SKIPPED = "skipped",
|
|
25
|
+
FAILED = "failed"
|
|
26
|
+
].freeze
|
|
27
|
+
|
|
28
|
+
class << self
|
|
29
|
+
|
|
30
|
+
# Builds a successful signal (state `complete`, status `success`).
|
|
31
|
+
#
|
|
32
|
+
# @param reason [String, nil] optional human-readable reason
|
|
33
|
+
# @param options [Hash{Symbol => Object}] optional `:metadata`, `:cause`, `:backtrace`
|
|
34
|
+
# @option options [Hash{Symbol => Object}] :metadata merged onto the task metadata payload
|
|
35
|
+
# @option options [Exception] :cause upstream exception when mirroring failures
|
|
36
|
+
# @option options [Array<Thread::Backtrace::Location>] :backtrace captured frames
|
|
37
|
+
# @return [Signal] new instance with frozen options
|
|
38
|
+
def success(reason = nil, **options)
|
|
39
|
+
new(COMPLETE, SUCCESS, **options, reason:)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Builds a skipped signal (state `interrupted`, status `skipped`).
|
|
43
|
+
#
|
|
44
|
+
# @param reason [String, nil] optional human-readable reason
|
|
45
|
+
# @param options [Hash{Symbol => Object}] optional `:metadata`, `:cause`, `:backtrace`
|
|
46
|
+
# @option options [Hash{Symbol => Object}] :metadata merged onto the task metadata payload
|
|
47
|
+
# @option options [Exception] :cause upstream exception when mirroring failures
|
|
48
|
+
# @option options [Array<Thread::Backtrace::Location>] :backtrace captured frames
|
|
49
|
+
# @return [Signal] new instance with frozen options
|
|
50
|
+
def skipped(reason = nil, **options)
|
|
51
|
+
new(INTERRUPTED, SKIPPED, **options, reason:)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Builds a failed signal (state `interrupted`, status `failed`).
|
|
55
|
+
#
|
|
56
|
+
# @param reason [String, nil] optional human-readable reason
|
|
57
|
+
# @param options [Hash{Symbol => Object}] optional `:metadata`, `:cause`, `:backtrace`
|
|
58
|
+
# @option options [Hash{Symbol => Object}] :metadata merged onto the task metadata payload
|
|
59
|
+
# @option options [Exception] :cause upstream exception when mirroring failures
|
|
60
|
+
# @option options [Array<Thread::Backtrace::Location>] :backtrace captured frames
|
|
61
|
+
# @return [Signal] new instance with frozen options
|
|
62
|
+
def failed(reason = nil, **options)
|
|
63
|
+
new(INTERRUPTED, FAILED, **options, reason:)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Mirrors another Signal/Result's state + status with fresh options.
|
|
67
|
+
# Used by Runtime to propagate a nested `Fault`'s outcome.
|
|
68
|
+
#
|
|
69
|
+
# @param other [Signal, Result] source to mirror state/status/reason from
|
|
70
|
+
# @param options [Hash{Symbol => Object}] overrides: `:metadata`, `:cause`,
|
|
71
|
+
# `:backtrace`, `:origin`
|
|
72
|
+
# @option options [Hash{Symbol => Object}] :metadata merged onto the task metadata payload
|
|
73
|
+
# @option options [Exception] :cause upstream exception when mirroring failures
|
|
74
|
+
# @option options [Array<Thread::Backtrace::Location>] :backtrace captured frames
|
|
75
|
+
# @option options [Result] :origin peer result this signal echoes (set automatically for Results)
|
|
76
|
+
# @return [Signal] new instance mirroring `other`
|
|
77
|
+
# @raise [ArgumentError] when `other` is neither a Signal nor a Result
|
|
78
|
+
def echoed(other, **options)
|
|
79
|
+
raise ArgumentError, "must be a Result or Signal" unless other.is_a?(Result) || other.is_a?(Signal)
|
|
80
|
+
|
|
81
|
+
options[:origin] = other if other.is_a?(Result) && !options.key?(:origin)
|
|
82
|
+
new(other.state, other.status, **options, reason: other.reason)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
attr_reader :state, :status
|
|
88
|
+
|
|
89
|
+
# @param state [String] one of {STATES}
|
|
90
|
+
# @param status [String] one of {STATUSES}
|
|
91
|
+
# @param options [Hash{Symbol => Object}] frozen metadata payload
|
|
92
|
+
# @option options [String] :reason
|
|
93
|
+
# @option options [Hash] :metadata
|
|
94
|
+
# @option options [Exception] :cause
|
|
95
|
+
# @option options [Result] :origin
|
|
96
|
+
# @option options [Array<Thread::Backtrace::Location>] :backtrace
|
|
97
|
+
def initialize(state, status, **options)
|
|
98
|
+
@state = state
|
|
99
|
+
@status = status
|
|
100
|
+
@options = options.freeze
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# @return [Boolean] true when the task ran to completion without interruption
|
|
104
|
+
def complete?
|
|
105
|
+
state == COMPLETE
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# @return [Boolean] true when skip/fail interrupted the task
|
|
109
|
+
def interrupted?
|
|
110
|
+
state == INTERRUPTED
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# @return [Boolean]
|
|
114
|
+
def success?
|
|
115
|
+
status == SUCCESS
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# @return [Boolean]
|
|
119
|
+
def skipped?
|
|
120
|
+
status == SKIPPED
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
# @return [Boolean]
|
|
124
|
+
def failed?
|
|
125
|
+
status == FAILED
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# @return [Boolean] true for success or skipped (anything but failed)
|
|
129
|
+
def ok?
|
|
130
|
+
!failed?
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
# @return [Boolean] true for skipped or failed (anything but success)
|
|
134
|
+
def ko?
|
|
135
|
+
!success?
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# @return [String, nil] human-readable explanation supplied by the caller
|
|
139
|
+
def reason
|
|
140
|
+
@options[:reason]
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
# @return [Hash{Symbol => Object}] frozen-empty hash when none was provided
|
|
144
|
+
def metadata
|
|
145
|
+
@options[:metadata] || EMPTY_HASH
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# @return [Exception, nil] underlying exception when a rescue produced this signal
|
|
149
|
+
def cause
|
|
150
|
+
@options[:cause]
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
# @return [Result, nil] upstream result this signal was echoed from, when any
|
|
154
|
+
def origin
|
|
155
|
+
@options[:origin]
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
# @return [Array<Thread::Backtrace::Location>, nil] caller locations captured
|
|
159
|
+
# by `fail!` / `throw!` for Fault backtraces
|
|
160
|
+
def backtrace
|
|
161
|
+
@options[:backtrace]
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
end
|
|
165
|
+
end
|