-
Notifications
You must be signed in to change notification settings - Fork 301
Expand file tree
/
Copy pathbackground-error-action-demo.yml
More file actions
58 lines (58 loc) · 1.04 KB
/
background-error-action-demo.yml
File metadata and controls
58 lines (58 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
metadata:
title: Background error callback
example start: 1
example end: 8
documentation: "https://docassemble.org/docs/background.html#background_error_action"
---
question: |
Give me some numbers.
fields:
- Numerator: b
datatype: number
- Denominator: c
datatype: number
---
code: |
need(b, c)
task = background_action('bg_task')
---
mandatory: True
code: |
if task.ready():
show_result
else:
show_waiting_screen
---
event: show_waiting_screen
reload: True
question: |
Waiting for result...
---
event: show_result
question: |
Result of task
subquestion: |
% if computation_ok:
The result was ${ answer }.
% else:
There was an error.
% endif
---
event: bg_task
code: |
# This is where time-consuming code
# would go.
background_error_action('bg_failure')
a = b / c
background_response_action('bg_success', answer=a)
---
event: bg_success
code: |
computation_ok = True
answer = action_argument('answer')
background_response()
---
event: bg_failure
code: |
computation_ok = False
background_response()