Debian Codegraph @

tests/functional/ext-trigger/00-satellite/flow.cylc

raw
1 #!Jinja2
2
3 # TEST WORKFLOW ADAPTED FROM examples/satellite/ext-trigger/
4
5 [meta]
6 title = Real time satellite data processing demo, variant 3 of 3
7 description = """
8 Successive cycle points retrieve and processes the next arbitrarily
9 timed and labelled dataset, in parallel if the data comes in quickly.
10 This variant of the workflow has initial get_data tasks with external
11 triggers: they do not submit until triggered by an external system.
12 """
13
14 # Note that the satellite simulator task here that supplies the external event
15 # trigger happens to be a workflow task - i.e. it is not really "external" - but
16 # this is only a convenience - an easy route to a self-contained example workflow.
17
18 # you can monitor output processing with:
19 # $ watch -n 1 \
20 # "find ~/cylc-run/<WORKFLOW>/share; find ~/cylc-run/<WORKFLOW>/work"
21
22 {% set N_DATASETS = 5 %}
23
24 # define shared directories (could use runtime namespaces for this)
25 {% set DATA_IN_DIR = "$CYLC_WORKFLOW_SHARE_DIR/incoming" %}
26 {% set PRODUCT_DIR = "$CYLC_WORKFLOW_SHARE_DIR/products" %}
27
28 [scheduler]
29 UTC mode = True
30
31 [scheduling]
32 cycling mode = integer
33 initial cycle point = 1
34 final cycle point = {{N_DATASETS}}
35 runahead limit = P4
36 [[special tasks]]
37 external-trigger = get_data("new dataset ready for processing")
38 [[graph]]
39 R1 = prep => satsim & get_data
40 P1 = """
41 # Processing chain for each dataset
42 get_data => proc1 => proc2 => products
43 # As one dataset is retrieved, start waiting on another.
44 get_data[-P1] => get_data
45 """
46 R1//{{N_DATASETS}} = products => collate # last cycle
47
48 [runtime]
49 [[prep]]
50 script = rm -rf $CYLC_WORKFLOW_SHARE_DIR $CYLC_WORKFLOW_WORK_DIR
51 [[[meta]]]
52 title = clean the workflow output directories
53
54 [[satsim]]
55 pre-script = mkdir -p {{DATA_IN_DIR}}
56 script = """
57 COUNT=0
58 while ((COUNT < {{N_DATASETS}})); do
59 # sleep $((RANDOM % 20))
60 # Generate datasets very quickly to test parallel processing.
61 DATA_ID=$(date +%s).$((RANDOM % 100))
62 DATA_FILE=dataset-${DATA_ID}.raw
63 touch {{DATA_IN_DIR}}/$DATA_FILE
64 ((COUNT += 1))
65 # (required to distinguish fast-arriving messages).
66 # Trigger downstream processing in the workflow.
67 cylc ext-trigger $CYLC_WORKFLOW_ID \
68 "new dataset ready for processing" $DATA_ID
69 done
70 """
71 [[[meta]]]
72 title = simulate a satellite data feed
73 description = """
74 Generates {{N_DATASETS}} arbitrarily labelled
75 datasets very quickly, to show parallel processing streams.
76 """
77
78 [[WORKDIR]]
79 # Define a common cycle-point-specific work-directory for all
80 # processing tasks so that they all work on the same dataset.
81 work sub-directory = proc-$CYLC_TASK_CYCLE_POINT
82 [[[environment]]]
83 DATASET = dataset-$CYLC_EXT_TRIGGER_ID
84
85 [[get_data]]
86 inherit = WORKDIR
87 script = mv {{DATA_IN_DIR}}/${DATASET}.raw $PWD
88 [[[meta]]]
89 title = retrieve next dataset
90 description = just do it - we know it exists already
91
92 [[proc1]]
93 inherit = WORKDIR
94 script = mv ${DATASET}.raw ${DATASET}.proc1
95 [[[meta]]]
96 title = convert .raw dataset to .proc1 form
97
98 [[proc2]]
99 inherit = WORKDIR
100 script = mv ${DATASET}.proc1 ${DATASET}.proc2
101 [[[meta]]]
102 title = convert .proc1 dataset to .proc2 form
103
104 [[products]]
105 inherit = WORKDIR
106 script = """
107 mkdir -p {{PRODUCT_DIR}}
108 mv ${DATASET}.proc2 {{PRODUCT_DIR}}/${DATASET}.prod
109 """
110 [[[meta]]]
111 title = generate products from .proc2 processed dataset
112
113 [[collate]]
114 # Note you might want to use "cylc workflow-state" to check that
115 # _all_ product tasks have finished before collating results.
116 script = """
117 echo PRODUCTS:
118 ls {{PRODUCT_DIR}}
119 """
120 [[[meta]]]
121 title = collate all products from the workflow run