This is page 3 of 10. Use http://codebase.md/m-gonzalo/cosa-sai?lines=true&page={x} to view the full context.
# Directory Structure
```
├── .gitignore
├── bun.lock
├── Dockerfile
├── package.json
├── prompts
│ └── default.txt
├── README.md
├── smithery.yaml
├── src
│ ├── db.ts
│ ├── gemini.ts
│ ├── index.ts
│ ├── logger.ts
│ └── types.ts
├── test
│ ├── docs
│ │ ├── ash-docs
│ │ │ ├── ash_admin.md
│ │ │ ├── ash_appsignal.md
│ │ │ ├── ash_archival.md
│ │ │ ├── ash_authentication_phoenix.md
│ │ │ ├── ash_authentication.md
│ │ │ ├── ash_cloak.md
│ │ │ ├── ash_csv.md
│ │ │ ├── ash_cubdb.md
│ │ │ ├── ash_double_entry.md
│ │ │ ├── ash_graphql.md
│ │ │ ├── ash_json_api.md
│ │ │ ├── ash_money.md
│ │ │ ├── ash_oban.md
│ │ │ ├── ash_phoenix.md
│ │ │ ├── ash_postgres.md
│ │ │ ├── ash_rbac.md
│ │ │ ├── ash_sqlite.md
│ │ │ ├── ash_state_machine.md
│ │ │ └── ash.md
│ │ ├── bun-elysia-docs
│ │ │ ├── bun.sh.md
│ │ │ └── elysiajs.com.md
│ │ ├── javascript-docs
│ │ │ └── sample.md
│ │ └── phoenix-docs
│ │ └── phx-docs.md
│ └── prompts
│ ├── ash-framework.txt
│ ├── bun-elysia.txt
│ ├── javascript.txt
│ └── phoenix.txt
└── tsconfig.json
```
# Files
--------------------------------------------------------------------------------
/test/docs/ash-docs/ash_state_machine.md:
--------------------------------------------------------------------------------
```markdown
1 | [](https://github.com/ash-project/ash_state_machine)
2 |
3 | [ash\_state\_machine](https://github.com/ash-project/ash_state_machine)
4 |
5 | v0.2.7
6 |
7 | - GUIDES
8 | - Modules
9 | - Mix Tasks
10 |
11 | <!--THE END-->
12 |
13 | <!--THE END-->
14 |
15 | <!--THE END-->
16 |
17 | Search documentation of ash\_state\_machine
18 |
19 | Settings
20 |
21 | # [View Source](https://github.com/ash-project/ash_state_machine "View Source") API Reference ash\_state\_machine v0.2.7
22 |
23 | ## [](api-reference.html#modules)Modules
24 |
25 | [AshStateMachine](AshStateMachine.html)
26 |
27 | Provides tools for defining and working with resource-backed state machines.
28 |
29 | [AshStateMachine.BuiltinChanges](AshStateMachine.BuiltinChanges.html)
30 |
31 | Changes for working with AshStateMachine resources.
32 |
33 | [AshStateMachine.Charts](AshStateMachine.Charts.html)
34 |
35 | Returns a mermaid flow chart of a given state machine resource.
36 |
37 | [AshStateMachine.Checks.ValidNextState](AshStateMachine.Checks.ValidNextState.html)
38 |
39 | A policy for pre\_flight checking if a state transition is allowed.
40 |
41 | [AshStateMachine.Errors.InvalidInitialState](AshStateMachine.Errors.InvalidInitialState.html)
42 |
43 | Used when an initial state is set that is not a valid initial state
44 |
45 | [AshStateMachine.Errors.NoMatchingTransition](AshStateMachine.Errors.NoMatchingTransition.html)
46 |
47 | Used when a state change occurs in an action with no matching transition
48 |
49 | [AshStateMachine.Info](AshStateMachine.Info.html)
50 |
51 | Introspection helpers for [`AshStateMachine`](AshStateMachine.html)
52 |
53 | [AshStateMachine.Transition](AshStateMachine.Transition.html)
54 |
55 | The configuration for an transition.
56 |
57 | ## [](api-reference.html#mix-tasks)Mix Tasks
58 |
59 | [mix ash\_state\_machine.generate\_flow\_charts](Mix.Tasks.AshStateMachine.GenerateFlowCharts.html)
60 |
61 | Generates a Mermaid Flow Chart for each [`Ash.Resource`](../ash/3.4.43/Ash.Resource.html) with the [`AshStateMachine`](AshStateMachine.html) extension alongside the resource.
62 |
63 | [Next Page → Home](readme.html)
64 |
65 | [Hex Package](https://hex.pm/packages/ash_state_machine/0.2.7) [Hex Preview](https://preview.hex.pm/preview/ash_state_machine/0.2.7) Search HexDocs [Download ePub version](ash_state_machine.epub "ePub version")
66 |
67 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.34.2) for the [Elixir programming language](https://elixir-lang.org "Elixir")
68 | [](https://github.com/ash-project/ash_state_machine)
69 |
70 | [ash\_state\_machine](https://github.com/ash-project/ash_state_machine)
71 |
72 | v0.2.7
73 |
74 | - GUIDES
75 | - Modules
76 | - Mix Tasks
77 |
78 | <!--THE END-->
79 |
80 | <!--THE END-->
81 |
82 | <!--THE END-->
83 |
84 | Search documentation of ash\_state\_machine
85 |
86 | Settings
87 |
88 | # [View Source](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/builtin_changes/builtin_changes.ex#L1 "View Source") AshStateMachine.BuiltinChanges (ash\_state\_machine v0.2.7)
89 |
90 | Changes for working with AshStateMachine resources.
91 |
92 | # [](AshStateMachine.BuiltinChanges.html#summary)Summary
93 |
94 | ## [Functions](AshStateMachine.BuiltinChanges.html#functions)
95 |
96 | [next\_state()](AshStateMachine.BuiltinChanges.html#next_state/0)
97 |
98 | Try and transition to the next state. Must be only one possible next state.
99 |
100 | [transition\_state(target)](AshStateMachine.BuiltinChanges.html#transition_state/1)
101 |
102 | Changes the state to the target state, validating the transition
103 |
104 | # [](AshStateMachine.BuiltinChanges.html#functions)Functions
105 |
106 | [](AshStateMachine.BuiltinChanges.html#next_state/0)
107 |
108 | # next\_state()
109 |
110 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/builtin_changes/builtin_changes.ex#L16)
111 |
112 | Try and transition to the next state. Must be only one possible next state.
113 |
114 | [](AshStateMachine.BuiltinChanges.html#transition_state/1)
115 |
116 | # transition\_state(target)
117 |
118 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/builtin_changes/builtin_changes.ex#L9)
119 |
120 | Changes the state to the target state, validating the transition
121 |
122 | [Hex Package](https://hex.pm/packages/ash_state_machine/0.2.7) [Hex Preview](https://preview.hex.pm/preview/ash_state_machine/0.2.7) Search HexDocs [Download ePub version](ash_state_machine.epub "ePub version")
123 |
124 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.34.2) for the [Elixir programming language](https://elixir-lang.org "Elixir")
125 | [](https://github.com/ash-project/ash_state_machine)
126 |
127 | [ash\_state\_machine](https://github.com/ash-project/ash_state_machine)
128 |
129 | v0.2.7
130 |
131 | - GUIDES
132 | - Modules
133 | - Mix Tasks
134 |
135 | <!--THE END-->
136 |
137 | <!--THE END-->
138 |
139 | <!--THE END-->
140 |
141 | Search documentation of ash\_state\_machine
142 |
143 | Settings
144 |
145 | # [View Source](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/charts.ex#L1 "View Source") AshStateMachine.Charts (ash\_state\_machine v0.2.7)
146 |
147 | Returns a mermaid flow chart of a given state machine resource.
148 |
149 | # [](AshStateMachine.Charts.html#summary)Summary
150 |
151 | ## [Functions](AshStateMachine.Charts.html#functions)
152 |
153 | [mermaid\_flowchart(resource)](AshStateMachine.Charts.html#mermaid_flowchart/1)
154 |
155 | [mermaid\_state\_diagram(resource)](AshStateMachine.Charts.html#mermaid_state_diagram/1)
156 |
157 | # [](AshStateMachine.Charts.html#functions)Functions
158 |
159 | [](AshStateMachine.Charts.html#mermaid_flowchart/1)
160 |
161 | # mermaid\_flowchart(resource)
162 |
163 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/charts.ex#L18)
164 |
165 | ```
166 | @spec mermaid_flowchart(Ash.Resource.t()) :: String.t()
167 | ```
168 |
169 | [](AshStateMachine.Charts.html#mermaid_state_diagram/1)
170 |
171 | # mermaid\_state\_diagram(resource)
172 |
173 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/charts.ex#L7)
174 |
175 | ```
176 | @spec mermaid_state_diagram(Ash.Resource.t()) :: String.t()
177 | ```
178 |
179 | [Hex Package](https://hex.pm/packages/ash_state_machine/0.2.7) [Hex Preview](https://preview.hex.pm/preview/ash_state_machine/0.2.7) Search HexDocs [Download ePub version](ash_state_machine.epub "ePub version")
180 |
181 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.34.2) for the [Elixir programming language](https://elixir-lang.org "Elixir")
182 | [](https://github.com/ash-project/ash_state_machine)
183 |
184 | [ash\_state\_machine](https://github.com/ash-project/ash_state_machine)
185 |
186 | v0.2.7
187 |
188 | - GUIDES
189 | - Modules
190 | - Mix Tasks
191 |
192 | <!--THE END-->
193 |
194 | <!--THE END-->
195 |
196 | <!--THE END-->
197 |
198 | Search documentation of ash\_state\_machine
199 |
200 | Settings
201 |
202 | # [View Source](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/checks/valid_next_state.ex#L1 "View Source") AshStateMachine.Checks.ValidNextState (ash\_state\_machine v0.2.7)
203 |
204 | A policy for pre\_flight checking if a state transition is allowed.
205 |
206 | # [](AshStateMachine.Checks.ValidNextState.html#summary)Summary
207 |
208 | ## [Functions](AshStateMachine.Checks.ValidNextState.html#functions)
209 |
210 | [auto\_filter(actor, authorizer, opts)](AshStateMachine.Checks.ValidNextState.html#auto_filter/3)
211 |
212 | Callback implementation for [`Ash.Policy.Check.auto_filter/3`](../ash/3.4.43/Ash.Policy.Check.html#c:auto_filter/3).
213 |
214 | [auto\_filter\_not(actor, authorizer, opts)](AshStateMachine.Checks.ValidNextState.html#auto_filter_not/3)
215 |
216 | [check(actor, data, authorizer, opts)](AshStateMachine.Checks.ValidNextState.html#check/4)
217 |
218 | Callback implementation for [`Ash.Policy.Check.check/4`](../ash/3.4.43/Ash.Policy.Check.html#c:check/4).
219 |
220 | [describe(\_)](AshStateMachine.Checks.ValidNextState.html#describe/1)
221 |
222 | Callback implementation for [`Ash.Policy.Check.describe/1`](../ash/3.4.43/Ash.Policy.Check.html#c:describe/1).
223 |
224 | [eager\_evaluate?()](AshStateMachine.Checks.ValidNextState.html#eager_evaluate?/0)
225 |
226 | Callback implementation for [`Ash.Policy.Check.eager_evaluate?/0`](../ash/3.4.43/Ash.Policy.Check.html#c:eager_evaluate?/0).
227 |
228 | [expand\_description(actor, authorizer, opts)](AshStateMachine.Checks.ValidNextState.html#expand_description/3)
229 |
230 | Callback implementation for [`Ash.Policy.Check.expand_description/3`](../ash/3.4.43/Ash.Policy.Check.html#c:expand_description/3).
231 |
232 | [filter(actor, context, options)](AshStateMachine.Checks.ValidNextState.html#filter/3)
233 |
234 | Callback implementation for [`Ash.Policy.FilterCheck.filter/3`](../ash/3.4.43/Ash.Policy.FilterCheck.html#c:filter/3).
235 |
236 | [prefer\_expanded\_description?()](AshStateMachine.Checks.ValidNextState.html#prefer_expanded_description?/0)
237 |
238 | Callback implementation for [`Ash.Policy.Check.prefer_expanded_description?/0`](../ash/3.4.43/Ash.Policy.Check.html#c:prefer_expanded_description?/0).
239 |
240 | [reject(actor, authorizer, opts)](AshStateMachine.Checks.ValidNextState.html#reject/3)
241 |
242 | Callback implementation for [`Ash.Policy.FilterCheck.reject/3`](../ash/3.4.43/Ash.Policy.FilterCheck.html#c:reject/3).
243 |
244 | [requires\_original\_data?(\_, \_)](AshStateMachine.Checks.ValidNextState.html#requires_original_data?/2)
245 |
246 | Callback implementation for [`Ash.Policy.Check.requires_original_data?/2`](../ash/3.4.43/Ash.Policy.Check.html#c:requires_original_data?/2).
247 |
248 | [strict\_check(actor, authorizer, opts)](AshStateMachine.Checks.ValidNextState.html#strict_check/3)
249 |
250 | Callback implementation for [`Ash.Policy.Check.strict_check/3`](../ash/3.4.43/Ash.Policy.Check.html#c:strict_check/3).
251 |
252 | [strict\_check\_context(opts)](AshStateMachine.Checks.ValidNextState.html#strict_check_context/1)
253 |
254 | [type()](AshStateMachine.Checks.ValidNextState.html#type/0)
255 |
256 | Callback implementation for [`Ash.Policy.Check.type/0`](../ash/3.4.43/Ash.Policy.Check.html#c:type/0).
257 |
258 | # [](AshStateMachine.Checks.ValidNextState.html#functions)Functions
259 |
260 | [](AshStateMachine.Checks.ValidNextState.html#auto_filter/3)
261 |
262 | # auto\_filter(actor, authorizer, opts)
263 |
264 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/checks/valid_next_state.ex#L5)
265 |
266 | Callback implementation for [`Ash.Policy.Check.auto_filter/3`](../ash/3.4.43/Ash.Policy.Check.html#c:auto_filter/3).
267 |
268 | [](AshStateMachine.Checks.ValidNextState.html#auto_filter_not/3)
269 |
270 | # auto\_filter\_not(actor, authorizer, opts)
271 |
272 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/checks/valid_next_state.ex#L5)
273 |
274 | [](AshStateMachine.Checks.ValidNextState.html#check/4)
275 |
276 | # check(actor, data, authorizer, opts)
277 |
278 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/checks/valid_next_state.ex#L5)
279 |
280 | Callback implementation for [`Ash.Policy.Check.check/4`](../ash/3.4.43/Ash.Policy.Check.html#c:check/4).
281 |
282 | [](AshStateMachine.Checks.ValidNextState.html#describe/1)
283 |
284 | # describe(\_)
285 |
286 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/checks/valid_next_state.ex#L7)
287 |
288 | Callback implementation for [`Ash.Policy.Check.describe/1`](../ash/3.4.43/Ash.Policy.Check.html#c:describe/1).
289 |
290 | [](AshStateMachine.Checks.ValidNextState.html#eager_evaluate?/0)
291 |
292 | # eager\_evaluate?()
293 |
294 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/checks/valid_next_state.ex#L5)
295 |
296 | Callback implementation for [`Ash.Policy.Check.eager_evaluate?/0`](../ash/3.4.43/Ash.Policy.Check.html#c:eager_evaluate?/0).
297 |
298 | [](AshStateMachine.Checks.ValidNextState.html#expand_description/3)
299 |
300 | # expand\_description(actor, authorizer, opts)
301 |
302 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/checks/valid_next_state.ex#L5)
303 |
304 | Callback implementation for [`Ash.Policy.Check.expand_description/3`](../ash/3.4.43/Ash.Policy.Check.html#c:expand_description/3).
305 |
306 | [](AshStateMachine.Checks.ValidNextState.html#filter/3)
307 |
308 | # filter(actor, context, options)
309 |
310 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/checks/valid_next_state.ex#L11)
311 |
312 | Callback implementation for [`Ash.Policy.FilterCheck.filter/3`](../ash/3.4.43/Ash.Policy.FilterCheck.html#c:filter/3).
313 |
314 | [](AshStateMachine.Checks.ValidNextState.html#prefer_expanded_description?/0)
315 |
316 | # prefer\_expanded\_description?()
317 |
318 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/checks/valid_next_state.ex#L5)
319 |
320 | Callback implementation for [`Ash.Policy.Check.prefer_expanded_description?/0`](../ash/3.4.43/Ash.Policy.Check.html#c:prefer_expanded_description?/0).
321 |
322 | [](AshStateMachine.Checks.ValidNextState.html#reject/3)
323 |
324 | # reject(actor, authorizer, opts)
325 |
326 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/checks/valid_next_state.ex#L5)
327 |
328 | Callback implementation for [`Ash.Policy.FilterCheck.reject/3`](../ash/3.4.43/Ash.Policy.FilterCheck.html#c:reject/3).
329 |
330 | [](AshStateMachine.Checks.ValidNextState.html#requires_original_data?/2)
331 |
332 | # requires\_original\_data?(\_, \_)
333 |
334 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/checks/valid_next_state.ex#L5)
335 |
336 | Callback implementation for [`Ash.Policy.Check.requires_original_data?/2`](../ash/3.4.43/Ash.Policy.Check.html#c:requires_original_data?/2).
337 |
338 | [](AshStateMachine.Checks.ValidNextState.html#strict_check/3)
339 |
340 | # strict\_check(actor, authorizer, opts)
341 |
342 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/checks/valid_next_state.ex#L5)
343 |
344 | Callback implementation for [`Ash.Policy.Check.strict_check/3`](../ash/3.4.43/Ash.Policy.Check.html#c:strict_check/3).
345 |
346 | [](AshStateMachine.Checks.ValidNextState.html#strict_check_context/1)
347 |
348 | # strict\_check\_context(opts)
349 |
350 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/checks/valid_next_state.ex#L5)
351 |
352 | [](AshStateMachine.Checks.ValidNextState.html#type/0)
353 |
354 | # type()
355 |
356 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/checks/valid_next_state.ex#L5)
357 |
358 | Callback implementation for [`Ash.Policy.Check.type/0`](../ash/3.4.43/Ash.Policy.Check.html#c:type/0).
359 |
360 | [Hex Package](https://hex.pm/packages/ash_state_machine/0.2.7) [Hex Preview](https://preview.hex.pm/preview/ash_state_machine/0.2.7) Search HexDocs [Download ePub version](ash_state_machine.epub "ePub version")
361 |
362 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.34.2) for the [Elixir programming language](https://elixir-lang.org "Elixir")
363 | [](https://github.com/ash-project/ash_state_machine)
364 |
365 | [ash\_state\_machine](https://github.com/ash-project/ash_state_machine)
366 |
367 | v0.2.7
368 |
369 | - GUIDES
370 | - Modules
371 | - Mix Tasks
372 |
373 | <!--THE END-->
374 |
375 | <!--THE END-->
376 |
377 | <!--THE END-->
378 |
379 | Search documentation of ash\_state\_machine
380 |
381 | Settings
382 |
383 | # [View Source](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/errors/invalid_initial_state.ex#L1 "View Source") AshStateMachine.Errors.InvalidInitialState exception (ash\_state\_machine v0.2.7)
384 |
385 | Used when an initial state is set that is not a valid initial state
386 |
387 | # [](AshStateMachine.Errors.InvalidInitialState.html#summary)Summary
388 |
389 | ## [Functions](AshStateMachine.Errors.InvalidInitialState.html#functions)
390 |
391 | [exception()](AshStateMachine.Errors.InvalidInitialState.html#exception/0)
392 |
393 | # [](AshStateMachine.Errors.InvalidInitialState.html#functions)Functions
394 |
395 | [](AshStateMachine.Errors.InvalidInitialState.html#exception/0)
396 |
397 | # exception()
398 |
399 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/errors/invalid_initial_state.ex#L5)
400 |
401 | [Hex Package](https://hex.pm/packages/ash_state_machine/0.2.7) [Hex Preview](https://preview.hex.pm/preview/ash_state_machine/0.2.7) Search HexDocs [Download ePub version](ash_state_machine.epub "ePub version")
402 |
403 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.34.2) for the [Elixir programming language](https://elixir-lang.org "Elixir")
404 | [](https://github.com/ash-project/ash_state_machine)
405 |
406 | [ash\_state\_machine](https://github.com/ash-project/ash_state_machine)
407 |
408 | v0.2.7
409 |
410 | - GUIDES
411 | - Modules
412 | - Mix Tasks
413 |
414 | <!--THE END-->
415 |
416 | <!--THE END-->
417 |
418 | <!--THE END-->
419 |
420 | Search documentation of ash\_state\_machine
421 |
422 | Settings
423 |
424 | # [View Source](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/errors/no_matching_event.ex#L1 "View Source") AshStateMachine.Errors.NoMatchingTransition exception (ash\_state\_machine v0.2.7)
425 |
426 | Used when a state change occurs in an action with no matching transition
427 |
428 | # [](AshStateMachine.Errors.NoMatchingTransition.html#summary)Summary
429 |
430 | ## [Functions](AshStateMachine.Errors.NoMatchingTransition.html#functions)
431 |
432 | [exception()](AshStateMachine.Errors.NoMatchingTransition.html#exception/0)
433 |
434 | # [](AshStateMachine.Errors.NoMatchingTransition.html#functions)Functions
435 |
436 | [](AshStateMachine.Errors.NoMatchingTransition.html#exception/0)
437 |
438 | # exception()
439 |
440 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/errors/no_matching_event.ex#L3)
441 |
442 | [Hex Package](https://hex.pm/packages/ash_state_machine/0.2.7) [Hex Preview](https://preview.hex.pm/preview/ash_state_machine/0.2.7) Search HexDocs [Download ePub version](ash_state_machine.epub "ePub version")
443 |
444 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.34.2) for the [Elixir programming language](https://elixir-lang.org "Elixir")
445 | [](https://github.com/ash-project/ash_state_machine)
446 |
447 | [ash\_state\_machine](https://github.com/ash-project/ash_state_machine)
448 |
449 | v0.2.7
450 |
451 | - GUIDES
452 | - Modules
453 | - Mix Tasks
454 |
455 | <!--THE END-->
456 |
457 | <!--THE END-->
458 |
459 | <!--THE END-->
460 |
461 | Search documentation of ash\_state\_machine
462 |
463 | Settings
464 |
465 | # [View Source](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/ash_state_machine.ex#L1 "View Source") AshStateMachine (ash\_state\_machine v0.2.7)
466 |
467 | Provides tools for defining and working with resource-backed state machines.
468 |
469 | # [](AshStateMachine.html#summary)Summary
470 |
471 | ## [Functions](AshStateMachine.html#functions)
472 |
473 | [possible\_next\_states(record)](AshStateMachine.html#possible_next_states/1)
474 |
475 | A reusable helper which returns all possible next states for a record (regardless of action).
476 |
477 | [possible\_next\_states(record, action\_name)](AshStateMachine.html#possible_next_states/2)
478 |
479 | A reusable helper which returns all possible next states for a record given a specific action.
480 |
481 | [state\_machine(body)](AshStateMachine.html#state_machine/1)
482 |
483 | [transition\_state(changeset, target)](AshStateMachine.html#transition_state/2)
484 |
485 | A utility to transition the state of a changeset, honoring the rules of the resource.
486 |
487 | # [](AshStateMachine.html#functions)Functions
488 |
489 | [](AshStateMachine.html#possible_next_states/1)
490 |
491 | # possible\_next\_states(record)
492 |
493 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/ash_state_machine.ex#L233)
494 |
495 | ```
496 | @spec possible_next_states(Ash.Resource.record()) :: [atom()]
497 | ```
498 |
499 | A reusable helper which returns all possible next states for a record (regardless of action).
500 |
501 | [](AshStateMachine.html#possible_next_states/2)
502 |
503 | # possible\_next\_states(record, action\_name)
504 |
505 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/ash_state_machine.ex#L251)
506 |
507 | ```
508 | @spec possible_next_states(Ash.Resource.record(), atom()) :: [atom()]
509 | ```
510 |
511 | A reusable helper which returns all possible next states for a record given a specific action.
512 |
513 | [](AshStateMachine.html#state_machine/1)
514 |
515 | # state\_machine(body)
516 |
517 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/ash_state_machine.ex#L111)(macro)
518 |
519 | [](AshStateMachine.html#transition_state/2)
520 |
521 | # transition\_state(changeset, target)
522 |
523 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/ash_state_machine.ex#L129)
524 |
525 | A utility to transition the state of a changeset, honoring the rules of the resource.
526 |
527 | [Hex Package](https://hex.pm/packages/ash_state_machine/0.2.7) [Hex Preview](https://preview.hex.pm/preview/ash_state_machine/0.2.7) Search HexDocs [Download ePub version](ash_state_machine.epub "ePub version")
528 |
529 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.34.2) for the [Elixir programming language](https://elixir-lang.org "Elixir")
530 | [](https://github.com/ash-project/ash_state_machine)
531 |
532 | [ash\_state\_machine](https://github.com/ash-project/ash_state_machine)
533 |
534 | v0.2.7
535 |
536 | - GUIDES
537 | - Modules
538 | - Mix Tasks
539 |
540 | <!--THE END-->
541 |
542 | <!--THE END-->
543 |
544 | <!--THE END-->
545 |
546 | Search documentation of ash\_state\_machine
547 |
548 | Settings
549 |
550 | # [View Source](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/info.ex#L1 "View Source") AshStateMachine.Info (ash\_state\_machine v0.2.7)
551 |
552 | Introspection helpers for [`AshStateMachine`](AshStateMachine.html)
553 |
554 | # [](AshStateMachine.Info.html#summary)Summary
555 |
556 | ## [Functions](AshStateMachine.Info.html#functions)
557 |
558 | [state\_machine\_all\_states(resource\_or\_dsl)](AshStateMachine.Info.html#state_machine_all_states/1)
559 |
560 | [state\_machine\_default\_initial\_state(dsl\_or\_extended)](AshStateMachine.Info.html#state_machine_default_initial_state/1)
561 |
562 | The default initial state
563 |
564 | [state\_machine\_default\_initial\_state!(dsl\_or\_extended)](AshStateMachine.Info.html#state_machine_default_initial_state!/1)
565 |
566 | The default initial state
567 |
568 | [state\_machine\_deprecated\_states(dsl\_or\_extended)](AshStateMachine.Info.html#state_machine_deprecated_states/1)
569 |
570 | A list of states that have been deprecated but are still valid. These will still be in the possible list of states, but `:*` will not include them.
571 |
572 | [state\_machine\_deprecated\_states!(dsl\_or\_extended)](AshStateMachine.Info.html#state_machine_deprecated_states!/1)
573 |
574 | A list of states that have been deprecated but are still valid. These will still be in the possible list of states, but `:*` will not include them.
575 |
576 | [state\_machine\_extra\_states(dsl\_or\_extended)](AshStateMachine.Info.html#state_machine_extra_states/1)
577 |
578 | A list of states that may be used by transitions to/from `:*`. See the docs on wildcards for more.
579 |
580 | [state\_machine\_extra\_states!(dsl\_or\_extended)](AshStateMachine.Info.html#state_machine_extra_states!/1)
581 |
582 | A list of states that may be used by transitions to/from `:*`. See the docs on wildcards for more.
583 |
584 | [state\_machine\_initial\_states(dsl\_or\_extended)](AshStateMachine.Info.html#state_machine_initial_states/1)
585 |
586 | The allowed starting states of this state machine.
587 |
588 | [state\_machine\_initial\_states!(dsl\_or\_extended)](AshStateMachine.Info.html#state_machine_initial_states!/1)
589 |
590 | The allowed starting states of this state machine.
591 |
592 | [state\_machine\_options(dsl\_or\_extended)](AshStateMachine.Info.html#state_machine_options/1)
593 |
594 | state\_machine DSL options
595 |
596 | [state\_machine\_state\_attribute(dsl\_or\_extended)](AshStateMachine.Info.html#state_machine_state_attribute/1)
597 |
598 | The attribute to store the state in.
599 |
600 | [state\_machine\_state\_attribute!(dsl\_or\_extended)](AshStateMachine.Info.html#state_machine_state_attribute!/1)
601 |
602 | The attribute to store the state in.
603 |
604 | [state\_machine\_transitions(dsl\_or\_extended)](AshStateMachine.Info.html#state_machine_transitions/1)
605 |
606 | state\_machine.transitions DSL entities
607 |
608 | [state\_machine\_transitions(resource\_or\_dsl, name)](AshStateMachine.Info.html#state_machine_transitions/2)
609 |
610 | # [](AshStateMachine.Info.html#functions)Functions
611 |
612 | [](AshStateMachine.Info.html#state_machine_all_states/1)
613 |
614 | # state\_machine\_all\_states(resource\_or\_dsl)
615 |
616 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/info.ex#L14)
617 |
618 | ```
619 | @spec state_machine_all_states(Ash.Resource.t() | map()) :: [atom()]
620 | ```
621 |
622 | [](AshStateMachine.Info.html#state_machine_default_initial_state/1)
623 |
624 | # state\_machine\_default\_initial\_state(dsl\_or\_extended)
625 |
626 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/info.ex#L3)
627 |
628 | ```
629 | @spec state_machine_default_initial_state(dsl_or_extended :: module() | map()) ::
630 | {:ok, atom()} | :error
631 | ```
632 |
633 | The default initial state
634 |
635 | [](AshStateMachine.Info.html#state_machine_default_initial_state!/1)
636 |
637 | # state\_machine\_default\_initial\_state!(dsl\_or\_extended)
638 |
639 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/info.ex#L3)
640 |
641 | ```
642 | @spec state_machine_default_initial_state!(dsl_or_extended :: module() | map()) ::
643 | atom() | no_return()
644 | ```
645 |
646 | The default initial state
647 |
648 | [](AshStateMachine.Info.html#state_machine_deprecated_states/1)
649 |
650 | # state\_machine\_deprecated\_states(dsl\_or\_extended)
651 |
652 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/info.ex#L3)
653 |
654 | ```
655 | @spec state_machine_deprecated_states(dsl_or_extended :: module() | map()) ::
656 | {:ok, [atom()]} | :error
657 | ```
658 |
659 | A list of states that have been deprecated but are still valid. These will still be in the possible list of states, but `:*` will not include them.
660 |
661 | [](AshStateMachine.Info.html#state_machine_deprecated_states!/1)
662 |
663 | # state\_machine\_deprecated\_states!(dsl\_or\_extended)
664 |
665 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/info.ex#L3)
666 |
667 | ```
668 | @spec state_machine_deprecated_states!(dsl_or_extended :: module() | map()) ::
669 | [atom()] | no_return()
670 | ```
671 |
672 | A list of states that have been deprecated but are still valid. These will still be in the possible list of states, but `:*` will not include them.
673 |
674 | [](AshStateMachine.Info.html#state_machine_extra_states/1)
675 |
676 | # state\_machine\_extra\_states(dsl\_or\_extended)
677 |
678 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/info.ex#L3)
679 |
680 | ```
681 | @spec state_machine_extra_states(dsl_or_extended :: module() | map()) ::
682 | {:ok, [atom()]} | :error
683 | ```
684 |
685 | A list of states that may be used by transitions to/from `:*`. See the docs on wildcards for more.
686 |
687 | [](AshStateMachine.Info.html#state_machine_extra_states!/1)
688 |
689 | # state\_machine\_extra\_states!(dsl\_or\_extended)
690 |
691 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/info.ex#L3)
692 |
693 | ```
694 | @spec state_machine_extra_states!(dsl_or_extended :: module() | map()) ::
695 | [atom()] | no_return()
696 | ```
697 |
698 | A list of states that may be used by transitions to/from `:*`. See the docs on wildcards for more.
699 |
700 | [](AshStateMachine.Info.html#state_machine_initial_states/1)
701 |
702 | # state\_machine\_initial\_states(dsl\_or\_extended)
703 |
704 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/info.ex#L3)
705 |
706 | ```
707 | @spec state_machine_initial_states(dsl_or_extended :: module() | map()) ::
708 | {:ok, [atom()]} | :error
709 | ```
710 |
711 | The allowed starting states of this state machine.
712 |
713 | [](AshStateMachine.Info.html#state_machine_initial_states!/1)
714 |
715 | # state\_machine\_initial\_states!(dsl\_or\_extended)
716 |
717 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/info.ex#L3)
718 |
719 | ```
720 | @spec state_machine_initial_states!(dsl_or_extended :: module() | map()) ::
721 | [atom()] | no_return()
722 | ```
723 |
724 | The allowed starting states of this state machine.
725 |
726 | [](AshStateMachine.Info.html#state_machine_options/1)
727 |
728 | # state\_machine\_options(dsl\_or\_extended)
729 |
730 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/info.ex#L3)
731 |
732 | ```
733 | @spec state_machine_options(dsl_or_extended :: module() | map()) :: %{
734 | required(atom()) => any()
735 | }
736 | ```
737 |
738 | state\_machine DSL options
739 |
740 | Returns a map containing the and any configured or default values.
741 |
742 | [](AshStateMachine.Info.html#state_machine_state_attribute/1)
743 |
744 | # state\_machine\_state\_attribute(dsl\_or\_extended)
745 |
746 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/info.ex#L3)
747 |
748 | ```
749 | @spec state_machine_state_attribute(dsl_or_extended :: module() | map()) ::
750 | {:ok, atom()} | :error
751 | ```
752 |
753 | The attribute to store the state in.
754 |
755 | [](AshStateMachine.Info.html#state_machine_state_attribute!/1)
756 |
757 | # state\_machine\_state\_attribute!(dsl\_or\_extended)
758 |
759 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/info.ex#L3)
760 |
761 | ```
762 | @spec state_machine_state_attribute!(dsl_or_extended :: module() | map()) ::
763 | atom() | no_return()
764 | ```
765 |
766 | The attribute to store the state in.
767 |
768 | [](AshStateMachine.Info.html#state_machine_transitions/1)
769 |
770 | # state\_machine\_transitions(dsl\_or\_extended)
771 |
772 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/info.ex#L3)
773 |
774 | ```
775 | @spec state_machine_transitions(dsl_or_extended :: module() | map()) :: [struct()]
776 | ```
777 |
778 | state\_machine.transitions DSL entities
779 |
780 | [](AshStateMachine.Info.html#state_machine_transitions/2)
781 |
782 | # state\_machine\_transitions(resource\_or\_dsl, name)
783 |
784 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/info.ex#L7)
785 |
786 | ```
787 | @spec state_machine_transitions(Ash.Resource.t() | map(), name :: atom()) :: [
788 | AshStateMachine.Transition.t()
789 | ]
790 | ```
791 |
792 | [Hex Package](https://hex.pm/packages/ash_state_machine/0.2.7) [Hex Preview](https://preview.hex.pm/preview/ash_state_machine/0.2.7) Search HexDocs [Download ePub version](ash_state_machine.epub "ePub version")
793 |
794 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.34.2) for the [Elixir programming language](https://elixir-lang.org "Elixir")
795 | [](https://github.com/ash-project/ash_state_machine)
796 |
797 | [ash\_state\_machine](https://github.com/ash-project/ash_state_machine)
798 |
799 | v0.2.7
800 |
801 | - GUIDES
802 | - Modules
803 | - Mix Tasks
804 |
805 | <!--THE END-->
806 |
807 | <!--THE END-->
808 |
809 | <!--THE END-->
810 |
811 | Search documentation of ash\_state\_machine
812 |
813 | Settings
814 |
815 | # [View Source](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/ash_state_machine.ex#L2 "View Source") AshStateMachine.Transition (ash\_state\_machine v0.2.7)
816 |
817 | The configuration for an transition.
818 |
819 | # [](AshStateMachine.Transition.html#summary)Summary
820 |
821 | ## [Types](AshStateMachine.Transition.html#types)
822 |
823 | [t()](AshStateMachine.Transition.html#t:t/0)
824 |
825 | # [](AshStateMachine.Transition.html#types)Types
826 |
827 | [](AshStateMachine.Transition.html#t:t/0)
828 |
829 | # t()
830 |
831 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/ash_state_machine.ex#L6)
832 |
833 | ```
834 | @type t() :: %AshStateMachine.Transition{
835 | __identifier__: any(),
836 | action: atom(),
837 | from: [atom()],
838 | to: [atom()]
839 | }
840 | ```
841 |
842 | [Hex Package](https://hex.pm/packages/ash_state_machine/0.2.7) [Hex Preview](https://preview.hex.pm/preview/ash_state_machine/0.2.7) Search HexDocs [Download ePub version](ash_state_machine.epub "ePub version")
843 |
844 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.34.2) for the [Elixir programming language](https://elixir-lang.org "Elixir")
845 | [](https://github.com/ash-project/ash_state_machine)
846 |
847 | [ash\_state\_machine](https://github.com/ash-project/ash_state_machine)
848 |
849 | v0.2.7
850 |
851 | - GUIDES
852 | - Modules
853 | - Mix Tasks
854 |
855 | <!--THE END-->
856 |
857 | <!--THE END-->
858 |
859 | <!--THE END-->
860 |
861 | Search documentation of ash\_state\_machine
862 |
863 | Settings
864 |
865 | # [View Source](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/documentation/topics/charts.md#L1 "View Source") Charts
866 |
867 | Run [`mix ash_state_machine.generate_flow_charts`](Mix.Tasks.AshStateMachine.GenerateFlowCharts.html) to generate flow charts for your resources. See the task documentation for more. Here is an example:
868 |
869 | ```
870 | stateDiagram-v2
871 | pending --> confirmed: confirm
872 | confirmed --> on_its_way: begin_delivery
873 | on_its_way --> arrived: package_arrived
874 | on_its_way --> error: error
875 | confirmed --> error: error
876 | pending --> error: error
877 | ```
878 |
879 | [← Previous Page What is AshStateMachine?](what-is-ash-state-machine.html)
880 |
881 | [Next Page → Working with Ash.can?](working-with-ash-can.html)
882 |
883 | [Hex Package](https://hex.pm/packages/ash_state_machine/0.2.7) [Hex Preview](https://preview.hex.pm/preview/ash_state_machine/0.2.7) ([current file](https://preview.hex.pm/preview/ash_state_machine/0.2.7/show/documentation/topics/charts.md)) Search HexDocs [Download ePub version](ash_state_machine.epub "ePub version")
884 |
885 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.34.2) for the [Elixir programming language](https://elixir-lang.org "Elixir")
886 | [](https://github.com/ash-project/ash_state_machine)
887 |
888 | [ash\_state\_machine](https://github.com/ash-project/ash_state_machine)
889 |
890 | v0.2.7
891 |
892 | - GUIDES
893 | - Modules
894 | - Mix Tasks
895 |
896 | <!--THE END-->
897 |
898 | <!--THE END-->
899 |
900 | <!--THE END-->
901 |
902 | Search documentation of ash\_state\_machine
903 |
904 | Settings
905 |
906 | # [View Source](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/documentation/dsls/DSL-AshStateMachine.md#L1 "View Source") DSL: AshStateMachine
907 |
908 | Provides tools for defining and working with resource-backed state machines.
909 |
910 | ## [](dsl-ashstatemachine.html#state_machine)state\_machine
911 |
912 | ### [](dsl-ashstatemachine.html#nested-dsls)Nested DSLs
913 |
914 | - [transitions](dsl-ashstatemachine.html#state_machine-transitions)
915 |
916 | - transition
917 |
918 | ### [](dsl-ashstatemachine.html#options)Options
919 |
920 | NameTypeDefaultDocs[`initial_states`](dsl-ashstatemachine.html#state_machine-initial_states)`list(atom)`The allowed starting states of this state machine.[`deprecated_states`](dsl-ashstatemachine.html#state_machine-deprecated_states)`list(atom)``[]`A list of states that have been deprecated but are still valid. These will still be in the possible list of states, but `:*` will not include them.[`extra_states`](dsl-ashstatemachine.html#state_machine-extra_states)`list(atom)``[]`A list of states that may be used by transitions to/from `:*`. See the docs on wildcards for more.[`state_attribute`](dsl-ashstatemachine.html#state_machine-state_attribute)`atom``:state`The attribute to store the state in.[`default_initial_state`](dsl-ashstatemachine.html#state_machine-default_initial_state)`atom`The default initial state
921 |
922 | ## [](dsl-ashstatemachine.html#state_machine-transitions)state\_machine.transitions
923 |
924 | ### [](dsl-ashstatemachine.html#wildcards)Wildcards
925 |
926 | Use `:*` to represent "any action" when used in place of an action, or "any state" when used in place of a state.
927 |
928 | For example:
929 |
930 | ```
931 | transition :*, from: :*, to: :*
932 | ```
933 |
934 | The full list of states is derived at compile time from the transitions. Use the `extra_states` to express that certain types should be included in that list even though no transitions go to/from that state explicitly. This is necessary for cases where there are states that use `:*` and no transition explicitly leads to that transition.
935 |
936 | ### [](dsl-ashstatemachine.html#nested-dsls-1)Nested DSLs
937 |
938 | - [transition](dsl-ashstatemachine.html#state_machine-transitions-transition)
939 |
940 | ## [](dsl-ashstatemachine.html#state_machine-transitions-transition)state\_machine.transitions.transition
941 |
942 | ```
943 | transition action
944 | ```
945 |
946 | ### [](dsl-ashstatemachine.html#arguments)Arguments
947 |
948 | NameTypeDefaultDocs[`action`](dsl-ashstatemachine.html#state_machine-transitions-transition-action)`atom`The corresponding action that is invoked for the transition. Use `:*` to allow any update action to perform this transition.
949 |
950 | ### [](dsl-ashstatemachine.html#options-1)Options
951 |
952 | NameTypeDefaultDocs[`from`](dsl-ashstatemachine.html#state_machine-transitions-transition-from)`list(atom) | atom`The states in which this action may be called. If not specified, then any state is accepted. Use `:*` to refer to all states.[`to`](dsl-ashstatemachine.html#state_machine-transitions-transition-to)`list(atom) | atom`The states that this action may move to. If not specified, then any state is accepted. Use `:*` to refer to all states.
953 |
954 | ### [](dsl-ashstatemachine.html#introspection)Introspection
955 |
956 | Target: [`AshStateMachine.Transition`](AshStateMachine.Transition.html)
957 |
958 | [← Previous Page Working with Ash.can?](working-with-ash-can.html)
959 |
960 | [Next Page → Change Log](changelog.html)
961 |
962 | [Hex Package](https://hex.pm/packages/ash_state_machine/0.2.7) [Hex Preview](https://preview.hex.pm/preview/ash_state_machine/0.2.7) ([current file](https://preview.hex.pm/preview/ash_state_machine/0.2.7/show/documentation/dsls/DSL-AshStateMachine.md)) Search HexDocs [Download ePub version](ash_state_machine.epub "ePub version")
963 |
964 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.34.2) for the [Elixir programming language](https://elixir-lang.org "Elixir")
965 | [](https://github.com/ash-project/ash_state_machine)
966 |
967 | [ash\_state\_machine](https://github.com/ash-project/ash_state_machine)
968 |
969 | v0.2.7
970 |
971 | - GUIDES
972 | - Modules
973 | - Mix Tasks
974 |
975 | <!--THE END-->
976 |
977 | <!--THE END-->
978 |
979 | <!--THE END-->
980 |
981 | Search documentation of ash\_state\_machine
982 |
983 | Settings
984 |
985 | # [View Source](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/documentation/tutorials/getting-started-with-ash-state-machine.md#L1 "View Source") Getting Started with State Machines
986 |
987 | ## [](getting-started-with-ash-state-machine.html#get-familiar-with-ash-resources)Get familiar with Ash resources
988 |
989 | If you haven't already, read the [Ash Getting Started Guide](../ash/get-started.html), and familiarize yourself with Ash and Ash resources.
990 |
991 | ## [](getting-started-with-ash-state-machine.html#bring-in-the-ash_state_machine-dependency)Bring in the ash\_state\_machine dependency
992 |
993 | ```
994 | {:ash_state_machine, "~> 0.2.7"}
995 | ```
996 |
997 | ## [](getting-started-with-ash-state-machine.html#add-the-extension-to-your-resource)Add the extension to your resource
998 |
999 | ```
1000 | use Ash.Resource,
1001 | extensions: [AshStateMachine]
1002 | ```
1003 |
1004 | ## [](getting-started-with-ash-state-machine.html#add-initial-states-and-a-default-initial-state)Add initial states, and a default initial state
1005 |
1006 | ```
1007 | use Ash.Resource,
1008 | extensions: [AshStateMachine]
1009 |
1010 | ...
1011 |
1012 | state_machine do
1013 | initial_states [:pending]
1014 | default_initial_state :pending
1015 | end
1016 | ```
1017 |
1018 | ## [](getting-started-with-ash-state-machine.html#add-allowed-transitions)Add allowed transitions
1019 |
1020 | ```
1021 | state_machine do
1022 | initial_states [:pending]
1023 | default_initial_state :pending
1024 |
1025 | transitions do
1026 | # `:begin` action can move state from `:pending` to `:started`/`:aborted`
1027 | transition :begin, from: :pending, to: [:started, :aborted]
1028 | end
1029 | end
1030 | ```
1031 |
1032 | ## [](getting-started-with-ash-state-machine.html#use-transition_state-in-your-actions)Use `transition_state` in your actions
1033 |
1034 | ### [](getting-started-with-ash-state-machine.html#for-simple-static-state-transitions)For simple/static state transitions
1035 |
1036 | ```
1037 | actions do
1038 | update :begin do
1039 | # for a static state transition
1040 | change transition_state(:started)
1041 | end
1042 | end
1043 | ```
1044 |
1045 | ### [](getting-started-with-ash-state-machine.html#for-dynamic-conditional-state-transitions)For dynamic/conditional state transitions
1046 |
1047 | ```
1048 | defmodule Start do
1049 | use Ash.Resource.Change
1050 |
1051 | def change(changeset, _, _) do
1052 | if ready_to_start?(changeset) do
1053 | AshStateMachine.transition_state(changeset, :started)
1054 | else
1055 | AshStateMachine.transition_state(changeset, :aborted)
1056 | end
1057 | end
1058 | end
1059 |
1060 | actions do
1061 | update :begin do
1062 | # for a dynamic state transition
1063 | change Start
1064 | end
1065 | end
1066 | ```
1067 |
1068 | ## [](getting-started-with-ash-state-machine.html#declaring-a-custom-state-attribute)Declaring a custom state attribute
1069 |
1070 | By default, a `:state` attribute is created on the resource that looks like this:
1071 |
1072 | ```
1073 | attribute :state, :atom do
1074 | allow_nil? false
1075 | default AshStateMachine.Info.state_machine_initial_default_state(dsl_state)
1076 | public? true
1077 | constraints one_of: [
1078 | AshStateMachine.Info.state_machine_all_states(dsl_state)
1079 | ]
1080 | end
1081 | ```
1082 |
1083 | You can change the name of this attribute, without declaring an attribute yourself, like so:
1084 |
1085 | ```
1086 | state_machine do
1087 | initial_states([:pending])
1088 | default_initial_state(:pending)
1089 | state_attribute(:alternative_state) # <-- save state in an attribute named :alternative_state
1090 | end
1091 | ```
1092 |
1093 | If you need more control, you can declare the attribute yourself on the resource:
1094 |
1095 | ```
1096 | attributes do
1097 | attribute :alternative_state, :atom do
1098 | allow_nil? false
1099 | default :issued
1100 | public? true
1101 | constraints one_of: [:issued, :sold, :reserved, :retired]
1102 | end
1103 | end
1104 | ```
1105 |
1106 | Be aware that the type of this attribute needs to be `:atom` or a type created with [`Ash.Type.Enum`](../ash/3.4.43/Ash.Type.Enum.html). Both the `default` and list of values need to be correct!
1107 |
1108 | ## [](getting-started-with-ash-state-machine.html#making-a-resource-into-a-state-machine)Making a resource into a state machine
1109 |
1110 | The concept of a state machine (in this case a "Finite State Machine"), essentially involves a single `state`, with specified transitions between states. For example, you might have an order state machine with states `[:pending, :on_its_way, :delivered]`. However, you can't go from `:pending` to `:delivered` (probably), and so you want to only allow certain transitions in certain circumstances, i.e `:pending -> :on_its_way -> :delivered`.
1111 |
1112 | This extension's goal is to help you write clear and clean state machines, with all of the extensibility and power of Ash resources and actions.
1113 |
1114 | [← Previous Page Home](readme.html)
1115 |
1116 | [Next Page → What is AshStateMachine?](what-is-ash-state-machine.html)
1117 |
1118 | [Hex Package](https://hex.pm/packages/ash_state_machine/0.2.7) [Hex Preview](https://preview.hex.pm/preview/ash_state_machine/0.2.7) ([current file](https://preview.hex.pm/preview/ash_state_machine/0.2.7/show/documentation/tutorials/getting-started-with-ash-state-machine.md)) Search HexDocs [Download ePub version](ash_state_machine.epub "ePub version")
1119 |
1120 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.34.2) for the [Elixir programming language](https://elixir-lang.org "Elixir")
1121 | [](https://github.com/ash-project/ash_state_machine)
1122 |
1123 | [ash\_state\_machine](https://github.com/ash-project/ash_state_machine)
1124 |
1125 | v0.2.7
1126 |
1127 | - GUIDES
1128 | - Modules
1129 | - Mix Tasks
1130 |
1131 | <!--THE END-->
1132 |
1133 | <!--THE END-->
1134 |
1135 | <!--THE END-->
1136 |
1137 | Search documentation of ash\_state\_machine
1138 |
1139 | Settings
1140 |
1141 | # [View Source](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/mix/generate_flow_charts.ex#L1 "View Source") mix ash\_state\_machine.generate\_flow\_charts (ash\_state\_machine v0.2.7)
1142 |
1143 | Generates a Mermaid Flow Chart for each [`Ash.Resource`](../ash/3.4.43/Ash.Resource.html) with the [`AshStateMachine`](AshStateMachine.html) extension alongside the resource.
1144 |
1145 | ## [](Mix.Tasks.AshStateMachine.GenerateFlowCharts.html#module-prerequisites)Prerequisites
1146 |
1147 | This mix task requires the Mermaid CLI to be installed on your system.
1148 |
1149 | See [https://github.com/mermaid-js/mermaid-cli](https://github.com/mermaid-js/mermaid-cli)
1150 |
1151 | ## [](Mix.Tasks.AshStateMachine.GenerateFlowCharts.html#module-command-line-options)Command line options
1152 |
1153 | - `--type` - generates a given type. Valid values are `"state_diagram"` and `"flow_chart"`. Defaults to `"state_diagram"`.
1154 | - `--only` - only generates the given Flow file
1155 | - `--format` - Can be set to one of either:
1156 |
1157 | - `plain` - Prints just the mermaid output as text. This is the default.
1158 | - `md` - Prints the mermaid diagram in a markdown code block.
1159 | - `svg` - Generates an SVG
1160 | - `pdf` - Generates a PDF
1161 | - `png` - Generates a PNG
1162 |
1163 | # [](Mix.Tasks.AshStateMachine.GenerateFlowCharts.html#summary)Summary
1164 |
1165 | ## [Functions](Mix.Tasks.AshStateMachine.GenerateFlowCharts.html#functions)
1166 |
1167 | [run(argv)](Mix.Tasks.AshStateMachine.GenerateFlowCharts.html#run/1)
1168 |
1169 | Callback implementation for [`Mix.Task.run/1`](../mix/Mix.Task.html#c:run/1).
1170 |
1171 | # [](Mix.Tasks.AshStateMachine.GenerateFlowCharts.html#functions)Functions
1172 |
1173 | [](Mix.Tasks.AshStateMachine.GenerateFlowCharts.html#run/1)
1174 |
1175 | # run(argv)
1176 |
1177 | [](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/lib/mix/generate_flow_charts.ex#L29)
1178 |
1179 | Callback implementation for [`Mix.Task.run/1`](../mix/Mix.Task.html#c:run/1).
1180 |
1181 | [Hex Package](https://hex.pm/packages/ash_state_machine/0.2.7) [Hex Preview](https://preview.hex.pm/preview/ash_state_machine/0.2.7) Search HexDocs [Download ePub version](ash_state_machine.epub "ePub version")
1182 |
1183 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.34.2) for the [Elixir programming language](https://elixir-lang.org "Elixir")
1184 | [](https://github.com/ash-project/ash_state_machine)
1185 |
1186 | [ash\_state\_machine](https://github.com/ash-project/ash_state_machine)
1187 |
1188 | v0.2.7
1189 |
1190 | - GUIDES
1191 | - Modules
1192 | - Mix Tasks
1193 |
1194 | <!--THE END-->
1195 |
1196 | <!--THE END-->
1197 |
1198 | <!--THE END-->
1199 |
1200 | Search documentation of ash\_state\_machine
1201 |
1202 | Settings
1203 |
1204 | # [View Source](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/README.md#L1 "View Source") Home
1205 |
1206 |  
1207 |
1208 |  [](https://opensource.org/licenses/MIT) [](https://hex.pm/packages/ash_state_machine) [](../ash_state_machine.html)
1209 |
1210 | # AshStateMachine
1211 |
1212 | Welcome! This is the extension for building state machines with [Ash](../ash_state_machine.html) resources.
1213 |
1214 | ## [](readme.html#tutorials)Tutorials
1215 |
1216 | - [Getting Started with AshStateMachine](getting-started-with-ash-state-machine.html)
1217 |
1218 | ## [](readme.html#topics)Topics
1219 |
1220 | - [What is AshStateMachine?](what-is-ash-state-machine.html)
1221 | - [Charts](charts.html)
1222 | - [Working with `Ash.can?`](working-with-ash-can.html)
1223 |
1224 | ## [](readme.html#reference)Reference
1225 |
1226 | - [AshStateMachine DSL](dsl-ashstatemachine.html)
1227 |
1228 | [← Previous Page API Reference](api-reference.html)
1229 |
1230 | [Next Page → Getting Started with State Machines](getting-started-with-ash-state-machine.html)
1231 |
1232 | [Hex Package](https://hex.pm/packages/ash_state_machine/0.2.7) [Hex Preview](https://preview.hex.pm/preview/ash_state_machine/0.2.7) ([current file](https://preview.hex.pm/preview/ash_state_machine/0.2.7/show/README.md)) Search HexDocs [Download ePub version](ash_state_machine.epub "ePub version")
1233 |
1234 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.34.2) for the [Elixir programming language](https://elixir-lang.org "Elixir")
1235 | [](https://github.com/ash-project/ash_state_machine)
1236 |
1237 | [ash\_state\_machine](https://github.com/ash-project/ash_state_machine)
1238 |
1239 | v0.2.7
1240 |
1241 | - GUIDES
1242 | - Modules
1243 | - Mix Tasks
1244 |
1245 | <!--THE END-->
1246 |
1247 | <!--THE END-->
1248 |
1249 | <!--THE END-->
1250 |
1251 | Search documentation of ash\_state\_machine
1252 |
1253 | Settings
1254 |
1255 | # [View Source](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/documentation/topics/what-is-ash-state-machine.md#L1 "View Source") What is AshStateMachine?
1256 |
1257 | ## [](what-is-ash-state-machine.html#what-is-a-state-machine)What is a State Machine?
1258 |
1259 | A state machine is a program who's purpose is to manage an internal "state". The simplest example of a state machine could be a program representing a light switch. A light switch might have two states, "on" and "off". You can transition from "on" to "off", and back.
1260 |
1261 | ```
1262 | classDiagram
1263 |
1264 | class Switch {
1265 | state on | off
1266 | turnOn() off -> on
1267 | turnOff() on -> off
1268 | }
1269 | ```
1270 |
1271 | To build state machines with [`Ash.Resource`](../ash/3.4.43/Ash.Resource.html), we use [`AshStateMachine`](../ash_state_machine.html).
1272 |
1273 | When we refer to "state machines" in AshStateMachine, we're referring to a specific type of state machine known as a "Finite State Machine". It is "finite", because there are a statically known list of states that the machine may be in at any time, just like the `Switch` example above.
1274 |
1275 | ### [](what-is-ash-state-machine.html#why-should-we-use-state-machines)Why should we use state machines?
1276 |
1277 | #### Flexible
1278 |
1279 | State machines are a *simple* and *powerful* way to represent complex workflows. They are flexible to modifications over time by adding new states, or new transitions between states.
1280 |
1281 | #### Migrateable
1282 |
1283 | State machines typically contain additional data about the state that they are in, or past states that they have been in, and this state must be migrated over time. When representing data as state machines, it becomes simple to do things like "update all `package` records that are in the `pending_shipment` state".
1284 |
1285 | #### Easy to reason about for humans
1286 |
1287 | State machines, when compared to things like workflows, are easy for people to reason about. We have an intuition for things like "the package is currently `on_its_way`, with a `current_location` of New York, New York", or "your package is now `out_for_delivery` with an ETA of 6PM".
1288 |
1289 | #### Compatible with any storage mechanism
1290 |
1291 | Since state machines are backed by simple state, you can often avoid any fancy workflow runners or complex storage mechanisms. You can store them in a database table, a json blob, a CSV file, at the end of the day its just a `:state` field and accompanying additional fields.
1292 |
1293 | ## [](what-is-ash-state-machine.html#what-does-ashstatemachine-do-differently-than-other-implementations)What does AshStateMachine do differently than other implementations?
1294 |
1295 | AshStateMachine is an [`Ash.Resource`](../ash/Ash.Resource.html) extension, meaning it *enhances a resource* with state machine capabilities. In [`Ash`](../ash/3.4.43/Ash.html), all modifications go through [*actions*](https://hexdocs.pm/ash_state_machine/actions.html). In accordance with this, [`AshStateMachine`](AshStateMachine.html) offers a DSL for declaring *valid states and transitions*, but does not, itself, *perform* those transitions. You will use a change called `transition_state/1` in an action to move from one state to the other. For more, check out the [CookBook](../ash/readme.html#cookbook)
1296 |
1297 | [← Previous Page Getting Started with State Machines](getting-started-with-ash-state-machine.html)
1298 |
1299 | [Next Page → Charts](charts.html)
1300 |
1301 | [Hex Package](https://hex.pm/packages/ash_state_machine/0.2.7) [Hex Preview](https://preview.hex.pm/preview/ash_state_machine/0.2.7) ([current file](https://preview.hex.pm/preview/ash_state_machine/0.2.7/show/documentation/topics/what-is-ash-state-machine.md)) Search HexDocs [Download ePub version](ash_state_machine.epub "ePub version")
1302 |
1303 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.34.2) for the [Elixir programming language](https://elixir-lang.org "Elixir")
1304 | [](https://github.com/ash-project/ash_state_machine)
1305 |
1306 | [ash\_state\_machine](https://github.com/ash-project/ash_state_machine)
1307 |
1308 | v0.2.7
1309 |
1310 | - GUIDES
1311 | - Modules
1312 | - Mix Tasks
1313 |
1314 | <!--THE END-->
1315 |
1316 | <!--THE END-->
1317 |
1318 | <!--THE END-->
1319 |
1320 | Search documentation of ash\_state\_machine
1321 |
1322 | Settings
1323 |
1324 | # [View Source](https://github.com/ash-project/ash_state_machine/blob/v0.2.7/documentation/topics/working-with-ash-can.md#L1 "View Source") Working with `Ash.can?`
1325 |
1326 | Using [`Ash.can?/3`](../ash/3.4.43/Ash.html#can?/3) won't return `false` if a given state machine transition is invalid. This is because [`Ash.can?/3`](../ash/3.4.43/Ash.html#can?/3) is only concerned with policies, not changes/validations. However, many folks use [`Ash.can?/3`](../ash/3.4.43/Ash.html#can?/3) in their UI to determine whether a given button/form/etc should be shown. To help with this you can add the following to your resource:
1327 |
1328 | ```
1329 | policies do
1330 | policy always() do
1331 | authorize_if AshStateMachine.Checks.ValidNextState
1332 | end
1333 | end
1334 | ```
1335 |
1336 | This check is only used in *pre\_flight* authorization checks (i.e calling [`Ash.can?/3`](../ash/3.4.43/Ash.html#can?/3)), but it will return `true` in all cases when running real authorization checks. This is because the change is validated when you use the `transition_state/1` change and [`AshStateMachine.transition_state/2`](AshStateMachine.html#transition_state/2), and so you would be doing extra work for no reason.
1337 |
1338 | [← Previous Page Charts](charts.html)
1339 |
1340 | [Next Page → DSL: AshStateMachine](dsl-ashstatemachine.html)
1341 |
1342 | [Hex Package](https://hex.pm/packages/ash_state_machine/0.2.7) [Hex Preview](https://preview.hex.pm/preview/ash_state_machine/0.2.7) ([current file](https://preview.hex.pm/preview/ash_state_machine/0.2.7/show/documentation/topics/working-with-ash-can.md)) Search HexDocs [Download ePub version](ash_state_machine.epub "ePub version")
1343 |
1344 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.34.2) for the [Elixir programming language](https://elixir-lang.org "Elixir")
1345 |
```
--------------------------------------------------------------------------------
/test/docs/ash-docs/ash_oban.md:
--------------------------------------------------------------------------------
```markdown
1 | [](https://github.com/ash-project/ash_oban)
2 |
3 | [ash\_oban](https://github.com/ash-project/ash_oban)
4 |
5 | v0.2.6
6 |
7 | - GUIDES
8 | - Modules
9 |
10 | <!--THE END-->
11 |
12 | <!--THE END-->
13 |
14 | Search documentation of ash\_oban
15 |
16 | Settings
17 |
18 | # [View Source](https://github.com/ash-project/ash_oban "View Source") API Reference ash\_oban v0.2.6
19 |
20 | ## [](api-reference.html#modules)Modules
21 |
22 | [AshOban](AshOban.html)
23 |
24 | Tools for working with AshOban triggers.
25 |
26 | [AshOban.ActorPersister](AshOban.ActorPersister.html)
27 |
28 | A behaviour for storing and retrieving an actor from oban job arguments
29 |
30 | [AshOban.Changes.BuiltinChanges](AshOban.Changes.BuiltinChanges.html)
31 |
32 | Builtin changes for [`AshOban`](AshOban.html)
33 |
34 | [AshOban.Changes.RunObanTrigger](AshOban.Changes.RunObanTrigger.html)
35 |
36 | Runs an oban trigger by name.
37 |
38 | [AshOban.Checks.AshObanInteraction](AshOban.Checks.AshObanInteraction.html)
39 |
40 | This check is true if the context `private.ash_oban?` is set to true.
41 |
42 | [AshOban.Errors.TriggerNoLongerApplies](AshOban.Errors.TriggerNoLongerApplies.html)
43 |
44 | Used when an invalid value is provided for an action argument
45 |
46 | [AshOban.Info](AshOban.Info.html)
47 |
48 | Introspection for AshOban
49 |
50 | [AshOban.Schedule](AshOban.Schedule.html)
51 |
52 | A configured scheduled action.
53 |
54 | [AshOban.Test](AshOban.Test.html)
55 |
56 | Helpers for testing ash\_oban triggers
57 |
58 | [AshOban.Trigger](AshOban.Trigger.html)
59 |
60 | A configured trigger.
61 |
62 | [Next Page → Home](readme.html)
63 |
64 | [Hex Package](https://hex.pm/packages/ash_oban/0.2.6) [Hex Preview](https://preview.hex.pm/preview/ash_oban/0.2.6) Search HexDocs [Download ePub version](ash_oban.epub "ePub version")
65 |
66 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.34.2) for the [Elixir programming language](https://elixir-lang.org "Elixir")
67 | [](https://github.com/ash-project/ash_oban)
68 |
69 | [ash\_oban](https://github.com/ash-project/ash_oban)
70 |
71 | v0.2.6
72 |
73 | - GUIDES
74 | - Modules
75 |
76 | <!--THE END-->
77 |
78 | <!--THE END-->
79 |
80 | Search documentation of ash\_oban
81 |
82 | Settings
83 |
84 | # [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/actor_persister.ex#L1 "View Source") AshOban.ActorPersister behaviour (ash\_oban v0.2.6)
85 |
86 | A behaviour for storing and retrieving an actor from oban job arguments
87 |
88 | # [](AshOban.ActorPersister.html#summary)Summary
89 |
90 | ## [Types](AshOban.ActorPersister.html#types)
91 |
92 | [actor()](AshOban.ActorPersister.html#t:actor/0)
93 |
94 | [actor\_json()](AshOban.ActorPersister.html#t:actor_json/0)
95 |
96 | ## [Callbacks](AshOban.ActorPersister.html#callbacks)
97 |
98 | [lookup(actor\_json)](AshOban.ActorPersister.html#c:lookup/1)
99 |
100 | [store(actor)](AshOban.ActorPersister.html#c:store/1)
101 |
102 | # [](AshOban.ActorPersister.html#types)Types
103 |
104 | [Link to this type](AshOban.ActorPersister.html#t:actor/0 "Link to this type")
105 |
106 | # actor()
107 |
108 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/actor_persister.ex#L6 "View Source")
109 |
110 | ```
111 | @type actor() :: any()
112 | ```
113 |
114 | [Link to this type](AshOban.ActorPersister.html#t:actor_json/0 "Link to this type")
115 |
116 | # actor\_json()
117 |
118 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/actor_persister.ex#L5 "View Source")
119 |
120 | ```
121 | @type actor_json() :: any()
122 | ```
123 |
124 | # [](AshOban.ActorPersister.html#callbacks)Callbacks
125 |
126 | [Link to this callback](AshOban.ActorPersister.html#c:lookup/1 "Link to this callback")
127 |
128 | # lookup(actor\_json)
129 |
130 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/actor_persister.ex#L9 "View Source")
131 |
132 | ```
133 | @callback lookup(actor_json :: actor_json() | nil) ::
134 | {:ok, actor() | nil} | {:error, Ash.Error.t()}
135 | ```
136 |
137 | [Link to this callback](AshOban.ActorPersister.html#c:store/1 "Link to this callback")
138 |
139 | # store(actor)
140 |
141 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/actor_persister.ex#L8 "View Source")
142 |
143 | ```
144 | @callback store(actor :: actor()) :: actor_json :: actor_json()
145 | ```
146 |
147 | [Hex Package](https://hex.pm/packages/ash_oban/0.2.6) [Hex Preview](https://preview.hex.pm/preview/ash_oban/0.2.6) Search HexDocs [Download ePub version](ash_oban.epub "ePub version")
148 |
149 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.34.2) for the [Elixir programming language](https://elixir-lang.org "Elixir")
150 | [](https://github.com/ash-project/ash_oban)
151 |
152 | [ash\_oban](https://github.com/ash-project/ash_oban)
153 |
154 | v0.2.6
155 |
156 | - GUIDES
157 | - Modules
158 |
159 | <!--THE END-->
160 |
161 | <!--THE END-->
162 |
163 | Search documentation of ash\_oban
164 |
165 | Settings
166 |
167 | # [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/changes/builtin_changes.ex#L1 "View Source") AshOban.Changes.BuiltinChanges (ash\_oban v0.2.6)
168 |
169 | Builtin changes for [`AshOban`](AshOban.html)
170 |
171 | # [](AshOban.Changes.BuiltinChanges.html#summary)Summary
172 |
173 | ## [Functions](AshOban.Changes.BuiltinChanges.html#functions)
174 |
175 | [run\_oban\_trigger(trigger\_name, oban\_job\_opts \\\\ \[\])](AshOban.Changes.BuiltinChanges.html#run_oban_trigger/2)
176 |
177 | # [](AshOban.Changes.BuiltinChanges.html#functions)Functions
178 |
179 | [Link to this function](AshOban.Changes.BuiltinChanges.html#run_oban_trigger/2 "Link to this function")
180 |
181 | # run\_oban\_trigger(trigger\_name, oban\_job\_opts \\\\ \[])
182 |
183 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/changes/builtin_changes.ex#L4 "View Source")
184 |
185 | [Hex Package](https://hex.pm/packages/ash_oban/0.2.6) [Hex Preview](https://preview.hex.pm/preview/ash_oban/0.2.6) Search HexDocs [Download ePub version](ash_oban.epub "ePub version")
186 |
187 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.34.2) for the [Elixir programming language](https://elixir-lang.org "Elixir")
188 | [](https://github.com/ash-project/ash_oban)
189 |
190 | [ash\_oban](https://github.com/ash-project/ash_oban)
191 |
192 | v0.2.6
193 |
194 | - GUIDES
195 | - Modules
196 |
197 | <!--THE END-->
198 |
199 | <!--THE END-->
200 |
201 | Search documentation of ash\_oban
202 |
203 | Settings
204 |
205 | # [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/changes/run_oban_trigger.ex#L1 "View Source") AshOban.Changes.RunObanTrigger (ash\_oban v0.2.6)
206 |
207 | Runs an oban trigger by name.
208 |
209 | # [](AshOban.Changes.RunObanTrigger.html#summary)Summary
210 |
211 | ## [Functions](AshOban.Changes.RunObanTrigger.html#functions)
212 |
213 | [change(changeset, opts, context)](AshOban.Changes.RunObanTrigger.html#change/3)
214 |
215 | Callback implementation for [`Ash.Resource.Change.change/3`](../ash/3.4.37/Ash.Resource.Change.html#c:change/3).
216 |
217 | # [](AshOban.Changes.RunObanTrigger.html#functions)Functions
218 |
219 | [Link to this function](AshOban.Changes.RunObanTrigger.html#change/3 "Link to this function")
220 |
221 | # change(changeset, opts, context)
222 |
223 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/changes/run_oban_trigger.ex#L8 "View Source")
224 |
225 | Callback implementation for [`Ash.Resource.Change.change/3`](../ash/3.4.37/Ash.Resource.Change.html#c:change/3).
226 |
227 | [Hex Package](https://hex.pm/packages/ash_oban/0.2.6) [Hex Preview](https://preview.hex.pm/preview/ash_oban/0.2.6) Search HexDocs [Download ePub version](ash_oban.epub "ePub version")
228 |
229 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.34.2) for the [Elixir programming language](https://elixir-lang.org "Elixir")
230 | [](https://github.com/ash-project/ash_oban)
231 |
232 | [ash\_oban](https://github.com/ash-project/ash_oban)
233 |
234 | v0.2.6
235 |
236 | - GUIDES
237 | - Modules
238 |
239 | <!--THE END-->
240 |
241 | <!--THE END-->
242 |
243 | Search documentation of ash\_oban
244 |
245 | Settings
246 |
247 | # [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/checks/ash_oban_interaction.ex#L1 "View Source") AshOban.Checks.AshObanInteraction (ash\_oban v0.2.6)
248 |
249 | This check is true if the context `private.ash_oban?` is set to true.
250 |
251 | This context will only ever be set in code that is called internally by `ash_oban`, allowing you to create a bypass in your policies on your user/user\_token resources.
252 |
253 | ```
254 | policies do
255 | bypass AshObanInteraction do
256 | authorize_if always()
257 | end
258 | end
259 | ```
260 |
261 | # [](AshOban.Checks.AshObanInteraction.html#summary)Summary
262 |
263 | ## [Functions](AshOban.Checks.AshObanInteraction.html#functions)
264 |
265 | [eager\_evaluate?()](AshOban.Checks.AshObanInteraction.html#eager_evaluate?/0)
266 |
267 | Callback implementation for [`Ash.Policy.Check.eager_evaluate?/0`](../ash/3.4.37/Ash.Policy.Check.html#c:eager_evaluate?/0).
268 |
269 | [prefer\_expanded\_description?()](AshOban.Checks.AshObanInteraction.html#prefer_expanded_description?/0)
270 |
271 | Callback implementation for [`Ash.Policy.Check.prefer_expanded_description?/0`](../ash/3.4.37/Ash.Policy.Check.html#c:prefer_expanded_description?/0).
272 |
273 | [requires\_original\_data?(\_, \_)](AshOban.Checks.AshObanInteraction.html#requires_original_data?/2)
274 |
275 | Callback implementation for [`Ash.Policy.Check.requires_original_data?/2`](../ash/3.4.37/Ash.Policy.Check.html#c:requires_original_data?/2).
276 |
277 | [strict\_check(actor, context, opts)](AshOban.Checks.AshObanInteraction.html#strict_check/3)
278 |
279 | Callback implementation for [`Ash.Policy.Check.strict_check/3`](../ash/3.4.37/Ash.Policy.Check.html#c:strict_check/3).
280 |
281 | [type()](AshOban.Checks.AshObanInteraction.html#type/0)
282 |
283 | Callback implementation for [`Ash.Policy.Check.type/0`](../ash/3.4.37/Ash.Policy.Check.html#c:type/0).
284 |
285 | # [](AshOban.Checks.AshObanInteraction.html#functions)Functions
286 |
287 | [Link to this function](AshOban.Checks.AshObanInteraction.html#eager_evaluate?/0 "Link to this function")
288 |
289 | # eager\_evaluate?()
290 |
291 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/checks/ash_oban_interaction.ex#L17 "View Source")
292 |
293 | Callback implementation for [`Ash.Policy.Check.eager_evaluate?/0`](../ash/3.4.37/Ash.Policy.Check.html#c:eager_evaluate?/0).
294 |
295 | [Link to this function](AshOban.Checks.AshObanInteraction.html#prefer_expanded_description?/0 "Link to this function")
296 |
297 | # prefer\_expanded\_description?()
298 |
299 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/checks/ash_oban_interaction.ex#L17 "View Source")
300 |
301 | Callback implementation for [`Ash.Policy.Check.prefer_expanded_description?/0`](../ash/3.4.37/Ash.Policy.Check.html#c:prefer_expanded_description?/0).
302 |
303 | [Link to this function](AshOban.Checks.AshObanInteraction.html#requires_original_data?/2 "Link to this function")
304 |
305 | # requires\_original\_data?(\_, \_)
306 |
307 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/checks/ash_oban_interaction.ex#L17 "View Source")
308 |
309 | Callback implementation for [`Ash.Policy.Check.requires_original_data?/2`](../ash/3.4.37/Ash.Policy.Check.html#c:requires_original_data?/2).
310 |
311 | [Link to this function](AshOban.Checks.AshObanInteraction.html#strict_check/3 "Link to this function")
312 |
313 | # strict\_check(actor, context, opts)
314 |
315 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/checks/ash_oban_interaction.ex#L17 "View Source")
316 |
317 | Callback implementation for [`Ash.Policy.Check.strict_check/3`](../ash/3.4.37/Ash.Policy.Check.html#c:strict_check/3).
318 |
319 | [Link to this function](AshOban.Checks.AshObanInteraction.html#type/0 "Link to this function")
320 |
321 | # type()
322 |
323 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/checks/ash_oban_interaction.ex#L17 "View Source")
324 |
325 | Callback implementation for [`Ash.Policy.Check.type/0`](../ash/3.4.37/Ash.Policy.Check.html#c:type/0).
326 |
327 | [Hex Package](https://hex.pm/packages/ash_oban/0.2.6) [Hex Preview](https://preview.hex.pm/preview/ash_oban/0.2.6) Search HexDocs [Download ePub version](ash_oban.epub "ePub version")
328 |
329 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.34.2) for the [Elixir programming language](https://elixir-lang.org "Elixir")
330 | [](https://github.com/ash-project/ash_oban)
331 |
332 | [ash\_oban](https://github.com/ash-project/ash_oban)
333 |
334 | v0.2.6
335 |
336 | - GUIDES
337 | - Modules
338 |
339 | <!--THE END-->
340 |
341 | <!--THE END-->
342 |
343 | Search documentation of ash\_oban
344 |
345 | Settings
346 |
347 | # [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/errors/trigger_no_longer_applies.ex#L1 "View Source") AshOban.Errors.TriggerNoLongerApplies exception (ash\_oban v0.2.6)
348 |
349 | Used when an invalid value is provided for an action argument
350 |
351 | # [](AshOban.Errors.TriggerNoLongerApplies.html#summary)Summary
352 |
353 | ## [Functions](AshOban.Errors.TriggerNoLongerApplies.html#functions)
354 |
355 | [exception()](AshOban.Errors.TriggerNoLongerApplies.html#exception/0)
356 |
357 | # [](AshOban.Errors.TriggerNoLongerApplies.html#functions)Functions
358 |
359 | [Link to this function](AshOban.Errors.TriggerNoLongerApplies.html#exception/0 "Link to this function")
360 |
361 | # exception()
362 |
363 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/errors/trigger_no_longer_applies.ex#L3 "View Source")
364 |
365 | [Hex Package](https://hex.pm/packages/ash_oban/0.2.6) [Hex Preview](https://preview.hex.pm/preview/ash_oban/0.2.6) Search HexDocs [Download ePub version](ash_oban.epub "ePub version")
366 |
367 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.34.2) for the [Elixir programming language](https://elixir-lang.org "Elixir")
368 | [](https://github.com/ash-project/ash_oban)
369 |
370 | [ash\_oban](https://github.com/ash-project/ash_oban)
371 |
372 | v0.2.6
373 |
374 | - GUIDES
375 | - Modules
376 |
377 | <!--THE END-->
378 |
379 | <!--THE END-->
380 |
381 | Search documentation of ash\_oban
382 |
383 | Settings
384 |
385 | # [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/ash_oban.ex#L1 "View Source") AshOban (ash\_oban v0.2.6)
386 |
387 | Tools for working with AshOban triggers.
388 |
389 | # [](AshOban.html#summary)Summary
390 |
391 | ## [Types](AshOban.html#types)
392 |
393 | [result()](AshOban.html#t:result/0)
394 |
395 | [triggerable()](AshOban.html#t:triggerable/0)
396 |
397 | ## [Functions](AshOban.html#functions)
398 |
399 | [authorize?()](AshOban.html#authorize?/0)
400 |
401 | [build\_trigger(record, trigger, opts \\\\ \[\])](AshOban.html#build_trigger/3)
402 |
403 | Builds a specific trigger for the record provided, but does not insert it into the database.
404 |
405 | [config(domains, base, opts \\\\ \[\])](AshOban.html#config/3)
406 |
407 | Alters your oban configuration to include the required AshOban configuration.
408 |
409 | [do\_schedule\_and\_run\_triggers(resources\_or\_domains\_or\_otp\_apps, opts)](AshOban.html#do_schedule_and_run_triggers/2)
410 |
411 | [lookup\_actor(actor\_json)](AshOban.html#lookup_actor/1)
412 |
413 | [oban(body)](AshOban.html#oban/1)
414 |
415 | [run\_trigger(record, trigger, opts \\\\ \[\])](AshOban.html#run_trigger/3)
416 |
417 | Runs a specific trigger for the record provided.
418 |
419 | [schedule(resource, trigger, opts \\\\ \[\])](AshOban.html#schedule/3)
420 |
421 | Schedules all relevant jobs for the provided trigger or scheduled action
422 |
423 | [schedule\_and\_run\_triggers(resources\_or\_domains\_or\_otp\_apps, opts \\\\ \[\])](AshOban.html#schedule_and_run_triggers/2)
424 |
425 | Runs the schedulers for the given resource, domain, or otp\_app, or list of resources, domains, or otp\_apps.
426 |
427 | [stacktrace(arg1)](AshOban.html#stacktrace/1)
428 |
429 | [store\_actor(args, actor)](AshOban.html#store_actor/2)
430 |
431 | # [](AshOban.html#types)Types
432 |
433 | [Link to this type](AshOban.html#t:result/0 "Link to this type")
434 |
435 | # result()
436 |
437 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/ash_oban.ex#L372 "View Source")
438 |
439 | ```
440 | @type result() :: %{
441 | discard: non_neg_integer(),
442 | cancelled: non_neg_integer(),
443 | success: non_neg_integer(),
444 | failure: non_neg_integer(),
445 | snoozed: non_neg_integer(),
446 | queues_not_drained: [atom()]
447 | }
448 | ```
449 |
450 | [Link to this type](AshOban.html#t:triggerable/0 "Link to this type")
451 |
452 | # triggerable()
453 |
454 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/ash_oban.ex#L371 "View Source")
455 |
456 | ```
457 | @type triggerable() ::
458 | Ash.Resource.t() | {Ash.Resource.t(), atom()} | Ash.Domain.t() | atom()
459 | ```
460 |
461 | # [](AshOban.html#functions)Functions
462 |
463 | [Link to this function](AshOban.html#authorize?/0 "Link to this function")
464 |
465 | # authorize?()
466 |
467 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/ash_oban.ex#L416 "View Source")
468 |
469 | ```
470 | @spec authorize?() :: boolean()
471 | ```
472 |
473 | [Link to this function](AshOban.html#build_trigger/3 "Link to this function")
474 |
475 | # build\_trigger(record, trigger, opts \\\\ \[])
476 |
477 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/ash_oban.ex#L474 "View Source")
478 |
479 | Builds a specific trigger for the record provided, but does not insert it into the database.
480 |
481 | ## [](AshOban.html#build_trigger/3-options)Options
482 |
483 | - `:actor` - the actor to set on the job. Requires configuring an actor persister.
484 | - `:action_arguments` - additional arguments to merge into the action invocation's arguments map. affects the uniqueness checks for the job.
485 | - `:args` - additional arguments to merge into the job's arguments map. the action will not use these arguments, it can only be used to affect the job uniqueness checks. you likely are looking for the `:action_arguments` job.
486 |
487 | All other options are passed through to [`Oban.Worker.new/2`](../oban/2.18.3/Oban.Worker.html#c:new/2)
488 |
489 | [Link to this function](AshOban.html#config/3 "Link to this function")
490 |
491 | # config(domains, base, opts \\\\ \[])
492 |
493 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/ash_oban.ex#L542 "View Source")
494 |
495 | Alters your oban configuration to include the required AshOban configuration.
496 |
497 | # Options
498 |
499 | - `:require?` ([`boolean/0`](../elixir/typespecs.html#built-in-types)) - Whether to require queues and plugins to be defined in your oban config. This can be helpful to allow the ability to split queues between nodes. See [https://hexdocs.pm/oban/splitting-queues.html](../oban/splitting-queues.html) The default value is `true`.
500 |
501 | [Link to this function](AshOban.html#do_schedule_and_run_triggers/2 "Link to this function")
502 |
503 | # do\_schedule\_and\_run\_triggers(resources\_or\_domains\_or\_otp\_apps, opts)
504 |
505 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/ash_oban.ex#L802 "View Source")
506 |
507 | [Link to this function](AshOban.html#lookup_actor/1 "Link to this function")
508 |
509 | # lookup\_actor(actor\_json)
510 |
511 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/ash_oban.ex#L434 "View Source")
512 |
513 | ```
514 | @spec lookup_actor(actor_json :: any()) :: any()
515 | ```
516 |
517 | [Link to this macro](AshOban.html#oban/1 "Link to this macro")
518 |
519 | # oban(body)
520 |
521 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/ash_oban.ex#L362 "View Source") (macro)
522 |
523 | [Link to this function](AshOban.html#run_trigger/3 "Link to this function")
524 |
525 | # run\_trigger(record, trigger, opts \\\\ \[])
526 |
527 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/ash_oban.ex#L454 "View Source")
528 |
529 | Runs a specific trigger for the record provided.
530 |
531 | ## [](AshOban.html#run_trigger/3-options)Options
532 |
533 | - `:actor` - the actor to set on the job. Requires configuring an actor persister.
534 | - `:args` - additional arguments to merge into the job's arguments map.
535 |
536 | All other options are passed through to [`Oban.Worker.new/2`](../oban/2.18.3/Oban.Worker.html#c:new/2)
537 |
538 | [Link to this function](AshOban.html#schedule/3 "Link to this function")
539 |
540 | # schedule(resource, trigger, opts \\\\ \[])
541 |
542 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/ash_oban.ex#L388 "View Source")
543 |
544 | Schedules all relevant jobs for the provided trigger or scheduled action
545 |
546 | ## [](AshOban.html#schedule/3-options)Options
547 |
548 | `:actor` - the actor to set on the job. Requires configuring an actor persister.
549 |
550 | [Link to this function](AshOban.html#schedule_and_run_triggers/2 "Link to this function")
551 |
552 | # schedule\_and\_run\_triggers(resources\_or\_domains\_or\_otp\_apps, opts \\\\ \[])
553 |
554 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/ash_oban.ex#L791 "View Source")
555 |
556 | ```
557 | @spec schedule_and_run_triggers(
558 | triggerable() | [triggerable()],
559 | keyword()
560 | ) :: result()
561 | ```
562 |
563 | Runs the schedulers for the given resource, domain, or otp\_app, or list of resources, domains, or otp\_apps.
564 |
565 | Options:
566 |
567 | - `drain_queues?` - Defaults to false, drains the queues after scheduling. This is primarily for testing
568 | - `queue`, `with_limit`, `with_recursion`, `with_safety`, `with_scheduled` - passed through to [`Oban.drain_queue/2`](../oban/2.18.3/Oban.html#drain_queue/2), if it is called
569 | - `scheduled_actions?` - Defaults to false, unless a scheduled action name was explicitly provided. Schedules all applicable scheduled actions.
570 | - `triggers?` - Defaults to true, schedules all applicable scheduled actions.
571 | - `actor` - The actor to schedule and run the triggers with
572 | - `oban` - The oban module to use. Defaults to [`Oban`](../oban/2.18.3/Oban.html)
573 |
574 | If the input is:
575 |
576 | - a list - each item is passed into [`schedule_and_run_triggers/1`](AshOban.html#schedule_and_run_triggers/1), and the results are merged together.
577 | - an otp\_app - each domain configured in the `ash_domains` of that otp\_app is passed into [`schedule_and_run_triggers/1`](AshOban.html#schedule_and_run_triggers/1), and the results are merged together.
578 | - a domain - each reosurce configured in that domain is passed into [`schedule_and_run_triggers/1`](AshOban.html#schedule_and_run_triggers/1), and the results are merged together.
579 | - a tuple of {resource, :trigger\_name} - that trigger is scheduled, and the results are merged together.
580 | - a resource - each trigger configured in that resource is scheduled, and the results are merged together.
581 |
582 | [Link to this function](AshOban.html#stacktrace/1 "Link to this function")
583 |
584 | # stacktrace(arg1)
585 |
586 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/ash_oban.ex#L765 "View Source")
587 |
588 | [Link to this function](AshOban.html#store_actor/2 "Link to this function")
589 |
590 | # store\_actor(args, actor)
591 |
592 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/ash_oban.ex#L421 "View Source")
593 |
594 | ```
595 | @spec store_actor(args :: map(), actor :: any()) :: any()
596 | ```
597 |
598 | [Hex Package](https://hex.pm/packages/ash_oban/0.2.6) [Hex Preview](https://preview.hex.pm/preview/ash_oban/0.2.6) Search HexDocs [Download ePub version](ash_oban.epub "ePub version")
599 |
600 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.34.2) for the [Elixir programming language](https://elixir-lang.org "Elixir")
601 | [](https://github.com/ash-project/ash_oban)
602 |
603 | [ash\_oban](https://github.com/ash-project/ash_oban)
604 |
605 | v0.2.6
606 |
607 | - GUIDES
608 | - Modules
609 |
610 | <!--THE END-->
611 |
612 | <!--THE END-->
613 |
614 | Search documentation of ash\_oban
615 |
616 | Settings
617 |
618 | # [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/info.ex#L1 "View Source") AshOban.Info (ash\_oban v0.2.6)
619 |
620 | Introspection for AshOban
621 |
622 | # [](AshOban.Info.html#summary)Summary
623 |
624 | ## [Functions](AshOban.Info.html#functions)
625 |
626 | [oban\_domain(dsl\_or\_extended)](AshOban.Info.html#oban_domain/1)
627 |
628 | The Domain to use when calling actions on this resource. Defaults to the resource's domain.
629 |
630 | [oban\_domain!(dsl\_or\_extended)](AshOban.Info.html#oban_domain!/1)
631 |
632 | The Domain to use when calling actions on this resource. Defaults to the resource's domain.
633 |
634 | [oban\_options(dsl\_or\_extended)](AshOban.Info.html#oban_options/1)
635 |
636 | oban DSL options
637 |
638 | [oban\_scheduled\_action(resource, name)](AshOban.Info.html#oban_scheduled_action/2)
639 |
640 | [oban\_scheduled\_actions(dsl\_or\_extended)](AshOban.Info.html#oban_scheduled_actions/1)
641 |
642 | oban.scheduled\_actions DSL entities
643 |
644 | [oban\_trigger(resource, name)](AshOban.Info.html#oban_trigger/2)
645 |
646 | [oban\_triggers(dsl\_or\_extended)](AshOban.Info.html#oban_triggers/1)
647 |
648 | oban.triggers DSL entities
649 |
650 | [oban\_triggers\_and\_scheduled\_actions(resource)](AshOban.Info.html#oban_triggers_and_scheduled_actions/1)
651 |
652 | [pro?()](AshOban.Info.html#pro?/0)
653 |
654 | # [](AshOban.Info.html#functions)Functions
655 |
656 | [Link to this function](AshOban.Info.html#oban_domain/1 "Link to this function")
657 |
658 | # oban\_domain(dsl\_or\_extended)
659 |
660 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/info.ex#L4 "View Source")
661 |
662 | ```
663 | @spec oban_domain(dsl_or_extended :: module() | map()) :: {:ok, module()} | :error
664 | ```
665 |
666 | The Domain to use when calling actions on this resource. Defaults to the resource's domain.
667 |
668 | [Link to this function](AshOban.Info.html#oban_domain!/1 "Link to this function")
669 |
670 | # oban\_domain!(dsl\_or\_extended)
671 |
672 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/info.ex#L4 "View Source")
673 |
674 | ```
675 | @spec oban_domain!(dsl_or_extended :: module() | map()) :: module() | no_return()
676 | ```
677 |
678 | The Domain to use when calling actions on this resource. Defaults to the resource's domain.
679 |
680 | [Link to this function](AshOban.Info.html#oban_options/1 "Link to this function")
681 |
682 | # oban\_options(dsl\_or\_extended)
683 |
684 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/info.ex#L4 "View Source")
685 |
686 | ```
687 | @spec oban_options(dsl_or_extended :: module() | map()) :: %{
688 | required(atom()) => any()
689 | }
690 | ```
691 |
692 | oban DSL options
693 |
694 | Returns a map containing the and any configured or default values.
695 |
696 | [Link to this function](AshOban.Info.html#oban_scheduled_action/2 "Link to this function")
697 |
698 | # oban\_scheduled\_action(resource, name)
699 |
700 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/info.ex#L18 "View Source")
701 |
702 | ```
703 | @spec oban_scheduled_action(Ash.Resource.t() | Spark.Dsl.t(), atom()) ::
704 | nil | AshOban.Schedule.t()
705 | ```
706 |
707 | [Link to this function](AshOban.Info.html#oban_scheduled_actions/1 "Link to this function")
708 |
709 | # oban\_scheduled\_actions(dsl\_or\_extended)
710 |
711 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/info.ex#L4 "View Source")
712 |
713 | ```
714 | @spec oban_scheduled_actions(dsl_or_extended :: module() | map()) :: [struct()]
715 | ```
716 |
717 | oban.scheduled\_actions DSL entities
718 |
719 | [Link to this function](AshOban.Info.html#oban_trigger/2 "Link to this function")
720 |
721 | # oban\_trigger(resource, name)
722 |
723 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/info.ex#L10 "View Source")
724 |
725 | ```
726 | @spec oban_trigger(Ash.Resource.t() | Spark.Dsl.t(), atom()) ::
727 | nil | AshOban.Trigger.t()
728 | ```
729 |
730 | [Link to this function](AshOban.Info.html#oban_triggers/1 "Link to this function")
731 |
732 | # oban\_triggers(dsl\_or\_extended)
733 |
734 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/info.ex#L4 "View Source")
735 |
736 | ```
737 | @spec oban_triggers(dsl_or_extended :: module() | map()) :: [struct()]
738 | ```
739 |
740 | oban.triggers DSL entities
741 |
742 | [Link to this function](AshOban.Info.html#oban_triggers_and_scheduled_actions/1 "Link to this function")
743 |
744 | # oban\_triggers\_and\_scheduled\_actions(resource)
745 |
746 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/info.ex#L28 "View Source")
747 |
748 | ```
749 | @spec oban_triggers_and_scheduled_actions(Ash.Resource.t() | Spark.Dsl.t()) :: [
750 | AshOban.Trigger.t() | AshOban.Schedule.t()
751 | ]
752 | ```
753 |
754 | [Link to this function](AshOban.Info.html#pro?/0 "Link to this function")
755 |
756 | # pro?()
757 |
758 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/info.ex#L7 "View Source")
759 |
760 | [Hex Package](https://hex.pm/packages/ash_oban/0.2.6) [Hex Preview](https://preview.hex.pm/preview/ash_oban/0.2.6) Search HexDocs [Download ePub version](ash_oban.epub "ePub version")
761 |
762 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.34.2) for the [Elixir programming language](https://elixir-lang.org "Elixir")
763 | [](https://github.com/ash-project/ash_oban)
764 |
765 | [ash\_oban](https://github.com/ash-project/ash_oban)
766 |
767 | v0.2.6
768 |
769 | - GUIDES
770 | - Modules
771 |
772 | <!--THE END-->
773 |
774 | <!--THE END-->
775 |
776 | Search documentation of ash\_oban
777 |
778 | Settings
779 |
780 | # [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/ash_oban.ex#L211 "View Source") AshOban.Schedule (ash\_oban v0.2.6)
781 |
782 | A configured scheduled action.
783 |
784 | # [](AshOban.Schedule.html#summary)Summary
785 |
786 | ## [Types](AshOban.Schedule.html#types)
787 |
788 | [t()](AshOban.Schedule.html#t:t/0)
789 |
790 | # [](AshOban.Schedule.html#types)Types
791 |
792 | [Link to this type](AshOban.Schedule.html#t:t/0 "Link to this type")
793 |
794 | # t()
795 |
796 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/ash_oban.ex#L216 "View Source")
797 |
798 | ```
799 | @type t() :: %AshOban.Schedule{
800 | __identifier__: term(),
801 | action: atom(),
802 | action_input: map(),
803 | cron: String.t(),
804 | debug: term(),
805 | debug?: boolean(),
806 | max_attempts: non_neg_integer(),
807 | name: atom(),
808 | priority: non_neg_integer(),
809 | queue: atom(),
810 | state: :active | :paused | :deleted,
811 | worker: module()
812 | }
813 | ```
814 |
815 | [Hex Package](https://hex.pm/packages/ash_oban/0.2.6) [Hex Preview](https://preview.hex.pm/preview/ash_oban/0.2.6) Search HexDocs [Download ePub version](ash_oban.epub "ePub version")
816 |
817 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.34.2) for the [Elixir programming language](https://elixir-lang.org "Elixir")
818 | [](https://github.com/ash-project/ash_oban)
819 |
820 | [ash\_oban](https://github.com/ash-project/ash_oban)
821 |
822 | v0.2.6
823 |
824 | - GUIDES
825 | - Modules
826 |
827 | <!--THE END-->
828 |
829 | <!--THE END-->
830 |
831 | Search documentation of ash\_oban
832 |
833 | Settings
834 |
835 | # [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/test.ex#L1 "View Source") AshOban.Test (ash\_oban v0.2.6)
836 |
837 | Helpers for testing ash\_oban triggers
838 |
839 | # [](AshOban.Test.html#summary)Summary
840 |
841 | ## [Functions](AshOban.Test.html#functions)
842 |
843 | [schedule\_and\_run\_triggers(resources\_or\_domains\_or\_otp\_apps, opts \\\\ \[\])](AshOban.Test.html#schedule_and_run_triggers/2)
844 |
845 | Calls [`AshOban.schedule_and_run_triggers/2`](AshOban.html#schedule_and_run_triggers/2) with `drain_queues?: true`.
846 |
847 | # [](AshOban.Test.html#functions)Functions
848 |
849 | [Link to this function](AshOban.Test.html#schedule_and_run_triggers/2 "Link to this function")
850 |
851 | # schedule\_and\_run\_triggers(resources\_or\_domains\_or\_otp\_apps, opts \\\\ \[])
852 |
853 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/test.ex#L7 "View Source")
854 |
855 | Calls [`AshOban.schedule_and_run_triggers/2`](AshOban.html#schedule_and_run_triggers/2) with `drain_queues?: true`.
856 |
857 | [Hex Package](https://hex.pm/packages/ash_oban/0.2.6) [Hex Preview](https://preview.hex.pm/preview/ash_oban/0.2.6) Search HexDocs [Download ePub version](ash_oban.epub "ePub version")
858 |
859 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.34.2) for the [Elixir programming language](https://elixir-lang.org "Elixir")
860 | [](https://github.com/ash-project/ash_oban)
861 |
862 | [ash\_oban](https://github.com/ash-project/ash_oban)
863 |
864 | v0.2.6
865 |
866 | - GUIDES
867 | - Modules
868 |
869 | <!--THE END-->
870 |
871 | <!--THE END-->
872 |
873 | Search documentation of ash\_oban
874 |
875 | Settings
876 |
877 | # [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/ash_oban.ex#L4 "View Source") AshOban.Trigger (ash\_oban v0.2.6)
878 |
879 | A configured trigger.
880 |
881 | # [](AshOban.Trigger.html#summary)Summary
882 |
883 | ## [Types](AshOban.Trigger.html#types)
884 |
885 | [t()](AshOban.Trigger.html#t:t/0)
886 |
887 | ## [Functions](AshOban.Trigger.html#functions)
888 |
889 | [transform(trigger)](AshOban.Trigger.html#transform/1)
890 |
891 | # [](AshOban.Trigger.html#types)Types
892 |
893 | [Link to this type](AshOban.Trigger.html#t:t/0 "Link to this type")
894 |
895 | # t()
896 |
897 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/ash_oban.ex#L9 "View Source")
898 |
899 | ```
900 | @type t() :: %AshOban.Trigger{
901 | __identifier__: atom(),
902 | action: atom(),
903 | action_input: map(),
904 | debug?: boolean(),
905 | lock_for_update?: boolean(),
906 | log_errors?: boolean(),
907 | log_final_error?: boolean(),
908 | max_attempts: pos_integer(),
909 | max_scheduler_attempts: pos_integer(),
910 | name: atom(),
911 | on_error: atom(),
912 | queue: atom(),
913 | read_action: atom(),
914 | read_metadata: (Ash.Resource.record() -> map()),
915 | record_limit: pos_integer(),
916 | scheduler: module() | nil,
917 | scheduler_cron: String.t(),
918 | scheduler_priority: non_neg_integer(),
919 | scheduler_queue: atom(),
920 | state: :active | :paused | :deleted,
921 | stream_batch_size: pos_integer(),
922 | where: Ash.Expr.t(),
923 | worker: module(),
924 | worker_priority: non_neg_integer(),
925 | worker_read_action: term()
926 | }
927 | ```
928 |
929 | # [](AshOban.Trigger.html#functions)Functions
930 |
931 | [Link to this function](AshOban.Trigger.html#transform/1 "Link to this function")
932 |
933 | # transform(trigger)
934 |
935 | [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/lib/ash_oban.ex#L64 "View Source")
936 |
937 | [Hex Package](https://hex.pm/packages/ash_oban/0.2.6) [Hex Preview](https://preview.hex.pm/preview/ash_oban/0.2.6) Search HexDocs [Download ePub version](ash_oban.epub "ePub version")
938 |
939 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.34.2) for the [Elixir programming language](https://elixir-lang.org "Elixir")
940 | [](https://github.com/ash-project/ash_oban)
941 |
942 | [ash\_oban](https://github.com/ash-project/ash_oban)
943 |
944 | v0.2.6
945 |
946 | - GUIDES
947 | - Modules
948 |
949 | <!--THE END-->
950 |
951 | <!--THE END-->
952 |
953 | Search documentation of ash\_oban
954 |
955 | Settings
956 |
957 | # [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/documentation/dsls/DSL-AshOban.md#L1 "View Source") DSL: AshOban
958 |
959 | Tools for working with AshOban triggers.
960 |
961 | ## [](dsl-ashoban.html#oban)oban
962 |
963 | ### [](dsl-ashoban.html#nested-dsls)Nested DSLs
964 |
965 | - [triggers](dsl-ashoban.html#oban-triggers)
966 |
967 | - trigger
968 | - [scheduled\_actions](dsl-ashoban.html#oban-scheduled_actions)
969 |
970 | - schedule
971 |
972 | ### [](dsl-ashoban.html#examples)Examples
973 |
974 | ```
975 | oban do
976 | triggers do
977 | trigger :process do
978 | action :process
979 | where expr(processed != true)
980 | worker_read_action(:read)
981 | end
982 | end
983 | end
984 | ```
985 |
986 | ### [](dsl-ashoban.html#options)Options
987 |
988 | NameTypeDefaultDocs[`domain`](dsl-ashoban.html#oban-domain)`module`The Domain to use when calling actions on this resource. Defaults to the resource's domain.
989 |
990 | ## [](dsl-ashoban.html#oban-triggers)oban.triggers
991 |
992 | ### [](dsl-ashoban.html#nested-dsls-1)Nested DSLs
993 |
994 | - [trigger](dsl-ashoban.html#oban-triggers-trigger)
995 |
996 | ### [](dsl-ashoban.html#examples-1)Examples
997 |
998 | ```
999 | triggers do
1000 | trigger :process do
1001 | action :process
1002 | where expr(processed != true)
1003 | worker_read_action(:read)
1004 | end
1005 | end
1006 | ```
1007 |
1008 | ## [](dsl-ashoban.html#oban-triggers-trigger)oban.triggers.trigger
1009 |
1010 | ```
1011 | trigger name
1012 | ```
1013 |
1014 | ### [](dsl-ashoban.html#examples-2)Examples
1015 |
1016 | ```
1017 | trigger :process do
1018 | action :process
1019 | where expr(processed != true)
1020 | worker_read_action(:read)
1021 | end
1022 | ```
1023 |
1024 | ### [](dsl-ashoban.html#arguments)Arguments
1025 |
1026 | NameTypeDefaultDocs[`name`](dsl-ashoban.html#oban-triggers-trigger-name)`atom`A unique identifier for this trigger.
1027 |
1028 | ### [](dsl-ashoban.html#options-1)Options
1029 |
1030 | NameTypeDefaultDocs[`action`](dsl-ashoban.html#oban-triggers-trigger-action)`atom`The action to be triggered. Defaults to the identifier of the resource plus the name of the trigger[`action_input`](dsl-ashoban.html#oban-triggers-trigger-action_input)`map`Static inputs to supply to the update/destroy action when it is called. Any metadata produced by `read_metadata` will overwrite these values.[`scheduler_queue`](dsl-ashoban.html#oban-triggers-trigger-scheduler_queue)`atom`The queue to place the scheduler job in. The same queue as job is used by default (but with a priority of 1 so schedulers run first).[`debug?`](dsl-ashoban.html#oban-triggers-trigger-debug?)`boolean``false`If set to `true`, detailed debug logging will be enabled for this trigger. You can also set `config :ash_oban, debug_all_triggers?: true` to enable debug logging for all triggers. If the action has `transaction?: false` this is automatically false.[`lock_for_update?`](dsl-ashoban.html#oban-triggers-trigger-lock_for_update?)`boolean``true`If `true`, a transaction will be started before looking up the record, and it will be locked for update. Typically you should leave this on unless you have before/after/around transaction hooks.[`scheduler_cron`](dsl-ashoban.html#oban-triggers-trigger-scheduler_cron)`String.t | false``"* * * * *"`A crontab configuration for when the job should run. Defaults to once per minute (" \*"). Use `false` to disable the scheduler entirely.[`stream_batch_size`](dsl-ashoban.html#oban-triggers-trigger-stream_batch_size)`pos_integer`The batch size to pass when streaming records from using [`Ash.stream!/2`](../ash/3.4.37/Ash.html#stream!/2). No batch size is passed if none is provided here, so the default is used.[`queue`](dsl-ashoban.html#oban-triggers-trigger-queue)`atom`The queue to place the worker job in. The trigger name is used by default.[`record_limit`](dsl-ashoban.html#oban-triggers-trigger-record_limit)`pos_integer`If set, any given run of the scheduler will only ever schedule this many items maximum[`log_errors?`](dsl-ashoban.html#oban-triggers-trigger-log_errors?)`boolean``true`Whether or not to log errors that occur when performing an action.[`log_final_error?`](dsl-ashoban.html#oban-triggers-trigger-log_final_error?)`boolean``true`If true, logs that an error occurred on the final attempt to perform an action even if `log_errors?` is set to false.[`worker_priority`](dsl-ashoban.html#oban-triggers-trigger-worker_priority)`non_neg_integer``2`A number from 0 to 3, where 0 is the highest priority and 3 is the lowest.[`scheduler_priority`](dsl-ashoban.html#oban-triggers-trigger-scheduler_priority)`non_neg_integer``3`A number from 0 to 3, where 0 is the highest priority and 3 is the lowest.[`max_scheduler_attempts`](dsl-ashoban.html#oban-triggers-trigger-max_scheduler_attempts)`pos_integer``1`How many times to attempt scheduling of the triggered action.[`max_attempts`](dsl-ashoban.html#oban-triggers-trigger-max_attempts)`pos_integer``1`How many times to attempt the job. After all attempts have been exhausted, the scheduler may just reschedule it. Use the `on_error` action to update the record to make the scheduler no longer apply.[`read_metadata`](dsl-ashoban.html#oban-triggers-trigger-read_metadata)`(any -> any)`Takes a record, and returns metadata to be given to the update action as an argument called `metadata`.[`state`](dsl-ashoban.html#oban-triggers-trigger-state)`:active | :paused | :deleted``:active`Describes the state of the cron job. See the getting started guide for more information. The most important thing is that you *do not remove a trigger from a resource if you are using oban pro*.[`read_action`](dsl-ashoban.html#oban-triggers-trigger-read_action)`atom`The read action to use when querying records. Defaults to the primary read. This action *must* support keyset pagination.[`worker_read_action`](dsl-ashoban.html#oban-triggers-trigger-worker_read_action)`atom`The read action to use when fetching the individual records for the trigger. Defaults to `read_action`. If you customize this, ensure your action handles scenarios where the trigger is no longer relevant.[`where`](dsl-ashoban.html#oban-triggers-trigger-where)`any`The filter expression to determine if something should be triggered[`on_error`](dsl-ashoban.html#oban-triggers-trigger-on_error)`atom`An update action to call after the last attempt has failed. See the getting started guide for more.
1031 |
1032 | ### [](dsl-ashoban.html#introspection)Introspection
1033 |
1034 | Target: [`AshOban.Trigger`](AshOban.Trigger.html)
1035 |
1036 | ## [](dsl-ashoban.html#oban-scheduled_actions)oban.scheduled\_actions
1037 |
1038 | A section for configured scheduled actions. Supports generic and create actions.
1039 |
1040 | ### [](dsl-ashoban.html#nested-dsls-2)Nested DSLs
1041 |
1042 | - [schedule](dsl-ashoban.html#oban-scheduled_actions-schedule)
1043 |
1044 | ### [](dsl-ashoban.html#examples-3)Examples
1045 |
1046 | ```
1047 | scheduled_actions do
1048 | schedule :import, "0 */6 * * *", action: :import
1049 | end
1050 | ```
1051 |
1052 | ## [](dsl-ashoban.html#oban-scheduled_actions-schedule)oban.scheduled\_actions.schedule
1053 |
1054 | ```
1055 | schedule name, cron
1056 | ```
1057 |
1058 | ### [](dsl-ashoban.html#arguments-1)Arguments
1059 |
1060 | NameTypeDefaultDocs[`name`](dsl-ashoban.html#oban-scheduled_actions-schedule-name)`atom`A unique identifier for this scheduled action.[`cron`](dsl-ashoban.html#oban-scheduled_actions-schedule-cron)`String.t`The schedule in crontab notation
1061 |
1062 | ### [](dsl-ashoban.html#options-2)Options
1063 |
1064 | NameTypeDefaultDocs[`action_input`](dsl-ashoban.html#oban-scheduled_actions-schedule-action_input)`map`Inputs to supply to the action when it is called.[`action`](dsl-ashoban.html#oban-scheduled_actions-schedule-action)`atom`The generic or create action to call when the schedule is triggered.[`queue`](dsl-ashoban.html#oban-scheduled_actions-schedule-queue)`atom`The queue to place the job in. Defaults to the resources short name plus the name of the scheduled action (not the action name).[`state`](dsl-ashoban.html#oban-scheduled_actions-schedule-state)`:active | :paused | :deleted``:active`Describes the state of the cron job. See the getting started guide for more information. The most important thing is that you *do not remove a scheduled action from a resource if you are using oban pro*.[`max_attempts`](dsl-ashoban.html#oban-scheduled_actions-schedule-max_attempts)`pos_integer``1`How many times to attempt the job. The action will receive a `last_oban_attempt?` argument on the last attempt, and you should handle errors accordingly.[`priority`](dsl-ashoban.html#oban-scheduled_actions-schedule-priority)`non_neg_integer``3`A number from 0 to 3, where 0 is the highest priority and 3 is the lowest.[`debug?`](dsl-ashoban.html#oban-scheduled_actions-schedule-debug?)`boolean``false`If set to `true`, detailed debug logging will be enabled for this trigger. You can also set `config :ash_oban, debug_all_triggers?: true` to enable debug logging for all triggers.
1065 |
1066 | ### [](dsl-ashoban.html#introspection-1)Introspection
1067 |
1068 | Target: [`AshOban.Schedule`](AshOban.Schedule.html)
1069 |
1070 | [← Previous Page Getting Started With Ash Oban](getting-started-with-ash-oban.html)
1071 |
1072 | [Next Page → Change Log](changelog.html)
1073 |
1074 | [Hex Package](https://hex.pm/packages/ash_oban/0.2.6) [Hex Preview](https://preview.hex.pm/preview/ash_oban/0.2.6) ([current file](https://preview.hex.pm/preview/ash_oban/0.2.6/show/documentation/dsls/DSL-AshOban.md)) Search HexDocs [Download ePub version](ash_oban.epub "ePub version")
1075 |
1076 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.34.2) for the [Elixir programming language](https://elixir-lang.org "Elixir")
1077 | [](https://github.com/ash-project/ash_oban)
1078 |
1079 | [ash\_oban](https://github.com/ash-project/ash_oban)
1080 |
1081 | v0.2.6
1082 |
1083 | - GUIDES
1084 | - Modules
1085 |
1086 | <!--THE END-->
1087 |
1088 | <!--THE END-->
1089 |
1090 | Search documentation of ash\_oban
1091 |
1092 | Settings
1093 |
1094 | # [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/documentation/tutorials/getting-started-with-ash-oban.md#L1 "View Source") Getting Started With Ash Oban
1095 |
1096 | AshOban will likely grow to provide many more oban-related features, but for now the primary focus is on "triggers".
1097 |
1098 | A trigger describes an action that is run periodically.
1099 |
1100 | ## [](getting-started-with-ash-oban.html#get-familiar-with-ash-resources)Get familiar with Ash resources
1101 |
1102 | If you haven't already, read the [Ash Getting Started Guide](../ash/get-started.html), and familiarize yourself with Ash and Ash resources.
1103 |
1104 | ## [](getting-started-with-ash-oban.html#bring-in-the-ash_oban-dependency)Bring in the `ash_oban` dependency
1105 |
1106 | ```
1107 | {:ash_oban, "~> 0.2.6"}
1108 | ```
1109 |
1110 | ## [](getting-started-with-ash-oban.html#setup)Setup
1111 |
1112 | First, follow the [Oban setup guide](../oban/installation.html).
1113 |
1114 | ### [](getting-started-with-ash-oban.html#oban-pro)Oban Pro
1115 |
1116 | If you are using Oban Pro, set the following configuration:
1117 |
1118 | ```
1119 | config :ash_oban, :pro?, true
1120 | ```
1121 |
1122 | Oban Pro lives in a separate hex repository, and therefore we, unfortunately, cannot have an explicit version dependency on it. What this means is that any version you use in hex will technically be accepted, and if you don't have the oban pro package installed and you use the above configuration, you will get compile time errors/warnings.
1123 |
1124 | ### [](getting-started-with-ash-oban.html#setting-up-ashoban)Setting up AshOban
1125 |
1126 | Next, allow AshOban to alter your configuration in your Application module:
1127 |
1128 | ```
1129 | # Replace this
1130 | {Oban, your_oban_config}
1131 |
1132 | # With this
1133 | {Oban, AshOban.config(Application.fetch_env!(:my_app, :ash_domains), your_oban_config)}
1134 | # OR this, to selectively enable AshOban only for specific domains
1135 | {Oban, AshOban.config([YourDomain, YourOtherDomain], your_oban_config)}
1136 | ```
1137 |
1138 | ## [](getting-started-with-ash-oban.html#usage)Usage
1139 |
1140 | Finally, configure your triggers in your resources.
1141 |
1142 | Add the [`AshOban`](AshOban.html) extension:
1143 |
1144 | ```
1145 | use Ash.Resource, domain: MyDomain, extensions: [AshOban]
1146 | ```
1147 |
1148 | For example:
1149 |
1150 | ```
1151 | oban do
1152 | triggers do
1153 | # add a trigger called `:process`
1154 | trigger :process do
1155 | # this trigger calls the `process` action
1156 | action :process
1157 | # for any record that has `processed != true`
1158 | where expr(processed != true)
1159 | # checking for matches every minute
1160 | scheduler_cron "* * * * *"
1161 | on_error :errored
1162 | end
1163 | end
1164 | end
1165 | ```
1166 |
1167 | See the DSL documentation for more: [`AshOban`](dsl-ashoban.html)
1168 |
1169 | ## [](getting-started-with-ash-oban.html#handling-errors)Handling Errors
1170 |
1171 | Error handling is done by adding an `on_error` to your trigger. This is an update action that will get the error as an argument called `:error`. The error will be an Ash error class. These error classes can contain many kinds of errors, so you will need to figure out handling specific errors on your own. Be sure to add the `:error` argument to the action if you want to receive the error.
1172 |
1173 | This is *not* foolproof. You want to be sure that your `on_error` action is as simple as possible, because if an exception is raised during the `on_error` action, the oban job will fail. If you are relying on your `on_error` logic to alter the resource to make it no longer apply to a trigger, consider making your action do *only that*. Then you can add another trigger watching for things in an errored state to do more rich error handling behavior.
1174 |
1175 | ## [](getting-started-with-ash-oban.html#changing-triggers-when-using-oban-pro)Changing Triggers when using Oban Pro
1176 |
1177 | To remove or disable triggers, *do not just remove them from your resource*. Due to the way that Oban Pro implements cron jobs, if you just remove them from your resource, the cron will attempt to continue scheduling jobs. Instead, set `paused true` or `delete true` on the trigger. See the oban docs for more: [https://getoban.pro/docs/pro/0.14.1/Oban.Pro.Plugins.DynamicCron.html#module-using-and-configuring](https://getoban.pro/docs/pro/0.14.1/Oban.Pro.Plugins.DynamicCron.html#module-using-and-configuring)
1178 |
1179 | PS: `delete true` is also indempotent, so there is no issue with deploying with that flag set to true multiple times. After you have deployed once with `delete true` you can safely delete the trigger.
1180 |
1181 | When not using Oban Pro, all crons are simply loaded on boot time and there is no side effects to simply deleting an unused trigger.
1182 |
1183 | ## [](getting-started-with-ash-oban.html#transactions)Transactions
1184 |
1185 | AshOban adds two new transaction reasons, as it uses explicit transactions to ensure that each triggered record is properly locked and executed in serially.
1186 |
1187 | ```
1188 | %{
1189 | type: :ash_oban_trigger,
1190 | metadata: %{
1191 | resource: Resource,
1192 | trigger: :trigger_name,
1193 | primary_key: %{primary_key_fields: value}
1194 | }
1195 | }
1196 | ```
1197 |
1198 | and
1199 |
1200 | ```
1201 | %{
1202 | type: :ash_oban_trigger_error,
1203 | metadata: %{
1204 | resource: Resource
1205 | trigger: :trigger_name,
1206 | primary_key: %{primary_key_fields: value},
1207 | error: <the error (this will be an ash error class)>
1208 | }
1209 | }
1210 | ```
1211 |
1212 | ## [](getting-started-with-ash-oban.html#authorizing-actions)Authorizing actions
1213 |
1214 | As of v0.2, `authorize?: true` is passed into every action that is called. This may be a breaking change for some users that are using policies. There are two ways to get around this:
1215 |
1216 | 1. you can set `config :ash_oban, authorize?: false` (easiest, reverts to old behavior, but not recommended)
1217 | 2. you can install the bypass at the top of your policies in any resource that you have triggers on that has policies:
1218 |
1219 | ```
1220 | policies do
1221 | bypass AshOban.Checks.AshObanInteraction do
1222 | authorize_if always()
1223 | end
1224 |
1225 | ...the rest of your policies
1226 | end
1227 | ```
1228 |
1229 | ## [](getting-started-with-ash-oban.html#persisting-the-actor-along-with-a-job)Persisting the actor along with a job
1230 |
1231 | Create a module that is responsible for translating the current user to a value that will be JSON encoded, and for turning that encoded value back into an actor.
1232 |
1233 | ```
1234 | defmodule MyApp.AshObanActorPersister do
1235 | use AshOban.PersistActor
1236 |
1237 | def store(%MyApp.User{id: id}), do: %{"type" => "user", "id" => id}
1238 |
1239 | def lookup(%{"type" => "user", "id" => id}), do: MyApp.Accounts.get(MyApp.User, id)
1240 |
1241 | # This allows you to set a default actor
1242 | # in cases where no actor was present
1243 | # when scheduling.
1244 | def lookup(nil), do: {:ok, nil}
1245 | end
1246 | ```
1247 |
1248 | Then, configure this in application config.
1249 |
1250 | ```
1251 | config :ash_oban, :actor_persister, MyApp.AshObanActorPersister
1252 | ```
1253 |
1254 | ### [](getting-started-with-ash-oban.html#considerations)Considerations
1255 |
1256 | There are a few things that are important to keep in mind:
1257 |
1258 | 1. The actor could be deleted or otherwise unavailable when you look it up. You very likely want your `lookup/1` to return an error in that scenario.
1259 | 2. The actor can have changed between when the job was scheduled and when the trigger is executing. It can even change across retries. If you are trying to authorize access for a given trigger's update action to a given actor, keep in mind that just because the trigger is running for a given action, does *not* mean that the conditions that allowed them to originally *schedule* that action are still true.
1260 |
1261 | [← Previous Page Home](readme.html)
1262 |
1263 | [Next Page → DSL: AshOban](dsl-ashoban.html)
1264 |
1265 | [Hex Package](https://hex.pm/packages/ash_oban/0.2.6) [Hex Preview](https://preview.hex.pm/preview/ash_oban/0.2.6) ([current file](https://preview.hex.pm/preview/ash_oban/0.2.6/show/documentation/tutorials/getting-started-with-ash-oban.md)) Search HexDocs [Download ePub version](ash_oban.epub "ePub version")
1266 |
1267 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.34.2) for the [Elixir programming language](https://elixir-lang.org "Elixir")
1268 | [](https://github.com/ash-project/ash_oban)
1269 |
1270 | [ash\_oban](https://github.com/ash-project/ash_oban)
1271 |
1272 | v0.2.6
1273 |
1274 | - GUIDES
1275 | - Modules
1276 |
1277 | <!--THE END-->
1278 |
1279 | <!--THE END-->
1280 |
1281 | Search documentation of ash\_oban
1282 |
1283 | Settings
1284 |
1285 | # [View Source](https://github.com/ash-project/ash_oban/blob/v0.2.6/README.md#L1 "View Source") Home
1286 |
1287 |  
1288 |
1289 |  [](https://opensource.org/licenses/MIT) [](https://hex.pm/packages/ash_oban) [](../ash_oban.html)
1290 |
1291 | # AshOban
1292 |
1293 | Welcome! This is the extension for integrating [Ash](../ash.html) resources with [Oban](../oban.html). This extension allows you to easily execute resource actions in the background, and trigger actions based on data conditions.
1294 |
1295 | ## [](readme.html#tutorials)Tutorials
1296 |
1297 | - [Getting Started with AshOban](getting-started-with-ash-oban.html)
1298 |
1299 | ## [](readme.html#reference)Reference
1300 |
1301 | - [AshOban DSL](dsl-ashoban.html)
1302 |
1303 | [← Previous Page API Reference](api-reference.html)
1304 |
1305 | [Next Page → Getting Started With Ash Oban](getting-started-with-ash-oban.html)
1306 |
1307 | [Hex Package](https://hex.pm/packages/ash_oban/0.2.6) [Hex Preview](https://preview.hex.pm/preview/ash_oban/0.2.6) ([current file](https://preview.hex.pm/preview/ash_oban/0.2.6/show/README.md)) Search HexDocs [Download ePub version](ash_oban.epub "ePub version")
1308 |
1309 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.34.2) for the [Elixir programming language](https://elixir-lang.org "Elixir")
1310 |
```