servus 0.1.2 → 0.1.4
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/.yardopts +6 -0
- data/CHANGELOG.md +8 -1
- data/IDEAS.md +5 -0
- data/READme.md +147 -42
- data/Rakefile +33 -0
- data/builds/servus-0.1.2.gem +0 -0
- data/builds/servus-0.1.3.gem +0 -0
- data/builds/servus-0.1.4.gem +0 -0
- data/docs/core/1_overview.md +77 -0
- data/docs/core/2_architecture.md +92 -0
- data/docs/core/3_service_objects.md +121 -0
- data/docs/features/1_schema_validation.md +119 -0
- data/docs/features/2_error_handling.md +121 -0
- data/docs/features/3_async_execution.md +81 -0
- data/docs/features/4_logging.md +64 -0
- data/docs/guides/1_common_patterns.md +90 -0
- data/docs/guides/2_migration_guide.md +175 -0
- data/docs/integration/1_configuration.md +51 -0
- data/docs/integration/2_testing.md +164 -0
- data/docs/integration/3_rails_integration.md +99 -0
- data/docs/yard/Servus/Base.html +1645 -0
- data/docs/yard/Servus/Config.html +582 -0
- data/docs/yard/Servus/Extensions/Async/Call.html +400 -0
- data/docs/yard/Servus/Extensions/Async/Errors/AsyncError.html +140 -0
- data/docs/yard/Servus/Extensions/Async/Errors/JobEnqueueError.html +154 -0
- data/docs/yard/Servus/Extensions/Async/Errors/ServiceNotFoundError.html +154 -0
- data/docs/yard/Servus/Extensions/Async/Errors.html +128 -0
- data/docs/yard/Servus/Extensions/Async/Ext.html +119 -0
- data/docs/yard/Servus/Extensions/Async/Job.html +310 -0
- data/docs/yard/Servus/Extensions/Async.html +141 -0
- data/docs/yard/Servus/Extensions.html +117 -0
- data/docs/yard/Servus/Generators/ServiceGenerator.html +261 -0
- data/docs/yard/Servus/Generators.html +115 -0
- data/docs/yard/Servus/Helpers/ControllerHelpers.html +457 -0
- data/docs/yard/Servus/Helpers.html +115 -0
- data/docs/yard/Servus/Railtie.html +134 -0
- data/docs/yard/Servus/Support/Errors/AuthenticationError.html +287 -0
- data/docs/yard/Servus/Support/Errors/BadRequestError.html +283 -0
- data/docs/yard/Servus/Support/Errors/ForbiddenError.html +284 -0
- data/docs/yard/Servus/Support/Errors/InternalServerError.html +283 -0
- data/docs/yard/Servus/Support/Errors/NotFoundError.html +284 -0
- data/docs/yard/Servus/Support/Errors/ServiceError.html +489 -0
- data/docs/yard/Servus/Support/Errors/ServiceUnavailableError.html +290 -0
- data/docs/yard/Servus/Support/Errors/UnauthorizedError.html +200 -0
- data/docs/yard/Servus/Support/Errors/UnprocessableEntityError.html +288 -0
- data/docs/yard/Servus/Support/Errors/ValidationError.html +200 -0
- data/docs/yard/Servus/Support/Errors.html +140 -0
- data/docs/yard/Servus/Support/Logger.html +856 -0
- data/docs/yard/Servus/Support/Rescuer/BlockContext.html +585 -0
- data/docs/yard/Servus/Support/Rescuer/CallOverride.html +257 -0
- data/docs/yard/Servus/Support/Rescuer/ClassMethods.html +343 -0
- data/docs/yard/Servus/Support/Rescuer.html +267 -0
- data/docs/yard/Servus/Support/Response.html +574 -0
- data/docs/yard/Servus/Support/Validator.html +1150 -0
- data/docs/yard/Servus/Support.html +119 -0
- data/docs/yard/Servus/Testing/ExampleBuilders.html +523 -0
- data/docs/yard/Servus/Testing/ExampleExtractor.html +578 -0
- data/docs/yard/Servus/Testing.html +142 -0
- data/docs/yard/Servus.html +343 -0
- data/docs/yard/_index.html +535 -0
- data/docs/yard/class_list.html +54 -0
- data/docs/yard/css/common.css +1 -0
- data/docs/yard/css/full_list.css +58 -0
- data/docs/yard/css/style.css +503 -0
- data/docs/yard/file.1_common_patterns.html +154 -0
- data/docs/yard/file.1_configuration.html +115 -0
- data/docs/yard/file.1_overview.html +142 -0
- data/docs/yard/file.1_schema_validation.html +188 -0
- data/docs/yard/file.2_architecture.html +157 -0
- data/docs/yard/file.2_error_handling.html +190 -0
- data/docs/yard/file.2_migration_guide.html +242 -0
- data/docs/yard/file.2_testing.html +227 -0
- data/docs/yard/file.3_async_execution.html +145 -0
- data/docs/yard/file.3_rails_integration.html +160 -0
- data/docs/yard/file.3_service_objects.html +191 -0
- data/docs/yard/file.4_logging.html +135 -0
- data/docs/yard/file.ErrorHandling.html +190 -0
- data/docs/yard/file.READme.html +674 -0
- data/docs/yard/file.architecture.html +157 -0
- data/docs/yard/file.async_execution.html +145 -0
- data/docs/yard/file.common_patterns.html +154 -0
- data/docs/yard/file.configuration.html +115 -0
- data/docs/yard/file.error_handling.html +190 -0
- data/docs/yard/file.logging.html +135 -0
- data/docs/yard/file.migration_guide.html +242 -0
- data/docs/yard/file.overview.html +142 -0
- data/docs/yard/file.rails_integration.html +160 -0
- data/docs/yard/file.schema_validation.html +188 -0
- data/docs/yard/file.service_objects.html +191 -0
- data/docs/yard/file.testing.html +227 -0
- data/docs/yard/file_list.html +119 -0
- data/docs/yard/frames.html +22 -0
- data/docs/yard/index.html +674 -0
- data/docs/yard/js/app.js +344 -0
- data/docs/yard/js/full_list.js +242 -0
- data/docs/yard/js/jquery.js +4 -0
- data/docs/yard/method_list.html +542 -0
- data/docs/yard/top-level-namespace.html +110 -0
- data/lib/generators/servus/service/service_generator.rb +64 -1
- data/lib/generators/servus/service/templates/service.rb.erb +1 -1
- data/lib/servus/base.rb +258 -57
- data/lib/servus/config.rb +58 -12
- data/lib/servus/extensions/async/call.rb +50 -18
- data/lib/servus/extensions/async/errors.rb +23 -3
- data/lib/servus/extensions/async/ext.rb +10 -2
- data/lib/servus/extensions/async/job.rb +32 -11
- data/lib/servus/helpers/controller_helpers.rb +73 -37
- data/lib/servus/support/errors.rb +135 -45
- data/lib/servus/support/rescuer.rb +189 -36
- data/lib/servus/support/response.rb +49 -7
- data/lib/servus/support/validator.rb +120 -19
- data/lib/servus/testing/example_builders.rb +133 -0
- data/lib/servus/testing/example_extractor.rb +309 -0
- data/lib/servus/testing.rb +17 -0
- data/lib/servus/version.rb +1 -1
- metadata +118 -19
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>
|
|
7
|
+
File: Core / Architecture
|
|
8
|
+
|
|
9
|
+
— Servus | Service Object Framework
|
|
10
|
+
|
|
11
|
+
</title>
|
|
12
|
+
|
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" />
|
|
14
|
+
|
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" />
|
|
16
|
+
|
|
17
|
+
<script type="text/javascript">
|
|
18
|
+
pathId = "architecture";
|
|
19
|
+
relpath = '';
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
|
24
|
+
|
|
25
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
</head>
|
|
29
|
+
<body>
|
|
30
|
+
<div class="nav_wrap">
|
|
31
|
+
<iframe id="nav" src="file_list.html?1"></iframe>
|
|
32
|
+
<div id="resizer"></div>
|
|
33
|
+
</div>
|
|
34
|
+
|
|
35
|
+
<div id="main" tabindex="-1">
|
|
36
|
+
<div id="header">
|
|
37
|
+
<div id="menu">
|
|
38
|
+
|
|
39
|
+
<a href="_index.html">Index</a> »
|
|
40
|
+
<span class="title">File: Core / Architecture</span>
|
|
41
|
+
|
|
42
|
+
</div>
|
|
43
|
+
|
|
44
|
+
<div id="search">
|
|
45
|
+
|
|
46
|
+
<a class="full_list_link" id="class_list_link"
|
|
47
|
+
href="class_list.html">
|
|
48
|
+
|
|
49
|
+
<svg width="24" height="24">
|
|
50
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
|
51
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
|
52
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
|
53
|
+
</svg>
|
|
54
|
+
</a>
|
|
55
|
+
|
|
56
|
+
</div>
|
|
57
|
+
<div class="clear"></div>
|
|
58
|
+
</div>
|
|
59
|
+
|
|
60
|
+
<div id="content"><div id='filecontents'><h1 id="architecture">Architecture</h1>
|
|
61
|
+
|
|
62
|
+
<p>Servus wraps service execution with automatic validation, logging, and error handling. When you call <code>Service.call(**args)</code>, the framework orchestrates these concerns transparently.</p>
|
|
63
|
+
|
|
64
|
+
<h2 id="execution-flow">Execution Flow</h2>
|
|
65
|
+
|
|
66
|
+
<pre class="code ruby"><code class="ruby"><span class='const'>Arguments</span> <span class='id identifier rubyid_→'>→</span> <span class='const'>Validation</span> <span class='id identifier rubyid_→'>→</span> <span class='const'>Service</span><span class='comment'>#call → Result Validation → Logging → Response
|
|
67
|
+
</span> <span class='id identifier rubyid_↓'>↓</span> <span class='id identifier rubyid_↓'>↓</span> <span class='id identifier rubyid_↓'>↓</span>
|
|
68
|
+
<span class='const'>ValidationError</span> <span class='const'>ValidationError</span> <span class='const'>Benchmark</span>
|
|
69
|
+
</code></pre>
|
|
70
|
+
|
|
71
|
+
<p>The framework intercepts the <code>.call</code> class method to inject cross-cutting concerns before and after your business logic runs. Your <code>call</code> instance method contains only business logic - validation, logging, and timing happen automatically.</p>
|
|
72
|
+
|
|
73
|
+
<h2 id="core-components">Core Components</h2>
|
|
74
|
+
|
|
75
|
+
<p><strong>Servus::Base</strong> (<code>lib/servus/base.rb</code>): Foundation class providing <code>.call()</code> orchestration and response helpers (<code>success</code>, <code>failure</code>, <code>error!</code>)</p>
|
|
76
|
+
|
|
77
|
+
<p><strong>Support::Response</strong> (<code>lib/servus/support/response.rb</code>): Immutable result object with <code>success?</code>, <code>data</code>, and <code>error</code> attributes</p>
|
|
78
|
+
|
|
79
|
+
<p><strong>Support::Validator</strong> (<code>lib/servus/support/validator.rb</code>): JSON Schema validation for arguments (before execution) and results (after execution). Schemas are cached after first load.</p>
|
|
80
|
+
|
|
81
|
+
<p><strong>Support::Logger</strong> (<code>lib/servus/support/logger.rb</code>): Automatic logging at DEBUG (calls with args), INFO (success), WARN (failures), ERROR (exceptions)</p>
|
|
82
|
+
|
|
83
|
+
<p><strong>Support::Rescuer</strong> (<code>lib/servus/support/rescuer.rb</code>): Declarative exception handling via <code>rescue_from</code> class method</p>
|
|
84
|
+
|
|
85
|
+
<p><strong>Support::Errors</strong> (<code>lib/servus/support/errors.rb</code>): HTTP-aligned error hierarchy (ServiceError, NotFoundError, ValidationError, etc.)</p>
|
|
86
|
+
|
|
87
|
+
<h2 id="extension-points">Extension Points</h2>
|
|
88
|
+
|
|
89
|
+
<h3 id="schema-validation">Schema Validation</h3>
|
|
90
|
+
|
|
91
|
+
<p>Use the <code>schema</code> DSL method to define JSON Schema validation for arguments and results:</p>
|
|
92
|
+
|
|
93
|
+
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>Service</span> <span class='op'><</span> <span class='const'><span class='object_link'><a href="Servus.html" title="Servus (module)">Servus</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Servus/Base.html" title="Servus::Base (class)">Base</a></span></span>
|
|
94
|
+
<span class='id identifier rubyid_schema'>schema</span><span class='lparen'>(</span>
|
|
95
|
+
<span class='label'>arguments:</span> <span class='lbrace'>{</span> <span class='label'>type:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>object</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>required:</span> <span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>user_id</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span> <span class='rbrace'>}</span><span class='comma'>,</span>
|
|
96
|
+
<span class='label'>result:</span> <span class='lbrace'>{</span> <span class='label'>type:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>object</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>required:</span> <span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>user</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span> <span class='rbrace'>}</span>
|
|
97
|
+
<span class='rparen'>)</span>
|
|
98
|
+
<span class='kw'>end</span>
|
|
99
|
+
</code></pre>
|
|
100
|
+
|
|
101
|
+
<h3 id="declarative-error-handling">Declarative Error Handling</h3>
|
|
102
|
+
|
|
103
|
+
<p>Use <code>rescue_from</code> to convert exceptions into failures. Provide a custom error type or use a block for custom handling.</p>
|
|
104
|
+
|
|
105
|
+
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>Service</span> <span class='op'><</span> <span class='const'><span class='object_link'><a href="Servus.html" title="Servus (module)">Servus</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Servus/Base.html" title="Servus::Base (class)">Base</a></span></span>
|
|
106
|
+
<span class='comment'># Default error type
|
|
107
|
+
</span> <span class='id identifier rubyid_rescue_from'>rescue_from</span> <span class='const'>Net</span><span class='op'>::</span><span class='const'>HTTPError</span><span class='comma'>,</span> <span class='const'>Timeout</span><span class='op'>::</span><span class='const'>Error</span><span class='comma'>,</span> <span class='label'>use:</span> <span class='const'>ServiceUnavailableError</span>
|
|
108
|
+
|
|
109
|
+
<span class='comment'># Custom handling with block
|
|
110
|
+
</span> <span class='id identifier rubyid_rescue_from'>rescue_from</span> <span class='const'>ActiveRecord</span><span class='op'>::</span><span class='const'>RecordInvalid</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_exception'>exception</span><span class='op'>|</span>
|
|
111
|
+
<span class='id identifier rubyid_failure'>failure</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Validation failed: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_exception'>exception</span><span class='period'>.</span><span class='id identifier rubyid_message'>message</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>type:</span> <span class='const'>ValidationError</span><span class='rparen'>)</span>
|
|
112
|
+
<span class='kw'>end</span>
|
|
113
|
+
<span class='kw'>end</span>
|
|
114
|
+
</code></pre>
|
|
115
|
+
|
|
116
|
+
<h3 id="support-classes">Support Classes</h3>
|
|
117
|
+
|
|
118
|
+
<p>Create helper classes in <code>app/services/service_name/support/*.rb</code>. These are namespaced to your service.</p>
|
|
119
|
+
|
|
120
|
+
<pre class="code ruby"><code class="ruby">app/services/process_payment/
|
|
121
|
+
├── service.rb
|
|
122
|
+
└── support/
|
|
123
|
+
├── payment_gateway.rb
|
|
124
|
+
└── receipt_formatter.rb
|
|
125
|
+
</code></pre>
|
|
126
|
+
|
|
127
|
+
<h2 id="async-execution">Async Execution</h2>
|
|
128
|
+
|
|
129
|
+
<p><code>Service.call_async(**args)</code> enqueues execution via ActiveJob. The service runs identically whether called sync or async.</p>
|
|
130
|
+
|
|
131
|
+
<pre class="code ruby"><code class="ruby"><span class='const'>ProcessPayment</span><span class='op'>::</span><span class='const'>Service</span><span class='period'>.</span><span class='id identifier rubyid_call_async'>call_async</span><span class='lparen'>(</span>
|
|
132
|
+
<span class='label'>user_id:</span> <span class='int'>1</span><span class='comma'>,</span>
|
|
133
|
+
<span class='label'>amount:</span> <span class='int'>50</span><span class='comma'>,</span>
|
|
134
|
+
<span class='label'>queue:</span> <span class='symbol'>:critical</span><span class='comma'>,</span>
|
|
135
|
+
<span class='label'>wait:</span> <span class='int'>5</span><span class='period'>.</span><span class='id identifier rubyid_minutes'>minutes</span>
|
|
136
|
+
<span class='rparen'>)</span>
|
|
137
|
+
</code></pre>
|
|
138
|
+
|
|
139
|
+
<h2 id="performance">Performance</h2>
|
|
140
|
+
|
|
141
|
+
<ul>
|
|
142
|
+
<li>Schema loading: Cached per class after first use</li>
|
|
143
|
+
<li>Validation overhead: ~1-5ms when schemas defined</li>
|
|
144
|
+
<li>Logging overhead: ~0.1ms per call</li>
|
|
145
|
+
<li>Total framework overhead: < 10ms per service call</li>
|
|
146
|
+
</ul>
|
|
147
|
+
</div></div>
|
|
148
|
+
|
|
149
|
+
<div id="footer">
|
|
150
|
+
Generated on Fri Nov 21 00:28:16 2025 by
|
|
151
|
+
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
152
|
+
0.9.37 (ruby-3.4.4).
|
|
153
|
+
</div>
|
|
154
|
+
|
|
155
|
+
</div>
|
|
156
|
+
</body>
|
|
157
|
+
</html>
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>
|
|
7
|
+
File: Features / Async Execution
|
|
8
|
+
|
|
9
|
+
— Servus | Service Object Framework
|
|
10
|
+
|
|
11
|
+
</title>
|
|
12
|
+
|
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" />
|
|
14
|
+
|
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" />
|
|
16
|
+
|
|
17
|
+
<script type="text/javascript">
|
|
18
|
+
pathId = "async_execution";
|
|
19
|
+
relpath = '';
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
|
24
|
+
|
|
25
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
</head>
|
|
29
|
+
<body>
|
|
30
|
+
<div class="nav_wrap">
|
|
31
|
+
<iframe id="nav" src="file_list.html?1"></iframe>
|
|
32
|
+
<div id="resizer"></div>
|
|
33
|
+
</div>
|
|
34
|
+
|
|
35
|
+
<div id="main" tabindex="-1">
|
|
36
|
+
<div id="header">
|
|
37
|
+
<div id="menu">
|
|
38
|
+
|
|
39
|
+
<a href="_index.html">Index</a> »
|
|
40
|
+
<span class="title">File: Features / Async Execution</span>
|
|
41
|
+
|
|
42
|
+
</div>
|
|
43
|
+
|
|
44
|
+
<div id="search">
|
|
45
|
+
|
|
46
|
+
<a class="full_list_link" id="class_list_link"
|
|
47
|
+
href="class_list.html">
|
|
48
|
+
|
|
49
|
+
<svg width="24" height="24">
|
|
50
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
|
51
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
|
52
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
|
53
|
+
</svg>
|
|
54
|
+
</a>
|
|
55
|
+
|
|
56
|
+
</div>
|
|
57
|
+
<div class="clear"></div>
|
|
58
|
+
</div>
|
|
59
|
+
|
|
60
|
+
<div id="content"><div id='filecontents'><h1 id="async-execution">Async Execution</h1>
|
|
61
|
+
|
|
62
|
+
<p>Servus provides asynchronous execution via ActiveJob. Services run identically whether called sync or async - they're unaware of execution context.</p>
|
|
63
|
+
|
|
64
|
+
<h2 id="usage">Usage</h2>
|
|
65
|
+
|
|
66
|
+
<p>Call <code>.call_async(**args)</code> instead of <code>.call(**args)</code> to execute in the background. The service is enqueued immediately and executed by a worker.</p>
|
|
67
|
+
|
|
68
|
+
<pre class="code ruby"><code class="ruby"><span class='comment'># Synchronous
|
|
69
|
+
</span><span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='const'>ProcessReport</span><span class='op'>::</span><span class='const'>Service</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span><span class='lparen'>(</span><span class='label'>user_id:</span> <span class='id identifier rubyid_user'>user</span><span class='period'>.</span><span class='id identifier rubyid_id'>id</span><span class='comma'>,</span> <span class='label'>report_type:</span> <span class='symbol'>:monthly</span><span class='rparen'>)</span>
|
|
70
|
+
<span class='id identifier rubyid_result'>result</span><span class='period'>.</span><span class='id identifier rubyid_data'>data</span><span class='lbracket'>[</span><span class='symbol'>:report</span><span class='rbracket'>]</span> <span class='comment'># Available immediately
|
|
71
|
+
</span>
|
|
72
|
+
<span class='comment'># Asynchronous
|
|
73
|
+
</span><span class='const'>ProcessReport</span><span class='op'>::</span><span class='const'>Service</span><span class='period'>.</span><span class='id identifier rubyid_call_async'>call_async</span><span class='lparen'>(</span><span class='label'>user_id:</span> <span class='id identifier rubyid_user'>user</span><span class='period'>.</span><span class='id identifier rubyid_id'>id</span><span class='comma'>,</span> <span class='label'>report_type:</span> <span class='symbol'>:monthly</span><span class='rparen'>)</span>
|
|
74
|
+
<span class='comment'># Returns true if enqueued successfully
|
|
75
|
+
</span><span class='comment'># Result not available (service hasn't run yet)
|
|
76
|
+
</span></code></pre>
|
|
77
|
+
|
|
78
|
+
<p>Services must accept JSON-serializable arguments for async execution (primitives, hashes, arrays, ActiveRecord objects via GlobalID). Complex objects like Procs won't work.</p>
|
|
79
|
+
|
|
80
|
+
<h2 id="queue-and-scheduling-options">Queue and Scheduling Options</h2>
|
|
81
|
+
|
|
82
|
+
<p>Pass ActiveJob options to control execution:</p>
|
|
83
|
+
|
|
84
|
+
<pre class="code ruby"><code class="ruby"><span class='const'>ProcessReport</span><span class='op'>::</span><span class='const'>Service</span><span class='period'>.</span><span class='id identifier rubyid_call_async'>call_async</span><span class='lparen'>(</span>
|
|
85
|
+
<span class='label'>user_id:</span> <span class='id identifier rubyid_user'>user</span><span class='period'>.</span><span class='id identifier rubyid_id'>id</span><span class='comma'>,</span>
|
|
86
|
+
<span class='label'>queue:</span> <span class='symbol'>:critical</span><span class='comma'>,</span> <span class='comment'># Specify queue
|
|
87
|
+
</span> <span class='label'>priority:</span> <span class='int'>10</span><span class='comma'>,</span> <span class='comment'># Higher priority
|
|
88
|
+
</span> <span class='label'>wait:</span> <span class='int'>5</span><span class='period'>.</span><span class='id identifier rubyid_minutes'>minutes</span> <span class='comment'># Delay execution
|
|
89
|
+
</span><span class='rparen'>)</span>
|
|
90
|
+
</code></pre>
|
|
91
|
+
|
|
92
|
+
<h2 id="result-handling">Result Handling</h2>
|
|
93
|
+
|
|
94
|
+
<p>Async services can't return results to callers (the service hasn't executed yet). If you need results, implement persistence in the service:</p>
|
|
95
|
+
|
|
96
|
+
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>GenerateReport</span><span class='op'>::</span><span class='const'>Service</span> <span class='op'><</span> <span class='const'><span class='object_link'><a href="Servus.html" title="Servus (module)">Servus</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Servus/Base.html" title="Servus::Base (class)">Base</a></span></span>
|
|
97
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_call'>call</span>
|
|
98
|
+
<span class='id identifier rubyid_report_data'>report_data</span> <span class='op'>=</span> <span class='id identifier rubyid_generate_report'>generate_report</span>
|
|
99
|
+
|
|
100
|
+
<span class='comment'># Persist result
|
|
101
|
+
</span> <span class='const'>Report</span><span class='period'>.</span><span class='id identifier rubyid_create!'>create!</span><span class='lparen'>(</span>
|
|
102
|
+
<span class='label'>user_id:</span> <span class='ivar'>@user_id</span><span class='comma'>,</span>
|
|
103
|
+
<span class='label'>data:</span> <span class='id identifier rubyid_report_data'>report_data</span><span class='comma'>,</span>
|
|
104
|
+
<span class='label'>status:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>completed</span><span class='tstring_end'>'</span></span>
|
|
105
|
+
<span class='rparen'>)</span>
|
|
106
|
+
|
|
107
|
+
<span class='comment'># Optionally notify user
|
|
108
|
+
</span> <span class='const'>UserMailer</span><span class='period'>.</span><span class='id identifier rubyid_report_ready'>report_ready</span><span class='lparen'>(</span><span class='ivar'>@user_id</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_deliver_now'>deliver_now</span>
|
|
109
|
+
|
|
110
|
+
<span class='id identifier rubyid_success'>success</span><span class='lparen'>(</span><span class='label'>data:</span> <span class='id identifier rubyid_report_data'>report_data</span><span class='rparen'>)</span>
|
|
111
|
+
<span class='kw'>end</span>
|
|
112
|
+
<span class='kw'>end</span>
|
|
113
|
+
|
|
114
|
+
<span class='comment'># Controller creates placeholder, service updates it
|
|
115
|
+
</span><span class='id identifier rubyid_report'>report</span> <span class='op'>=</span> <span class='const'>Report</span><span class='period'>.</span><span class='id identifier rubyid_create!'>create!</span><span class='lparen'>(</span><span class='label'>user_id:</span> <span class='id identifier rubyid_user'>user</span><span class='period'>.</span><span class='id identifier rubyid_id'>id</span><span class='comma'>,</span> <span class='label'>status:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>pending</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
|
116
|
+
<span class='const'>GenerateReport</span><span class='op'>::</span><span class='const'>Service</span><span class='period'>.</span><span class='id identifier rubyid_call_async'>call_async</span><span class='lparen'>(</span><span class='label'>user_id:</span> <span class='id identifier rubyid_user'>user</span><span class='period'>.</span><span class='id identifier rubyid_id'>id</span><span class='comma'>,</span> <span class='label'>report_id:</span> <span class='id identifier rubyid_report'>report</span><span class='period'>.</span><span class='id identifier rubyid_id'>id</span><span class='rparen'>)</span>
|
|
117
|
+
</code></pre>
|
|
118
|
+
|
|
119
|
+
<h2 id="error-handling">Error Handling</h2>
|
|
120
|
+
|
|
121
|
+
<p>Failures (business logic) don't trigger retries - the job completes successfully but returns a failure Response.</p>
|
|
122
|
+
|
|
123
|
+
<p>Exceptions (system errors) trigger ActiveJob retry logic. Use <code>rescue_from</code> to convert transient errors into exceptions:</p>
|
|
124
|
+
|
|
125
|
+
<pre class="code ruby"><code class="ruby">class Service < Servus::Base
|
|
126
|
+
rescue_from Net::HTTPError, Timeout::Error use: ServiceUnavailableError
|
|
127
|
+
end
|
|
128
|
+
</code></pre>
|
|
129
|
+
|
|
130
|
+
<h2 id="when-to-use-async">When to Use Async</h2>
|
|
131
|
+
|
|
132
|
+
<p><strong>Good candidates</strong>: Email sending, report generation, data imports, long-running API calls, cleanup tasks</p>
|
|
133
|
+
|
|
134
|
+
<p><strong>Poor candidates</strong>: Operations requiring immediate feedback, fast operations (<100ms), critical path operations where user waits for result</p>
|
|
135
|
+
</div></div>
|
|
136
|
+
|
|
137
|
+
<div id="footer">
|
|
138
|
+
Generated on Fri Nov 21 00:30:04 2025 by
|
|
139
|
+
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
140
|
+
0.9.37 (ruby-3.4.4).
|
|
141
|
+
</div>
|
|
142
|
+
|
|
143
|
+
</div>
|
|
144
|
+
</body>
|
|
145
|
+
</html>
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>
|
|
7
|
+
File: Guides / Common Patterns
|
|
8
|
+
|
|
9
|
+
— Servus | Service Object Framework
|
|
10
|
+
|
|
11
|
+
</title>
|
|
12
|
+
|
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" />
|
|
14
|
+
|
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" />
|
|
16
|
+
|
|
17
|
+
<script type="text/javascript">
|
|
18
|
+
pathId = "common_patterns";
|
|
19
|
+
relpath = '';
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
|
24
|
+
|
|
25
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
</head>
|
|
29
|
+
<body>
|
|
30
|
+
<div class="nav_wrap">
|
|
31
|
+
<iframe id="nav" src="file_list.html?1"></iframe>
|
|
32
|
+
<div id="resizer"></div>
|
|
33
|
+
</div>
|
|
34
|
+
|
|
35
|
+
<div id="main" tabindex="-1">
|
|
36
|
+
<div id="header">
|
|
37
|
+
<div id="menu">
|
|
38
|
+
|
|
39
|
+
<a href="_index.html">Index</a> »
|
|
40
|
+
<span class="title">File: Guides / Common Patterns</span>
|
|
41
|
+
|
|
42
|
+
</div>
|
|
43
|
+
|
|
44
|
+
<div id="search">
|
|
45
|
+
|
|
46
|
+
<a class="full_list_link" id="class_list_link"
|
|
47
|
+
href="class_list.html">
|
|
48
|
+
|
|
49
|
+
<svg width="24" height="24">
|
|
50
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
|
51
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
|
52
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
|
53
|
+
</svg>
|
|
54
|
+
</a>
|
|
55
|
+
|
|
56
|
+
</div>
|
|
57
|
+
<div class="clear"></div>
|
|
58
|
+
</div>
|
|
59
|
+
|
|
60
|
+
<div id="content"><div id='filecontents'><h1 id="common-patterns">Common Patterns</h1>
|
|
61
|
+
|
|
62
|
+
<p>Common architectural patterns for using Servus effectively.</p>
|
|
63
|
+
|
|
64
|
+
<h2 id="parent-child-services">Parent-Child Services</h2>
|
|
65
|
+
|
|
66
|
+
<p>When one service orchestrates multiple sub-operations, decide on transaction boundaries and error propagation.</p>
|
|
67
|
+
|
|
68
|
+
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>Orders</span><span class='op'>::</span><span class='const'>Checkout</span><span class='op'>::</span><span class='const'>Service</span> <span class='op'><</span> <span class='const'><span class='object_link'><a href="Servus.html" title="Servus (module)">Servus</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Servus/Base.html" title="Servus::Base (class)">Base</a></span></span>
|
|
69
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_call'>call</span>
|
|
70
|
+
<span class='const'>ActiveRecord</span><span class='op'>::</span><span class='const'>Base</span><span class='period'>.</span><span class='id identifier rubyid_transaction'>transaction</span> <span class='kw'>do</span>
|
|
71
|
+
<span class='comment'># Create order
|
|
72
|
+
</span> <span class='id identifier rubyid_order_result'>order_result</span> <span class='op'>=</span> <span class='const'>Orders</span><span class='op'>::</span><span class='const'>Create</span><span class='op'>::</span><span class='const'>Service</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span><span class='lparen'>(</span><span class='id identifier rubyid_order_params'>order_params</span><span class='rparen'>)</span>
|
|
73
|
+
<span class='kw'>return</span> <span class='id identifier rubyid_order_result'>order_result</span> <span class='kw'>unless</span> <span class='id identifier rubyid_order_result'>order_result</span><span class='period'>.</span><span class='id identifier rubyid_success?'>success?</span>
|
|
74
|
+
|
|
75
|
+
<span class='comment'># Charge payment
|
|
76
|
+
</span> <span class='id identifier rubyid_payment_result'>payment_result</span> <span class='op'>=</span> <span class='const'>Payments</span><span class='op'>::</span><span class='const'>Charge</span><span class='op'>::</span><span class='const'>Service</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span><span class='lparen'>(</span>
|
|
77
|
+
<span class='label'>user_id:</span> <span class='ivar'>@user_id</span><span class='comma'>,</span>
|
|
78
|
+
<span class='label'>amount:</span> <span class='id identifier rubyid_order_result'>order_result</span><span class='period'>.</span><span class='id identifier rubyid_data'>data</span><span class='lbracket'>[</span><span class='symbol'>:order</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_total'>total</span>
|
|
79
|
+
<span class='rparen'>)</span>
|
|
80
|
+
<span class='kw'>return</span> <span class='id identifier rubyid_payment_result'>payment_result</span> <span class='kw'>unless</span> <span class='id identifier rubyid_payment_result'>payment_result</span><span class='period'>.</span><span class='id identifier rubyid_success?'>success?</span>
|
|
81
|
+
|
|
82
|
+
<span class='comment'># Update inventory
|
|
83
|
+
</span> <span class='id identifier rubyid_inventory_result'>inventory_result</span> <span class='op'>=</span> <span class='const'>Inventory</span><span class='op'>::</span><span class='const'>Reserve</span><span class='op'>::</span><span class='const'>Service</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span><span class='lparen'>(</span>
|
|
84
|
+
<span class='label'>order_id:</span> <span class='id identifier rubyid_order_result'>order_result</span><span class='period'>.</span><span class='id identifier rubyid_data'>data</span><span class='lbracket'>[</span><span class='symbol'>:order</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_id'>id</span>
|
|
85
|
+
<span class='rparen'>)</span>
|
|
86
|
+
<span class='kw'>return</span> <span class='id identifier rubyid_inventory_result'>inventory_result</span> <span class='kw'>unless</span> <span class='id identifier rubyid_inventory_result'>inventory_result</span><span class='period'>.</span><span class='id identifier rubyid_success?'>success?</span>
|
|
87
|
+
|
|
88
|
+
<span class='id identifier rubyid_success'>success</span><span class='lparen'>(</span><span class='label'>order:</span> <span class='id identifier rubyid_order_result'>order_result</span><span class='period'>.</span><span class='id identifier rubyid_data'>data</span><span class='lbracket'>[</span><span class='symbol'>:order</span><span class='rbracket'>]</span><span class='rparen'>)</span>
|
|
89
|
+
<span class='kw'>end</span>
|
|
90
|
+
<span class='kw'>end</span>
|
|
91
|
+
<span class='kw'>end</span>
|
|
92
|
+
</code></pre>
|
|
93
|
+
|
|
94
|
+
<p><strong>Use parent transaction when</strong>: All children must succeed or all roll back (atomic operation)</p>
|
|
95
|
+
|
|
96
|
+
<p><strong>Use child transactions when</strong>: Children can succeed independently (partial success acceptable)</p>
|
|
97
|
+
|
|
98
|
+
<h2 id="async-with-result-persistence">Async with Result Persistence</h2>
|
|
99
|
+
|
|
100
|
+
<p>Store async results in database for later retrieval:</p>
|
|
101
|
+
|
|
102
|
+
<pre class="code ruby"><code class="ruby"><span class='comment'># Controller creates placeholder
|
|
103
|
+
</span><span class='id identifier rubyid_report'>report</span> <span class='op'>=</span> <span class='const'>Report</span><span class='period'>.</span><span class='id identifier rubyid_create!'>create!</span><span class='lparen'>(</span><span class='label'>user_id:</span> <span class='id identifier rubyid_user'>user</span><span class='period'>.</span><span class='id identifier rubyid_id'>id</span><span class='comma'>,</span> <span class='label'>status:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>pending</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
|
104
|
+
<span class='const'>GenerateReport</span><span class='op'>::</span><span class='const'>Service</span><span class='period'>.</span><span class='id identifier rubyid_call_async'>call_async</span><span class='lparen'>(</span><span class='label'>report_id:</span> <span class='id identifier rubyid_report'>report</span><span class='period'>.</span><span class='id identifier rubyid_id'>id</span><span class='rparen'>)</span>
|
|
105
|
+
|
|
106
|
+
<span class='comment'># Service updates record
|
|
107
|
+
</span><span class='kw'>class</span> <span class='const'>GenerateReport</span><span class='op'>::</span><span class='const'>Service</span> <span class='op'><</span> <span class='const'><span class='object_link'><a href="Servus.html" title="Servus (module)">Servus</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Servus/Base.html" title="Servus::Base (class)">Base</a></span></span>
|
|
108
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_call'>call</span>
|
|
109
|
+
<span class='id identifier rubyid_report'>report</span> <span class='op'>=</span> <span class='const'>Report</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span><span class='lparen'>(</span><span class='ivar'>@report_id</span><span class='rparen'>)</span>
|
|
110
|
+
<span class='id identifier rubyid_data'>data</span> <span class='op'>=</span> <span class='id identifier rubyid_generate_report_data'>generate_report_data</span>
|
|
111
|
+
|
|
112
|
+
<span class='id identifier rubyid_report'>report</span><span class='period'>.</span><span class='id identifier rubyid_update!'>update!</span><span class='lparen'>(</span><span class='label'>data:</span> <span class='id identifier rubyid_data'>data</span><span class='comma'>,</span> <span class='label'>status:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>completed</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
|
113
|
+
<span class='id identifier rubyid_success'>success</span><span class='lparen'>(</span><span class='label'>report:</span> <span class='id identifier rubyid_report'>report</span><span class='rparen'>)</span>
|
|
114
|
+
<span class='kw'>end</span>
|
|
115
|
+
<span class='kw'>end</span>
|
|
116
|
+
</code></pre>
|
|
117
|
+
|
|
118
|
+
<h2 id="idempotent-services">Idempotent Services</h2>
|
|
119
|
+
|
|
120
|
+
<p>Use database constraints to make services idempotent:</p>
|
|
121
|
+
|
|
122
|
+
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>Users</span><span class='op'>::</span><span class='const'>Create</span><span class='op'>::</span><span class='const'>Service</span> <span class='op'><</span> <span class='const'><span class='object_link'><a href="Servus.html" title="Servus (module)">Servus</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Servus/Base.html" title="Servus::Base (class)">Base</a></span></span>
|
|
123
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_call'>call</span>
|
|
124
|
+
<span class='comment'># Unique constraint on email prevents duplicates
|
|
125
|
+
</span> <span class='id identifier rubyid_user'>user</span> <span class='op'>=</span> <span class='const'>User</span><span class='period'>.</span><span class='id identifier rubyid_create!'>create!</span><span class='lparen'>(</span><span class='label'>email:</span> <span class='ivar'>@email</span><span class='comma'>,</span> <span class='label'>name:</span> <span class='ivar'>@name</span><span class='rparen'>)</span>
|
|
126
|
+
<span class='id identifier rubyid_success'>success</span><span class='lparen'>(</span><span class='label'>user:</span> <span class='id identifier rubyid_user'>user</span><span class='rparen'>)</span>
|
|
127
|
+
<span class='kw'>rescue</span> <span class='const'>ActiveRecord</span><span class='op'>::</span><span class='const'>RecordNotUnique</span>
|
|
128
|
+
<span class='id identifier rubyid_user'>user</span> <span class='op'>=</span> <span class='const'>User</span><span class='period'>.</span><span class='id identifier rubyid_find_by!'>find_by!</span><span class='lparen'>(</span><span class='label'>email:</span> <span class='ivar'>@email</span><span class='rparen'>)</span>
|
|
129
|
+
<span class='id identifier rubyid_success'>success</span><span class='lparen'>(</span><span class='label'>user:</span> <span class='id identifier rubyid_user'>user</span><span class='rparen'>)</span> <span class='comment'># Return existing user, not error
|
|
130
|
+
</span> <span class='kw'>end</span>
|
|
131
|
+
<span class='kw'>end</span>
|
|
132
|
+
</code></pre>
|
|
133
|
+
|
|
134
|
+
<p>Or check for existing resources explicitly:</p>
|
|
135
|
+
|
|
136
|
+
<pre class="code ruby"><code class="ruby"><span class='kw'>def</span> <span class='id identifier rubyid_call'>call</span>
|
|
137
|
+
<span class='id identifier rubyid_existing'>existing</span> <span class='op'>=</span> <span class='const'>User</span><span class='period'>.</span><span class='id identifier rubyid_find_by'>find_by</span><span class='lparen'>(</span><span class='label'>email:</span> <span class='ivar'>@email</span><span class='rparen'>)</span>
|
|
138
|
+
<span class='kw'>return</span> <span class='id identifier rubyid_success'>success</span><span class='lparen'>(</span><span class='label'>user:</span> <span class='id identifier rubyid_existing'>existing</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_existing'>existing</span>
|
|
139
|
+
|
|
140
|
+
<span class='id identifier rubyid_user'>user</span> <span class='op'>=</span> <span class='const'>User</span><span class='period'>.</span><span class='id identifier rubyid_create!'>create!</span><span class='lparen'>(</span><span class='label'>email:</span> <span class='ivar'>@email</span><span class='comma'>,</span> <span class='label'>name:</span> <span class='ivar'>@name</span><span class='rparen'>)</span>
|
|
141
|
+
<span class='id identifier rubyid_success'>success</span><span class='lparen'>(</span><span class='label'>user:</span> <span class='id identifier rubyid_user'>user</span><span class='rparen'>)</span>
|
|
142
|
+
<span class='kw'>end</span>
|
|
143
|
+
</code></pre>
|
|
144
|
+
</div></div>
|
|
145
|
+
|
|
146
|
+
<div id="footer">
|
|
147
|
+
Generated on Fri Nov 21 00:30:04 2025 by
|
|
148
|
+
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
149
|
+
0.9.37 (ruby-3.4.4).
|
|
150
|
+
</div>
|
|
151
|
+
|
|
152
|
+
</div>
|
|
153
|
+
</body>
|
|
154
|
+
</html>
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>
|
|
7
|
+
File: Integration / Configuration
|
|
8
|
+
|
|
9
|
+
— Servus | Service Object Framework
|
|
10
|
+
|
|
11
|
+
</title>
|
|
12
|
+
|
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" />
|
|
14
|
+
|
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" />
|
|
16
|
+
|
|
17
|
+
<script type="text/javascript">
|
|
18
|
+
pathId = "configuration";
|
|
19
|
+
relpath = '';
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
|
24
|
+
|
|
25
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
</head>
|
|
29
|
+
<body>
|
|
30
|
+
<div class="nav_wrap">
|
|
31
|
+
<iframe id="nav" src="file_list.html?1"></iframe>
|
|
32
|
+
<div id="resizer"></div>
|
|
33
|
+
</div>
|
|
34
|
+
|
|
35
|
+
<div id="main" tabindex="-1">
|
|
36
|
+
<div id="header">
|
|
37
|
+
<div id="menu">
|
|
38
|
+
|
|
39
|
+
<a href="_index.html">Index</a> »
|
|
40
|
+
<span class="title">File: Integration / Configuration</span>
|
|
41
|
+
|
|
42
|
+
</div>
|
|
43
|
+
|
|
44
|
+
<div id="search">
|
|
45
|
+
|
|
46
|
+
<a class="full_list_link" id="class_list_link"
|
|
47
|
+
href="class_list.html">
|
|
48
|
+
|
|
49
|
+
<svg width="24" height="24">
|
|
50
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
|
51
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
|
52
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
|
53
|
+
</svg>
|
|
54
|
+
</a>
|
|
55
|
+
|
|
56
|
+
</div>
|
|
57
|
+
<div class="clear"></div>
|
|
58
|
+
</div>
|
|
59
|
+
|
|
60
|
+
<div id="content"><div id='filecontents'><h1 id="configuration">Configuration</h1>
|
|
61
|
+
|
|
62
|
+
<p>Servus works without configuration. One optional setting exists for schema file location.</p>
|
|
63
|
+
|
|
64
|
+
<h2 id="schema-root">Schema Root</h2>
|
|
65
|
+
|
|
66
|
+
<p>By default, Servus looks for schema JSON files in <code>Rails.root/app/schemas/services</code> (or <code>./app/schemas/services</code> in non-Rails apps).</p>
|
|
67
|
+
|
|
68
|
+
<p>Change the location if needed:</p>
|
|
69
|
+
|
|
70
|
+
<pre class="code ruby"><code class="ruby"><span class='comment'># config/initializers/servus.rb
|
|
71
|
+
</span><span class='const'><span class='object_link'><a href="Servus.html" title="Servus (module)">Servus</a></span></span><span class='period'>.</span><span class='id identifier rubyid_configure'><span class='object_link'><a href="Servus.html#configure-class_method" title="Servus.configure (method)">configure</a></span></span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_config'>config</span><span class='op'>|</span>
|
|
72
|
+
<span class='id identifier rubyid_config'>config</span><span class='period'>.</span><span class='id identifier rubyid_schema_root'>schema_root</span> <span class='op'>=</span> <span class='const'>Rails</span><span class='period'>.</span><span class='id identifier rubyid_root'>root</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>config/schemas</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
|
73
|
+
<span class='kw'>end</span>
|
|
74
|
+
</code></pre>
|
|
75
|
+
|
|
76
|
+
<p>This affects legacy file-based schemas only - schemas defined via the <code>schema</code> DSL method do not use files.</p>
|
|
77
|
+
|
|
78
|
+
<h2 id="schema-cache">Schema Cache</h2>
|
|
79
|
+
|
|
80
|
+
<p>Schemas are cached after first load for performance. Clear the cache during development when schemas change:</p>
|
|
81
|
+
|
|
82
|
+
<pre class="code ruby"><code class="ruby"><span class='const'><span class='object_link'><a href="Servus.html" title="Servus (module)">Servus</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Servus/Support.html" title="Servus::Support (module)">Support</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Servus/Support/Validator.html" title="Servus::Support::Validator (class)">Validator</a></span></span><span class='period'>.</span><span class='id identifier rubyid_clear_cache!'><span class='object_link'><a href="Servus/Support/Validator.html#clear_cache!-class_method" title="Servus::Support::Validator.clear_cache! (method)">clear_cache!</a></span></span>
|
|
83
|
+
</code></pre>
|
|
84
|
+
|
|
85
|
+
<p>In production, schemas are deployed with code - no need to clear cache.</p>
|
|
86
|
+
|
|
87
|
+
<h2 id="log-level">Log Level</h2>
|
|
88
|
+
|
|
89
|
+
<p>Servus uses <code>Rails.logger</code> (or stdout in non-Rails apps). Control logging via Rails configuration:</p>
|
|
90
|
+
|
|
91
|
+
<pre class="code ruby"><code class="ruby"><span class='comment'># config/environments/production.rb
|
|
92
|
+
</span><span class='id identifier rubyid_config'>config</span><span class='period'>.</span><span class='id identifier rubyid_log_level'>log_level</span> <span class='op'>=</span> <span class='symbol'>:info</span> <span class='comment'># Hides DEBUG argument logs
|
|
93
|
+
</span></code></pre>
|
|
94
|
+
|
|
95
|
+
<h2 id="activejob-configuration">ActiveJob Configuration</h2>
|
|
96
|
+
|
|
97
|
+
<p>Async execution uses ActiveJob. Configure your adapter:</p>
|
|
98
|
+
|
|
99
|
+
<pre class="code ruby"><code class="ruby"><span class='comment'># config/application.rb
|
|
100
|
+
</span><span class='id identifier rubyid_config'>config</span><span class='period'>.</span><span class='id identifier rubyid_active_job'>active_job</span><span class='period'>.</span><span class='id identifier rubyid_queue_adapter'>queue_adapter</span> <span class='op'>=</span> <span class='symbol'>:sidekiq</span>
|
|
101
|
+
<span class='id identifier rubyid_config'>config</span><span class='period'>.</span><span class='id identifier rubyid_active_job'>active_job</span><span class='period'>.</span><span class='id identifier rubyid_default_queue_name'>default_queue_name</span> <span class='op'>=</span> <span class='symbol'>:default</span>
|
|
102
|
+
</code></pre>
|
|
103
|
+
|
|
104
|
+
<p>Servus respects ActiveJob queue configuration - no Servus-specific setup needed.</p>
|
|
105
|
+
</div></div>
|
|
106
|
+
|
|
107
|
+
<div id="footer">
|
|
108
|
+
Generated on Fri Nov 21 00:30:04 2025 by
|
|
109
|
+
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
110
|
+
0.9.37 (ruby-3.4.4).
|
|
111
|
+
</div>
|
|
112
|
+
|
|
113
|
+
</div>
|
|
114
|
+
</body>
|
|
115
|
+
</html>
|