cmdx 1.0.1 → 1.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.
- checksums.yaml +4 -4
- data/.cursor/prompts/rspec.md +20 -0
- data/.cursor/prompts/yardoc.md +8 -0
- data/.rubocop.yml +2 -0
- data/CHANGELOG.md +17 -2
- data/README.md +1 -1
- data/docs/basics/call.md +2 -2
- data/docs/basics/chain.md +1 -1
- data/docs/callbacks.md +3 -36
- data/docs/configuration.md +58 -12
- data/docs/interruptions/exceptions.md +1 -1
- data/docs/interruptions/faults.md +2 -2
- data/docs/logging.md +4 -4
- data/docs/middlewares.md +43 -43
- data/docs/parameters/coercions.md +49 -38
- data/docs/parameters/defaults.md +1 -1
- data/docs/parameters/validations.md +0 -39
- data/docs/testing.md +11 -12
- data/docs/workflows.md +4 -4
- data/lib/cmdx/.DS_Store +0 -0
- data/lib/cmdx/callback.rb +36 -56
- data/lib/cmdx/callback_registry.rb +82 -73
- data/lib/cmdx/chain.rb +65 -122
- data/lib/cmdx/chain_inspector.rb +22 -115
- data/lib/cmdx/chain_serializer.rb +17 -148
- data/lib/cmdx/coercion.rb +49 -0
- data/lib/cmdx/coercion_registry.rb +94 -0
- data/lib/cmdx/coercions/array.rb +18 -36
- data/lib/cmdx/coercions/big_decimal.rb +21 -33
- data/lib/cmdx/coercions/boolean.rb +21 -40
- data/lib/cmdx/coercions/complex.rb +18 -31
- data/lib/cmdx/coercions/date.rb +20 -39
- data/lib/cmdx/coercions/date_time.rb +22 -39
- data/lib/cmdx/coercions/float.rb +19 -32
- data/lib/cmdx/coercions/hash.rb +22 -41
- data/lib/cmdx/coercions/integer.rb +20 -33
- data/lib/cmdx/coercions/rational.rb +20 -32
- data/lib/cmdx/coercions/string.rb +23 -31
- data/lib/cmdx/coercions/time.rb +24 -40
- data/lib/cmdx/coercions/virtual.rb +14 -31
- data/lib/cmdx/configuration.rb +57 -171
- data/lib/cmdx/context.rb +22 -165
- data/lib/cmdx/core_ext/hash.rb +42 -67
- data/lib/cmdx/core_ext/module.rb +35 -79
- data/lib/cmdx/core_ext/object.rb +63 -98
- data/lib/cmdx/correlator.rb +40 -156
- data/lib/cmdx/error.rb +37 -202
- data/lib/cmdx/errors.rb +165 -202
- data/lib/cmdx/fault.rb +55 -158
- data/lib/cmdx/faults.rb +26 -137
- data/lib/cmdx/immutator.rb +22 -109
- data/lib/cmdx/lazy_struct.rb +103 -187
- data/lib/cmdx/log_formatters/json.rb +14 -40
- data/lib/cmdx/log_formatters/key_value.rb +14 -40
- data/lib/cmdx/log_formatters/line.rb +14 -48
- data/lib/cmdx/log_formatters/logstash.rb +14 -57
- data/lib/cmdx/log_formatters/pretty_json.rb +14 -50
- data/lib/cmdx/log_formatters/pretty_key_value.rb +13 -46
- data/lib/cmdx/log_formatters/pretty_line.rb +16 -54
- data/lib/cmdx/log_formatters/raw.rb +19 -49
- data/lib/cmdx/logger.rb +20 -82
- data/lib/cmdx/logger_ansi.rb +18 -75
- data/lib/cmdx/logger_serializer.rb +24 -114
- data/lib/cmdx/middleware.rb +38 -60
- data/lib/cmdx/middleware_registry.rb +81 -77
- data/lib/cmdx/middlewares/correlate.rb +41 -226
- data/lib/cmdx/middlewares/timeout.rb +46 -185
- data/lib/cmdx/parameter.rb +120 -198
- data/lib/cmdx/parameter_evaluator.rb +231 -0
- data/lib/cmdx/parameter_inspector.rb +25 -56
- data/lib/cmdx/parameter_registry.rb +59 -84
- data/lib/cmdx/parameter_serializer.rb +23 -74
- data/lib/cmdx/railtie.rb +24 -107
- data/lib/cmdx/result.rb +254 -260
- data/lib/cmdx/result_ansi.rb +19 -85
- data/lib/cmdx/result_inspector.rb +27 -68
- data/lib/cmdx/result_logger.rb +18 -81
- data/lib/cmdx/result_serializer.rb +28 -132
- data/lib/cmdx/rspec/matchers.rb +28 -0
- data/lib/cmdx/rspec/result_matchers/be_executed.rb +42 -0
- data/lib/cmdx/rspec/result_matchers/be_failed_task.rb +94 -0
- data/lib/cmdx/rspec/result_matchers/be_skipped_task.rb +94 -0
- data/lib/cmdx/rspec/result_matchers/be_state_matchers.rb +59 -0
- data/lib/cmdx/rspec/result_matchers/be_status_matchers.rb +57 -0
- data/lib/cmdx/rspec/result_matchers/be_successful_task.rb +87 -0
- data/lib/cmdx/rspec/result_matchers/have_bad_outcome.rb +51 -0
- data/lib/cmdx/rspec/result_matchers/have_caused_failure.rb +58 -0
- data/lib/cmdx/rspec/result_matchers/have_chain_index.rb +59 -0
- data/lib/cmdx/rspec/result_matchers/have_context.rb +86 -0
- data/lib/cmdx/rspec/result_matchers/have_empty_metadata.rb +54 -0
- data/lib/cmdx/rspec/result_matchers/have_good_outcome.rb +52 -0
- data/lib/cmdx/rspec/result_matchers/have_metadata.rb +114 -0
- data/lib/cmdx/rspec/result_matchers/have_preserved_context.rb +66 -0
- data/lib/cmdx/rspec/result_matchers/have_received_thrown_failure.rb +64 -0
- data/lib/cmdx/rspec/result_matchers/have_runtime.rb +78 -0
- data/lib/cmdx/rspec/result_matchers/have_thrown_failure.rb +76 -0
- data/lib/cmdx/rspec/task_matchers/be_well_formed_task.rb +62 -0
- data/lib/cmdx/rspec/task_matchers/have_callback.rb +85 -0
- data/lib/cmdx/rspec/task_matchers/have_cmd_setting.rb +68 -0
- data/lib/cmdx/rspec/task_matchers/have_executed_callbacks.rb +92 -0
- data/lib/cmdx/rspec/task_matchers/have_middleware.rb +46 -0
- data/lib/cmdx/rspec/task_matchers/have_parameter.rb +181 -0
- data/lib/cmdx/task.rb +213 -425
- data/lib/cmdx/task_deprecator.rb +55 -0
- data/lib/cmdx/task_processor.rb +245 -0
- data/lib/cmdx/task_serializer.rb +22 -70
- data/lib/cmdx/utils/ansi_color.rb +13 -89
- data/lib/cmdx/utils/log_timestamp.rb +13 -42
- data/lib/cmdx/utils/monotonic_runtime.rb +13 -63
- data/lib/cmdx/utils/name_affix.rb +21 -71
- data/lib/cmdx/validator.rb +48 -0
- data/lib/cmdx/validator_registry.rb +86 -0
- data/lib/cmdx/validators/exclusion.rb +55 -94
- data/lib/cmdx/validators/format.rb +31 -85
- data/lib/cmdx/validators/inclusion.rb +65 -110
- data/lib/cmdx/validators/length.rb +117 -133
- data/lib/cmdx/validators/numeric.rb +123 -130
- data/lib/cmdx/validators/presence.rb +38 -79
- data/lib/cmdx/version.rb +1 -7
- data/lib/cmdx/workflow.rb +46 -339
- data/lib/cmdx.rb +1 -1
- data/lib/generators/cmdx/install_generator.rb +14 -31
- data/lib/generators/cmdx/task_generator.rb +39 -55
- data/lib/generators/cmdx/templates/install.rb +24 -6
- data/lib/generators/cmdx/workflow_generator.rb +41 -66
- data/lib/locales/ar.yml +0 -1
- data/lib/locales/cs.yml +0 -1
- data/lib/locales/da.yml +0 -1
- data/lib/locales/de.yml +0 -1
- data/lib/locales/el.yml +0 -1
- data/lib/locales/en.yml +0 -1
- data/lib/locales/es.yml +0 -1
- data/lib/locales/fi.yml +0 -1
- data/lib/locales/fr.yml +0 -1
- data/lib/locales/he.yml +0 -1
- data/lib/locales/hi.yml +0 -1
- data/lib/locales/it.yml +0 -1
- data/lib/locales/ja.yml +0 -1
- data/lib/locales/ko.yml +0 -1
- data/lib/locales/nl.yml +0 -1
- data/lib/locales/no.yml +0 -1
- data/lib/locales/pl.yml +0 -1
- data/lib/locales/pt.yml +0 -1
- data/lib/locales/ru.yml +0 -1
- data/lib/locales/sv.yml +0 -1
- data/lib/locales/th.yml +0 -1
- data/lib/locales/tr.yml +0 -1
- data/lib/locales/vi.yml +0 -1
- data/lib/locales/zh.yml +0 -1
- metadata +34 -8
- data/lib/cmdx/parameter_validator.rb +0 -81
- data/lib/cmdx/parameter_value.rb +0 -244
- data/lib/cmdx/parameters_inspector.rb +0 -72
- data/lib/cmdx/parameters_serializer.rb +0 -115
- data/lib/cmdx/rspec/result_matchers.rb +0 -917
- data/lib/cmdx/rspec/task_matchers.rb +0 -570
- data/lib/cmdx/validators/custom.rb +0 -102
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bd1613d4572cca134192d5c80bf3016b278b42a9a002d13fba66d2871da92fb
|
4
|
+
data.tar.gz: 1a174bc8b62bf3402e1e464b8252cdcd589731f8e81141723b8dbf3cf97f9f1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df70552dbf814fddff62cb3e1d593edf6bf5c33087d84154f36c794d430ee156b986998651383fa15b3b08e4d14d198d69020bb0dec7a13ffab43c75b1c57b02
|
7
|
+
data.tar.gz: 03ad35b1f6007e1afa3c41f3b63d44784566e78b9eb9b7f25f301d81165753af14b06bb8a6cfd67ea7e5bce02a03c311c338f61538d9d981d7de58d7f2b36f8f
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Add tests for the file in context.
|
2
|
+
- Expectations should be concise, non-repetitive, and realistic (how it would be used in the real world)
|
3
|
+
- Follow best practices and implementation
|
4
|
+
- Update any pre-existing specs to match stated rules
|
5
|
+
- New tests should be consistent with current `spec/cmdx` specs
|
6
|
+
- Use custom matchers available within `lib/cmdx/rspec`
|
7
|
+
- Use task helpers available within `spec/support/helpers`
|
8
|
+
- Use stubs to return predefined values for specific methods. Isolate the unit being tested, but avoid over-mocking; test real behavior when possible. (mocks should be used only when necessary)
|
9
|
+
- Ensure each test is independent; avoid shared state between tests.
|
10
|
+
- Use let and let! to define test data, ensuring minimal and necessary setup.
|
11
|
+
- Context block descriptions should start with the following words: `when`, `with`, `without`
|
12
|
+
- Organize tests logically using describe for classes/modules and context for different scenarios.
|
13
|
+
- Use subject to define the object under test when appropriate to avoid repetition.
|
14
|
+
- Ensure test file paths mirror the structure of the files being tested, but within the spec directory (e.g., lib/cmdx/task.rb → spec/cmdx/task_spec.rb).
|
15
|
+
- Use clear and descriptive names for describe, context, and it blocks.
|
16
|
+
- Prefer the expect syntax for assertions to improve readability.
|
17
|
+
- Keep test code concise; avoid unnecessary complexity or duplication.
|
18
|
+
- Tests must cover both typical cases and edge cases, including invalid inputs and error conditions.
|
19
|
+
- Consider all possible scenarios for each method or behavior and ensure they are tested.
|
20
|
+
- Verify all specs are passing
|
@@ -0,0 +1,8 @@
|
|
1
|
+
Add yardoc to the file in context.
|
2
|
+
- Do NOT include `CMDx` module level docs
|
3
|
+
- Module level docs description should NOT include `@example`
|
4
|
+
- Method level docs should include `@example`, `@return`, `@raise`
|
5
|
+
- Examples should be concise and realistic
|
6
|
+
- Follow best practices and implementation
|
7
|
+
- Update any pre-existing docs to match stated rules
|
8
|
+
- New documentation should be consistent with current `lib/cmdx` documentation
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -8,11 +8,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
8
8
|
## [TODO]
|
9
9
|
|
10
10
|
- Add table and pretty_table log formatters
|
11
|
-
-
|
12
|
-
- Refactor parameter modules and classes for more robust usages
|
11
|
+
- Refactor all `docs`
|
13
12
|
|
14
13
|
## [Unreleased]
|
15
14
|
|
15
|
+
### Added
|
16
|
+
- Added `CoercionRegistry` class for managing parameter coercions with support for custom type registration
|
17
|
+
- Added `ValidatorRegistry` class for managing parameter validators with support for custom validator registration
|
18
|
+
- Added `CallbackRegistry` class to take uninstantiated callback classes
|
19
|
+
- Added `Validator` and `Coercion` classes to build their respective handlers
|
20
|
+
|
21
|
+
### Changed
|
22
|
+
- Moved `Task::CALLBACKS` constant to `CallbackRegistry::TYPES`
|
23
|
+
- Updated `ParameterRegistry` class to not inherit from `Hash`
|
24
|
+
- Updated `MiddlewareRegistry` class to not inherit from `Hash`
|
25
|
+
- Updated `CallbackRegistry` class to not inherit from `Hash`
|
26
|
+
|
27
|
+
### Removed
|
28
|
+
- Removed task `register` class method
|
29
|
+
- Removed `Custom` validator since users can create and register a custom one
|
30
|
+
|
16
31
|
## [1.0.1] - 2025-07-07
|
17
32
|
|
18
33
|
### Added
|
data/README.md
CHANGED
data/docs/basics/call.md
CHANGED
@@ -103,7 +103,7 @@ task.context.notify_customer #=> true
|
|
103
103
|
task.result.state #=> "initialized"
|
104
104
|
|
105
105
|
# Manual execution
|
106
|
-
task.
|
106
|
+
task.process
|
107
107
|
task.result.success? #=> true/false
|
108
108
|
```
|
109
109
|
|
@@ -113,7 +113,7 @@ task.result.success? #=> true/false
|
|
113
113
|
|----------|----------|----------|
|
114
114
|
| `TaskClass.call(...)` | Standard execution | Simple, handles full lifecycle |
|
115
115
|
| `TaskClass.call!(...)` | Exception-based flow | Automatic fault raising |
|
116
|
-
| `TaskClass.new(...).
|
116
|
+
| `TaskClass.new(...).process` | Advanced scenarios | Full control, testing flexibility |
|
117
117
|
|
118
118
|
> [!NOTE]
|
119
119
|
> Direct instantiation gives you access to the task instance before and after execution, but you must call the execution method manually.
|
data/docs/basics/chain.md
CHANGED
@@ -195,7 +195,7 @@ The `CMDx::Middlewares::Correlate` middleware automatically manages correlation
|
|
195
195
|
```ruby
|
196
196
|
class ProcessOrderTask < CMDx::Task
|
197
197
|
# Apply correlate middleware globally or per-task
|
198
|
-
use CMDx::Middlewares::Correlate
|
198
|
+
use :middleware, CMDx::Middlewares::Correlate
|
199
199
|
|
200
200
|
def call
|
201
201
|
# Correlation is automatically managed
|
data/docs/callbacks.md
CHANGED
@@ -79,9 +79,7 @@ end
|
|
79
79
|
|
80
80
|
## Callback Classes
|
81
81
|
|
82
|
-
For complex callback logic or reusable patterns, you can create Callback classes similar to Middleware classes. Callback classes inherit from `CMDx::Callback` and implement the `call(task,
|
83
|
-
|
84
|
-
### Creating Callback Classes
|
82
|
+
For complex callback logic or reusable patterns, you can create Callback classes similar to Middleware classes. Callback classes inherit from `CMDx::Callback` and implement the `call(task, type)` method.
|
85
83
|
|
86
84
|
```ruby
|
87
85
|
class NotificationCallback < CMDx::Callback
|
@@ -89,8 +87,8 @@ class NotificationCallback < CMDx::Callback
|
|
89
87
|
@channels = Array(channels)
|
90
88
|
end
|
91
89
|
|
92
|
-
def call(task,
|
93
|
-
return unless
|
90
|
+
def call(task, type)
|
91
|
+
return unless type == :on_success
|
94
92
|
|
95
93
|
@channels.each do |channel|
|
96
94
|
NotificationService.send(channel, "Task #{task.class.name} completed")
|
@@ -99,37 +97,6 @@ class NotificationCallback < CMDx::Callback
|
|
99
97
|
end
|
100
98
|
```
|
101
99
|
|
102
|
-
### Registering Callback Classes
|
103
|
-
|
104
|
-
Callback classes can be registered using the `register` class method (recommended) or by directly calling the CallbackRegistry:
|
105
|
-
|
106
|
-
```ruby
|
107
|
-
class ProcessOrderTask < CMDx::Task
|
108
|
-
# Recommended: Use the register class method
|
109
|
-
register :before_execution, LoggingCallback.new(:debug)
|
110
|
-
register :on_success, NotificationCallback.new([:email, :slack])
|
111
|
-
register :on_failure, :alert_admin, if: :critical?
|
112
|
-
|
113
|
-
# Alternative: Direct CallbackRegistry access (less common)
|
114
|
-
# cmd_callbacks.register(:after_execution, CleanupCallback.new)
|
115
|
-
|
116
|
-
# Traditional callback definitions still work alongside Callback classes
|
117
|
-
before_validation :validate_order_data
|
118
|
-
on_success :update_metrics
|
119
|
-
|
120
|
-
def call
|
121
|
-
context.order = Order.find(order_id)
|
122
|
-
context.order.process!
|
123
|
-
end
|
124
|
-
|
125
|
-
private
|
126
|
-
|
127
|
-
def critical?
|
128
|
-
context.order.value > 10_000
|
129
|
-
end
|
130
|
-
end
|
131
|
-
```
|
132
|
-
|
133
100
|
## Available Callbacks
|
134
101
|
|
135
102
|
### Validation Callbacks
|
data/docs/configuration.md
CHANGED
@@ -10,6 +10,8 @@ CMDx provides a flexible configuration system that allows customization at both
|
|
10
10
|
- [Configuration Options](#configuration-options)
|
11
11
|
- [Global Middlewares](#global-middlewares)
|
12
12
|
- [Global Callbacks](#global-callbacks)
|
13
|
+
- [Global Coercions](#global-coercions)
|
14
|
+
- [Global Validators](#global-validators)
|
13
15
|
- [Task Settings](#task-settings)
|
14
16
|
- [Available Task Settings](#available-task-settings)
|
15
17
|
- [Workflow Configuration](#workflow-configuration)
|
@@ -21,7 +23,7 @@ CMDx provides a flexible configuration system that allows customization at both
|
|
21
23
|
|
22
24
|
- **Hierarchy** - Global → Task Settings → Runtime (each level overrides previous)
|
23
25
|
- **Global config** - Framework-wide defaults via `CMDx.configure`
|
24
|
-
- **Task settings** - Class-level overrides using `
|
26
|
+
- **Task settings** - Class-level overrides using `cmd_settings!`
|
25
27
|
- **Key options** - `task_halt`, `workflow_halt`, `logger`, `middlewares`, `callbacks`
|
26
28
|
- **Generator** - Use `rails g cmdx:install` to create configuration file
|
27
29
|
- **Inheritance** - Settings are inherited from parent classes
|
@@ -31,7 +33,7 @@ CMDx provides a flexible configuration system that allows customization at both
|
|
31
33
|
CMDx follows a three-tier configuration hierarchy:
|
32
34
|
|
33
35
|
1. **Global Configuration**: Framework-wide defaults
|
34
|
-
2. **Task Settings**: Class-level overrides via `
|
36
|
+
2. **Task Settings**: Class-level overrides via `cmd_settings!`
|
35
37
|
3. **Runtime Parameters**: Instance-specific overrides during execution
|
36
38
|
|
37
39
|
> [!IMPORTANT]
|
@@ -56,6 +58,8 @@ This creates `config/initializers/cmdx.rb` with default settings.
|
|
56
58
|
| `logger` | Logger | Line formatter | Logger instance for task execution logging |
|
57
59
|
| `middlewares` | MiddlewareRegistry | Empty registry | Global middleware registry applied to all tasks |
|
58
60
|
| `callbacks` | CallbackRegistry | Empty registry | Global callback registry applied to all tasks |
|
61
|
+
| `coercions` | CoercionRegistry | Built-in coercions | Global coercion registry for custom parameter types |
|
62
|
+
| `validators` | ValidatorRegistry | Built-in validators | Global validator registry for parameter validation |
|
59
63
|
|
60
64
|
### Global Middlewares
|
61
65
|
|
@@ -82,30 +86,70 @@ Configure callbacks that automatically apply to all tasks in your application:
|
|
82
86
|
CMDx.configure do |config|
|
83
87
|
# Add method callbacks
|
84
88
|
config.callbacks.register :before_execution, :log_task_start
|
85
|
-
config.callbacks.register :after_execution, :log_task_end
|
86
89
|
|
87
90
|
# Add callback instances
|
88
91
|
config.callbacks.register :on_success, NotificationCallback.new([:slack])
|
89
|
-
config.callbacks.register :on_failure, AlertCallback.new(severity: :critical)
|
90
92
|
|
91
93
|
# Add conditional callbacks
|
92
94
|
config.callbacks.register :on_failure, :page_admin, if: :production?
|
93
|
-
config.callbacks.register :before_validation, :skip_validation, unless: :validate_params?
|
94
95
|
|
95
96
|
# Add proc callbacks
|
96
|
-
config.callbacks.register :on_complete, proc { |task,
|
97
|
+
config.callbacks.register :on_complete, proc { |task, type|
|
97
98
|
Metrics.increment("task.#{task.class.name.underscore}.completed")
|
98
99
|
}
|
99
100
|
end
|
100
101
|
```
|
101
102
|
|
103
|
+
### Global Coercions
|
104
|
+
|
105
|
+
Configure custom coercions that automatically apply to all tasks in your application:
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
CMDx.configure do |config|
|
109
|
+
# Add custom coercion classes
|
110
|
+
config.coercions.register :money, MoneyCoercion
|
111
|
+
|
112
|
+
# Add complex coercions with options support
|
113
|
+
config.coercions.register :tags, proc { |value, options|
|
114
|
+
separator = options[:separator] || ','
|
115
|
+
max_tags = options[:max_tags] || 10
|
116
|
+
|
117
|
+
tags = value.to_s.split(separator).map(&:strip).reject(&:empty?)
|
118
|
+
tags = tags.first(max_tags) if max_tags
|
119
|
+
tags.uniq
|
120
|
+
}
|
121
|
+
end
|
122
|
+
```
|
123
|
+
|
124
|
+
### Global Validators
|
125
|
+
|
126
|
+
Configure validators that automatically apply to all tasks in your application:
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
CMDx.configure do |config|
|
130
|
+
# Add validator classes
|
131
|
+
config.validators.register :email, EmailValidator
|
132
|
+
|
133
|
+
# Add complex validators with options support
|
134
|
+
config.validators.register :phone, proc { |value, options|
|
135
|
+
country = options.dig(:phone, :country) || "US"
|
136
|
+
case country
|
137
|
+
when "US"
|
138
|
+
value.match?(/\A\d{3}-\d{3}-\d{4}\z/)
|
139
|
+
else
|
140
|
+
value.match?(/\A\+?\d{10,15}\z/)
|
141
|
+
end
|
142
|
+
}
|
143
|
+
end
|
144
|
+
```
|
145
|
+
|
102
146
|
## Task Settings
|
103
147
|
|
104
|
-
Override global configuration for specific tasks or workflows using `
|
148
|
+
Override global configuration for specific tasks or workflows using `cmd_settings!`:
|
105
149
|
|
106
150
|
```ruby
|
107
151
|
class ProcessPaymentTask < CMDx::Task
|
108
|
-
|
152
|
+
cmd_settings!(
|
109
153
|
task_halt: ["failed"], # Only halt on failures
|
110
154
|
tags: ["payments", "critical"], # Add logging tags
|
111
155
|
logger: Rails.logger, # Use Rails logger
|
@@ -137,7 +181,7 @@ Configure halt behavior for workflows:
|
|
137
181
|
```ruby
|
138
182
|
class OrderProcessingWorkflow < CMDx::Workflow
|
139
183
|
# Strict workflow - halt on any failure
|
140
|
-
|
184
|
+
cmd_settings!(workflow_halt: ["failed", "skipped"])
|
141
185
|
|
142
186
|
process ValidateOrderTask
|
143
187
|
process ChargePaymentTask
|
@@ -155,14 +199,16 @@ CMDx.configuration.logger #=> <Logger instance>
|
|
155
199
|
CMDx.configuration.task_halt #=> "failed"
|
156
200
|
CMDx.configuration.middlewares #=> <MiddlewareRegistry instance>
|
157
201
|
CMDx.configuration.callbacks #=> <CallbackRegistry instance>
|
202
|
+
CMDx.configuration.coercions #=> <CoercionRegistry instance>
|
203
|
+
CMDx.configuration.validators #=> <ValidatorRegistry instance>
|
158
204
|
|
159
205
|
# Task-specific settings
|
160
206
|
class AnalyzeDataTask < CMDx::Task
|
161
|
-
|
207
|
+
cmd_settings!(tags: ["analytics"])
|
162
208
|
|
163
209
|
def call
|
164
|
-
tags =
|
165
|
-
halt_statuses =
|
210
|
+
tags = cmd_setting(:tags) # Gets ["analytics"]
|
211
|
+
halt_statuses = cmd_setting(:task_halt) # Gets global default
|
166
212
|
end
|
167
213
|
end
|
168
214
|
```
|
@@ -187,7 +187,7 @@ CMDx faults have special handling in both call methods:
|
|
187
187
|
```ruby
|
188
188
|
class ProcessOrderWithHaltTask < CMDx::Task
|
189
189
|
# Configure to halt on failures
|
190
|
-
|
190
|
+
cmd_settings!(task_halt: [CMDx::Result::FAILED])
|
191
191
|
|
192
192
|
def call
|
193
193
|
fail!(reason: "This is a controlled failure")
|
@@ -213,7 +213,7 @@ Control which statuses raise exceptions using the `task_halt` setting:
|
|
213
213
|
```ruby
|
214
214
|
class ProcessUserOrderTask < CMDx::Task
|
215
215
|
# Only failed tasks raise exceptions on call!
|
216
|
-
|
216
|
+
cmd_settings!(task_halt: [CMDx::Result::FAILED])
|
217
217
|
|
218
218
|
def call
|
219
219
|
skip!(reason: "Order already processed") if already_processed?
|
@@ -223,7 +223,7 @@ end
|
|
223
223
|
|
224
224
|
class ValidateUserDataTask < CMDx::Task
|
225
225
|
# Both failed and skipped tasks raise exceptions
|
226
|
-
|
226
|
+
cmd_settings!(task_halt: [CMDx::Result::FAILED, CMDx::Result::SKIPPED])
|
227
227
|
|
228
228
|
def call
|
229
229
|
skip!(reason: "Validation not required") if skip_validation?
|
data/docs/logging.md
CHANGED
@@ -27,7 +27,7 @@ CMDx provides comprehensive automatic logging for task execution with structured
|
|
27
27
|
|
28
28
|
- **Automatic logging** - All task results logged after completion with structured data
|
29
29
|
- **8 formatters** - Standard (Line, Json, KeyValue, Logstash, Raw) and Stylized (Pretty variants)
|
30
|
-
- **Configuration** - Global via `CMDx.configure` or task-specific via `
|
30
|
+
- **Configuration** - Global via `CMDx.configure` or task-specific via `cmd_settings!`
|
31
31
|
- **Severity mapping** - Success=INFO, Skipped=WARN, Failed=ERROR
|
32
32
|
- **Rich metadata** - Includes runtime, chain_id, status, context, and failure chains
|
33
33
|
- **Manual logging** - Access `logger` within tasks for custom messages
|
@@ -93,7 +93,7 @@ Override logging settings for individual tasks:
|
|
93
93
|
|
94
94
|
```ruby
|
95
95
|
class SendEmailTask < CMDx::Task
|
96
|
-
|
96
|
+
cmd_settings!(
|
97
97
|
logger: Rails.logger,
|
98
98
|
log_formatter: CMDx::LogFormatters::Json.new,
|
99
99
|
log_level: Logger::WARN
|
@@ -106,7 +106,7 @@ end
|
|
106
106
|
|
107
107
|
# Base class with shared logging configuration
|
108
108
|
class ApplicationTask < CMDx::Task
|
109
|
-
|
109
|
+
cmd_settings!(
|
110
110
|
logger: Logger.new("log/tasks.log"),
|
111
111
|
log_formatter: CMDx::LogFormatters::Logstash.new,
|
112
112
|
log_level: Logger::INFO
|
@@ -179,7 +179,7 @@ class SlackLogFormatter
|
|
179
179
|
end
|
180
180
|
|
181
181
|
class SendNotificationTask < CMDx::Task
|
182
|
-
|
182
|
+
cmd_settings!(
|
183
183
|
logger: Logger.new("log/notifications.log", formatter: SlackLogFormatter.new)
|
184
184
|
)
|
185
185
|
end
|