forked from treasure-data/digdag-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
workflow_definition.html
663 lines (517 loc) · 38.7 KB
/
workflow_definition.html
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Workflow definition — Digdag 0.10.0 documentation</title>
<script type="text/javascript" src="_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="_static/language_data.js"></script>
<script type="text/javascript" src="_static/js/theme.js"></script>
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/custom.css" type="text/css" />
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Scheduling workflow" href="scheduling_workflow.html" />
<link rel="prev" title="Concepts" href="concepts.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="index.html" class="icon icon-home"> Digdag
</a>
<div class="version">
0.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="getting_started.html">Getting started</a></li>
<li class="toctree-l1"><a class="reference internal" href="architecture.html">Architecture</a></li>
<li class="toctree-l1"><a class="reference internal" href="concepts.html">Concepts</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Workflow definition</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#workflow-definition-dig-files">Workflow definition: *.dig files</a></li>
<li class="toctree-l2"><a class="reference internal" href="#is-a-task">“+” is a task</a></li>
<li class="toctree-l2"><a class="reference internal" href="#operators">operators></a></li>
<li class="toctree-l2"><a class="reference internal" href="#using-variables">Using ${variables}</a></li>
<li class="toctree-l2"><a class="reference internal" href="#calculating-variables">Calculating variables</a></li>
<li class="toctree-l2"><a class="reference internal" href="#defining-variables">Defining variables</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#using-export-parameter">Using _export: parameter</a></li>
<li class="toctree-l3"><a class="reference internal" href="#using-api">Using API</a></li>
<li class="toctree-l3"><a class="reference internal" href="#starting-a-session-with-variables">Starting a session with variables</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#include-another-file">!include another file</a></li>
<li class="toctree-l2"><a class="reference internal" href="#parallel-execution">Parallel execution</a></li>
<li class="toctree-l2"><a class="reference internal" href="#retrying-failed-tasks-automatically">Retrying failed tasks automatically</a></li>
<li class="toctree-l2"><a class="reference internal" href="#sending-error-notification">Sending error notification</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="scheduling_workflow.html">Scheduling workflow</a></li>
<li class="toctree-l1"><a class="reference internal" href="operators.html">Operators</a></li>
<li class="toctree-l1"><a class="reference internal" href="command_reference.html">Command reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="python_api.html">Language API - Python</a></li>
<li class="toctree-l1"><a class="reference internal" href="ruby_api.html">Language API - Ruby</a></li>
<li class="toctree-l1"><a class="reference internal" href="rest_api.html">REST API</a></li>
<li class="toctree-l1"><a class="reference internal" href="command_executor.html">Command Executor</a></li>
<li class="toctree-l1"><a class="reference internal" href="internal.html">Internal architecture</a></li>
<li class="toctree-l1"><a class="reference internal" href="metrics.html">Digdag metrics (experimental)</a></li>
<li class="toctree-l1"><a class="reference internal" href="community_contributions.html">Community Contributions</a></li>
<li class="toctree-l1"><a class="reference internal" href="releases.html">Release Notes</a></li>
<li class="toctree-l1"><a class="reference internal" href="logo.html">Logo</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">Digdag</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html">Docs</a> »</li>
<li>Workflow definition</li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/workflow_definition.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="workflow-definition">
<h1>Workflow definition<a class="headerlink" href="#workflow-definition" title="Permalink to this headline">¶</a></h1>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><p><a class="reference internal" href="#workflow-definition-dig-files" id="id2">Workflow definition: *.dig files</a></p></li>
<li><p><a class="reference internal" href="#is-a-task" id="id3">“+” is a task</a></p></li>
<li><p><a class="reference internal" href="#operators" id="id4">operators></a></p></li>
<li><p><a class="reference internal" href="#using-variables" id="id5">Using ${variables}</a></p></li>
<li><p><a class="reference internal" href="#calculating-variables" id="id6">Calculating variables</a></p></li>
<li><p><a class="reference internal" href="#defining-variables" id="id7">Defining variables</a></p>
<ul>
<li><p><a class="reference internal" href="#using-export-parameter" id="id8">Using _export: parameter</a></p></li>
<li><p><a class="reference internal" href="#using-api" id="id9">Using API</a></p></li>
<li><p><a class="reference internal" href="#starting-a-session-with-variables" id="id10">Starting a session with variables</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#include-another-file" id="id11">!include another file</a></p></li>
<li><p><a class="reference internal" href="#parallel-execution" id="id12">Parallel execution</a></p></li>
<li><p><a class="reference internal" href="#retrying-failed-tasks-automatically" id="id13">Retrying failed tasks automatically</a></p></li>
<li><p><a class="reference internal" href="#sending-error-notification" id="id14">Sending error notification</a></p></li>
</ul>
</div>
<div class="section" id="workflow-definition-dig-files">
<h2><a class="toc-backref" href="#id2">Workflow definition: *.dig files</a><a class="headerlink" href="#workflow-definition-dig-files" title="Permalink to this headline">¶</a></h2>
<p>A digdag workflow is defined in a file named with <code class="docutils literal notranslate"><span class="pre">.dig</span></code> suffix. Name of the file is name of the workflow.</p>
<p>For example, if you create <code class="docutils literal notranslate"><span class="pre">hello_world</span></code> workflow, you will create <code class="docutils literal notranslate"><span class="pre">hello_world.dig</span></code> file. Contents of the file looks like this:</p>
<div class="highlight-yaml notranslate"><div class="highlight"><pre><span></span><span class="nt">timezone</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">UTC</span>
<span class="nt">+step1</span><span class="p">:</span>
<span class="nt">sh></span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">tasks/shell_sample.sh</span>
<span class="nt">+step2</span><span class="p">:</span>
<span class="nt">py></span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">tasks.MyWorkflow.step2</span>
<span class="nt">param1</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">this is param1</span>
<span class="nt">+step3</span><span class="p">:</span>
<span class="nt">rb></span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">MyWorkflow.step3</span>
<span class="nt">require</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">tasks/ruby_sample.rb</span>
</pre></div>
</div>
<p>The <code class="docutils literal notranslate"><span class="pre">timezone</span></code> parameter is used to configure the time zone of the workflow and affects session timestamp variables and scheduling. The default time zone is <code class="docutils literal notranslate"><span class="pre">UTC</span></code>. Some examples of other valid time zones are <code class="docutils literal notranslate"><span class="pre">America/Los_Angeles</span></code>, <code class="docutils literal notranslate"><span class="pre">Europe/Berlin</span></code>, <code class="docutils literal notranslate"><span class="pre">Asia/Tokyo</span></code>, etc.</p>
</div>
<div class="section" id="is-a-task">
<h2><a class="toc-backref" href="#id3">“+” is a task</a><a class="headerlink" href="#is-a-task" title="Permalink to this headline">¶</a></h2>
<p>Key names starting with <code class="docutils literal notranslate"><span class="pre">+</span></code> sign is a task. Tasks run from the top to bottom in order. A task can be nested as a child of another task. In above example, <code class="docutils literal notranslate"><span class="pre">+step2</span></code> runs after <code class="docutils literal notranslate"><span class="pre">+step1</span></code> as a child of <code class="docutils literal notranslate"><span class="pre">+main</span></code> task.</p>
</div>
<div class="section" id="operators">
<h2><a class="toc-backref" href="#id4">operators></a><a class="headerlink" href="#operators" title="Permalink to this headline">¶</a></h2>
<p>A task with <code class="docutils literal notranslate"><span class="pre">type>:</span> <span class="pre">command</span></code> or <code class="docutils literal notranslate"><span class="pre">_type:</span> <span class="pre">NAME</span></code> parameter executes an action. You can choose various kinds of operators such as <a class="reference external" href="operators/sh.html">running shell scripts</a>, <a class="reference external" href="operators/py.html">Python methods</a>, <a class="reference external" href="operators/mail.html">sending email</a>, etc. See <a class="reference external" href="operators.html">Operators</a> page for the list of built-in operators.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Setting <code class="docutils literal notranslate"><span class="pre">foo>:</span> <span class="pre">bar</span></code> parameter is equivalent to setting <code class="docutils literal notranslate"><span class="pre">_type:</span> <span class="pre">foo</span></code> and <code class="docutils literal notranslate"><span class="pre">_command:</span> <span class="pre">bar</span></code> parameters. That is a syntax sugar of setting 2 parameters in 1 line.</p>
</div>
</div>
<div class="section" id="using-variables">
<h2><a class="toc-backref" href="#id5">Using ${variables}</a><a class="headerlink" href="#using-variables" title="Permalink to this headline">¶</a></h2>
<p>Workflow can embed variables using <code class="docutils literal notranslate"><span class="pre">${...}</span></code> syntax. You can use built-in variables or define your own variables.</p>
<p>Here is the list of built-in variables:</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 28%" />
<col style="width: 39%" />
<col style="width: 33%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Name</p></th>
<th class="head"><p>Description</p></th>
<th class="head"><p>Example</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><strong>timezone</strong></p></td>
<td><p>Timezone of this workflow</p></td>
<td><p>America/Los_Angeles</p></td>
</tr>
<tr class="row-odd"><td><p><strong>project_id</strong></p></td>
<td><p>The project ID of this workflow</p></td>
<td><p>12345</p></td>
</tr>
<tr class="row-even"><td><p><strong>session_uuid</strong></p></td>
<td><p>Unique UUID of this session</p></td>
<td><p>414a8b9e-b365-4394-916a-f0ed9987bd2b</p></td>
</tr>
<tr class="row-odd"><td><p><strong>session_id</strong></p></td>
<td><p>Integer ID of this session</p></td>
<td><p>2381</p></td>
</tr>
<tr class="row-even"><td><p><strong>session_time</strong></p></td>
<td><p>Time of this session with time zone</p></td>
<td><p>2016-01-30T00:00:00-08:00</p></td>
</tr>
<tr class="row-odd"><td><p><strong>session_date</strong></p></td>
<td><p>Date part of session_time</p></td>
<td><p>2016-01-30</p></td>
</tr>
<tr class="row-even"><td><p><strong>session_date_compact</strong></p></td>
<td><p>Date part of session_time (compact)</p></td>
<td><p>20160130</p></td>
</tr>
<tr class="row-odd"><td><p><strong>session_local_time</strong></p></td>
<td><p>Local time format of session_time</p></td>
<td><p>2016-01-30 00:00:00</p></td>
</tr>
<tr class="row-even"><td><p><strong>session_tz_offset</strong></p></td>
<td><p>Time zone offset part of session_time</p></td>
<td><p>-0800</p></td>
</tr>
<tr class="row-odd"><td><p><strong>session_unixtime</strong></p></td>
<td><p>Seconds since the epoch time</p></td>
<td><p>1454140800</p></td>
</tr>
<tr class="row-even"><td><p><strong>task_name</strong></p></td>
<td><p>Name of this task</p></td>
<td><p>+my_workflow+parent_task+child_task0</p></td>
</tr>
<tr class="row-odd"><td><p><strong>attempt_id</strong></p></td>
<td><p>Integer ID of this attempt</p></td>
<td><p>7</p></td>
</tr>
</tbody>
</table>
<p>If <a class="reference external" href="scheduling_workflow.html">schedule: option is set</a>, <strong>last_session_time</strong> and <strong>next_session_time</strong> are also available as following:</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 41%" />
<col style="width: 30%" />
<col style="width: 30%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Name</p></th>
<th class="head"><p>Example (hourly schedule)</p></th>
<th class="head"><p>Example (daily schedule)</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><strong>last_session_time</strong></p></td>
<td><p>2016-01-29T23:00:00-08:00</p></td>
<td><p>2016-01-29T00:00:00-08:00</p></td>
</tr>
<tr class="row-odd"><td><p><strong>last_session_date</strong></p></td>
<td><p>2016-01-29</p></td>
<td><p>2016-01-29</p></td>
</tr>
<tr class="row-even"><td><p><strong>last_session_date_compact</strong></p></td>
<td><p>20160129</p></td>
<td><p>20160129</p></td>
</tr>
<tr class="row-odd"><td><p><strong>last_session_local_time</strong></p></td>
<td><p>2016-01-29 23:00:00</p></td>
<td><p>2016-01-29 00:00:00</p></td>
</tr>
<tr class="row-even"><td><p><strong>last_session_tz_offset</strong></p></td>
<td><p>-0800</p></td>
<td><p>-0800</p></td>
</tr>
<tr class="row-odd"><td><p><strong>last_session_unixtime</strong></p></td>
<td><p>1454137200</p></td>
<td><p>1454054400</p></td>
</tr>
<tr class="row-even"><td><p><strong>last_executed_session_time</strong></p></td>
<td><p>2016-01-29T23:00:00-08:00</p></td>
<td><p>2016-01-29T00:00:00-08:00</p></td>
</tr>
<tr class="row-odd"><td><p><strong>last_executed_session_unixtime</strong></p></td>
<td><p>1454137200</p></td>
<td><p>1454054400</p></td>
</tr>
<tr class="row-even"><td><p><strong>next_session_time</strong></p></td>
<td><p>2016-01-30T01:00:00-08:00</p></td>
<td><p>2016-01-31T00:00:00-08:00</p></td>
</tr>
<tr class="row-odd"><td><p><strong>next_session_date</strong></p></td>
<td><p>2016-01-30</p></td>
<td><p>2016-01-31</p></td>
</tr>
<tr class="row-even"><td><p><strong>next_session_date_compact</strong></p></td>
<td><p>20160130</p></td>
<td><p>20160131</p></td>
</tr>
<tr class="row-odd"><td><p><strong>next_session_local_time</strong></p></td>
<td><p>2016-01-30 01:00:00</p></td>
<td><p>2016-01-31 00:00:00</p></td>
</tr>
<tr class="row-even"><td><p><strong>next_session_tz_offset</strong></p></td>
<td><p>-0800</p></td>
<td><p>-0800</p></td>
</tr>
<tr class="row-odd"><td><p><strong>next_session_unixtime</strong></p></td>
<td><p>1454144400</p></td>
<td><p>1454227200</p></td>
</tr>
</tbody>
</table>
<p>last_session_time is the timestamp of the last schedule. If the schedule is hourly, it’s the last hour. If the schedule is daily, it’s yesterday. It doesn’t matter whether the last schedule actually ran or not. It’s simply set to the last timestamp calculated from the current session time.
last_executed_session_time variable is the previously executed session time.</p>
</div>
<div class="section" id="calculating-variables">
<h2><a class="toc-backref" href="#id6">Calculating variables</a><a class="headerlink" href="#calculating-variables" title="Permalink to this headline">¶</a></h2>
<p>You can use basic JavaScript scripts in <code class="docutils literal notranslate"><span class="pre">${...}</span></code> syntax to calculate variables.</p>
<p>A common use case is formatting timestamp in different format. Digdag bundles <a class="reference external" href="http://momentjs.com/">Moment.js</a> for time calculation.</p>
<div class="highlight-yaml notranslate"><div class="highlight"><pre><span></span><span class="nt">timezone</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">America/Los_Angeles</span>
<span class="nt">+format_session_time</span><span class="p">:</span>
<span class="c1"># "2016-09-24 00:00:00 -0700"</span>
<span class="nt">echo></span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">${moment(session_time).format("YYYY-MM-DD HH:mm:ss Z")}</span>
<span class="nt">+format_in_utc</span><span class="p">:</span>
<span class="c1"># "2016-09-24 07:00:00"</span>
<span class="nt">echo></span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">${moment(session_time).utc().format("YYYY-MM-DD HH:mm:ss")}</span>
<span class="nt">+format_tomorrow</span><span class="p">:</span>
<span class="c1"># "September 24, 2016 12:00 AM"</span>
<span class="nt">echo></span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">${moment(session_time).add(1, 'days').format("LLL")}</span>
<span class="nt">+get_execution_time</span><span class="p">:</span>
<span class="c1"># "2016-09-24 05:24:49 -0700"</span>
<span class="nt">echo></span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">${moment().format("YYYY-MM-DD HH:mm:ss Z")}</span>
</pre></div>
</div>
</div>
<div class="section" id="defining-variables">
<h2><a class="toc-backref" href="#id7">Defining variables</a><a class="headerlink" href="#defining-variables" title="Permalink to this headline">¶</a></h2>
<p>You can define variables in 3 ways:</p>
<ul class="simple">
<li><p>Using <code class="docutils literal notranslate"><span class="pre">_export</span></code> parameter in YAML</p></li>
<li><p>Setting variable programmably using API</p></li>
<li><p>Starting a session with variables</p></li>
</ul>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>You cannot overwrite built-in variables.</p>
</div>
<div class="section" id="using-export-parameter">
<h3><a class="toc-backref" href="#id8">Using _export: parameter</a><a class="headerlink" href="#using-export-parameter" title="Permalink to this headline">¶</a></h3>
<p>In a YAML file, <code class="docutils literal notranslate"><span class="pre">_export:</span></code> directive defines variables. This is useful to load static configurations such as host name of a database.</p>
<p>If a task has <code class="docutils literal notranslate"><span class="pre">_export</span></code> directive, the task and its children can use the variables because it defines variables in a scope. With following example, all tasks can use <code class="docutils literal notranslate"><span class="pre">foo=1</span></code> but only +step1 (and +analyze) can use <code class="docutils literal notranslate"><span class="pre">bar=2</span></code>.</p>
<div class="highlight-yaml notranslate"><div class="highlight"><pre><span></span><span class="nt">_export</span><span class="p">:</span>
<span class="nt">foo</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">1</span>
<span class="nt">+prepare</span><span class="p">:</span>
<span class="nt">py></span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">tasks.MyWorkflow.prepare</span>
<span class="nt">+analyze</span><span class="p">:</span>
<span class="nt">_export</span><span class="p">:</span>
<span class="nt">bar</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">2</span>
<span class="nt">+step1</span><span class="p">:</span>
<span class="nt">py></span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">tasks.MyWorkflow.analyze_step1</span>
<span class="nt">+dump</span><span class="p">:</span>
<span class="nt">py></span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">tasks.MyWorkflow.dump</span>
</pre></div>
</div>
</div>
<div class="section" id="using-api">
<h3><a class="toc-backref" href="#id9">Using API</a><a class="headerlink" href="#using-api" title="Permalink to this headline">¶</a></h3>
<p>You can set variables programmably using language API. For example, Python API provides <code class="docutils literal notranslate"><span class="pre">digdag.env.export</span></code> and <code class="docutils literal notranslate"><span class="pre">digdag.env.store</span></code>:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">digdag</span>
<span class="k">class</span> <span class="nc">MyWorkflow</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">prepare</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">digdag</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">store</span><span class="p">({</span><span class="s2">"my_param"</span><span class="p">:</span> <span class="mi">2</span><span class="p">})</span>
<span class="k">def</span> <span class="nf">analyze</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">my_var</span><span class="p">):</span>
<span class="k">print</span><span class="p">(</span><span class="s2">"my_var should be 2: </span><span class="si">%d</span><span class="s2">"</span> <span class="o">%</span> <span class="n">my_var</span><span class="p">)</span>
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">digdag.env.store(dict)</span></code> stores variables so that all following tasks (including tasks which are not children of the task) can use them.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">digdag</span>
<span class="k">class</span> <span class="nc">MyWorkflow</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">export_and_call_child</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">digdag</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">export</span><span class="p">({</span><span class="s2">"my_param"</span><span class="p">:</span> <span class="mi">2</span><span class="p">})</span>
<span class="n">digdag</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">add_subtask</span><span class="p">({</span><span class="s1">'_type'</span><span class="p">:</span> <span class="s1">'call'</span><span class="p">,</span> <span class="s1">'_command'</span><span class="p">:</span> <span class="s1">'child1.dig'</span><span class="p">})</span>
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">digdag.env.export(dict)</span></code> is same with “_export” directive in YAML file. It defines variables for their children.</p>
<p>See language API documents for details:</p>
<ul class="simple">
<li><p><a class="reference external" href="python_api.html">Python API</a></p></li>
<li><p><a class="reference external" href="ruby_api.html">Ruby API</a></p></li>
</ul>
</div>
<div class="section" id="starting-a-session-with-variables">
<h3><a class="toc-backref" href="#id10">Starting a session with variables</a><a class="headerlink" href="#starting-a-session-with-variables" title="Permalink to this headline">¶</a></h3>
<p>You can set variables when you start a new workflow session. To set variables, use <code class="docutils literal notranslate"><span class="pre">-p</span> <span class="pre">KEY=VALUE</span></code> multiple times:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$</span> digdag run -p <span class="nv">my_var1</span><span class="o">=</span>foo -p <span class="nv">my_var2</span><span class="o">=</span>abc
</pre></div>
</div>
</div>
</div>
<div class="section" id="include-another-file">
<h2><a class="toc-backref" href="#id11">!include another file</a><a class="headerlink" href="#include-another-file" title="Permalink to this headline">¶</a></h2>
<p>You can divide a YAML file into small files to organize complex workflow. <code class="docutils literal notranslate"><span class="pre">!include</span></code> directive is used to gather those files:</p>
<div class="highlight-yaml notranslate"><div class="highlight"><pre><span></span><span class="nt">_export</span><span class="p">:</span>
<span class="nt">mysql</span><span class="p">:</span>
<span class="nt">!include </span><span class="p">:</span> <span class="s">'config/mysql.dig'</span>
<span class="nt">hive</span><span class="p">:</span>
<span class="nt">!include </span><span class="p">:</span> <span class="s">'config/hive.dig'</span>
<span class="nt">!include </span><span class="p">:</span> <span class="s">'tasks/foo.dig'</span>
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>A whitespace character before <code class="docutils literal notranslate"><span class="pre">:</span></code> is necessary by a limitation to be a valid YAML.</p>
</div>
</div>
<div class="section" id="parallel-execution">
<h2><a class="toc-backref" href="#id12">Parallel execution</a><a class="headerlink" href="#parallel-execution" title="Permalink to this headline">¶</a></h2>
<p>If <code class="docutils literal notranslate"><span class="pre">_parallel:</span> <span class="pre">true</span></code> parameter is set to a group, child tasks in the group run in parallel (grandchildren are not affected):</p>
<div class="highlight-yaml notranslate"><div class="highlight"><pre><span></span><span class="nt">+prepare</span><span class="p">:</span>
<span class="c1"># +data1, +data2, and +data3 run in parallel.</span>
<span class="nt">_parallel</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">true</span>
<span class="nt">+data1</span><span class="p">:</span>
<span class="nt">sh></span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">tasks/prepare_data1.sh</span>
<span class="nt">+data2</span><span class="p">:</span>
<span class="nt">sh></span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">tasks/prepare_data2.sh</span>
<span class="nt">+data3</span><span class="p">:</span>
<span class="nt">sh></span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">tasks/prepare_data3.sh</span>
<span class="nt">+analyze</span><span class="p">:</span>
<span class="nt">sh></span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">tasks/analyze_prepared_data_sets.sh</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">_parallel:</span> <span class="pre">{limit:</span> <span class="pre">N}</span></code> (N is an integer: 1, 2, 3, …) parameter is set to a group,
child tasks in the group run in parallel is limited to N (grandchildren are not affected):</p>
<div class="highlight-yaml notranslate"><div class="highlight"><pre><span></span><span class="nt">+prepare</span><span class="p">:</span>
<span class="c1"># +data1 and +data2 run in parallel, then +data3 and +data4 run in parallel.</span>
<span class="c1"># (+data1 and +data2 need to be successful.)</span>
<span class="nt">_parallel</span><span class="p">:</span>
<span class="nt">limit</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">2</span>
<span class="nt">+data1</span><span class="p">:</span>
<span class="nt">sh></span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">tasks/prepare_data1.sh</span>
<span class="nt">+data2</span><span class="p">:</span>
<span class="nt">sh></span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">tasks/prepare_data2.sh</span>
<span class="nt">+data3</span><span class="p">:</span>
<span class="nt">sh></span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">tasks/prepare_data3.sh</span>
<span class="nt">+data4</span><span class="p">:</span>
<span class="nt">sh></span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">tasks/prepare_data4.sh</span>
<span class="nt">+analyze</span><span class="p">:</span>
<span class="nt">sh></span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">tasks/analyze_prepared_data_sets.sh</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">_background:</span> <span class="pre">true</span></code> parameter is set to a task or group, the task or group run in parallel with previous tasks. Next task wait for the completion of the background task or group.</p>
<div class="highlight-yaml notranslate"><div class="highlight"><pre><span></span><span class="nt">+prepare</span><span class="p">:</span>
<span class="nt">+data1</span><span class="p">:</span>
<span class="nt">sh></span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">tasks/prepare_data1.sh</span>
<span class="c1"># +data1 and +data2 run in parallel.</span>
<span class="nt">+data2</span><span class="p">:</span>
<span class="nt">_background</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">true</span>
<span class="nt">sh></span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">tasks/prepare_data2.sh</span>
<span class="c1"># +data3 runs after +data1 and +data2.</span>
<span class="nt">+data3</span><span class="p">:</span>
<span class="nt">sh></span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">tasks/prepare_data3.sh</span>
<span class="nt">+analyze</span><span class="p">:</span>
<span class="nt">sh></span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">tasks/analyze_prepared_data_sets.sh</span>
</pre></div>
</div>
</div>
<div class="section" id="retrying-failed-tasks-automatically">
<h2><a class="toc-backref" href="#id13">Retrying failed tasks automatically</a><a class="headerlink" href="#retrying-failed-tasks-automatically" title="Permalink to this headline">¶</a></h2>
<p>If <code class="docutils literal notranslate"><span class="pre">_retry:</span> <span class="pre">N</span></code> (N is an integer: 1, 2, 3, …) parameter is set to a group, it retries the group from the beginning when one or more children failed.</p>
<div class="highlight-yaml notranslate"><div class="highlight"><pre><span></span><span class="nt">+prepare</span><span class="p">:</span>
<span class="c1"># If +erase_table, +load_data, or +check_loaded_data fail, it retries from</span>
<span class="c1"># +erase_table again.</span>
<span class="nt">_retry</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">3</span>
<span class="nt">+erase_table</span><span class="p">:</span>
<span class="nt">sh></span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">tasks/erase_table.sh</span>
<span class="nt">+load_data</span><span class="p">:</span>
<span class="nt">sh></span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">tasks/load_data.sh</span>
<span class="nt">+check_loaded_data</span><span class="p">:</span>
<span class="nt">sh></span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">tasks/check_loaded_data.sh</span>
<span class="nt">+analyze</span><span class="p">:</span>
<span class="nt">sh></span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">tasks/analyze_prepared_data_sets.sh</span>
</pre></div>
</div>
<p>Tasks also support <code class="docutils literal notranslate"><span class="pre">_retry:</span> <span class="pre">N</span></code> parameter to retry the specific task. Note that some operators don’t support the generic <code class="docutils literal notranslate"><span class="pre">_retry</span></code> option but have their own options to control retrying behavior. Operators that involve external systems may reuse previous results. To ensure an external task is repeated, you may use <code class="docutils literal notranslate"><span class="pre">_retry</span></code> at the group level.</p>
<p>You can set interval to _retry as follows.</p>
<div class="highlight-yaml notranslate"><div class="highlight"><pre><span></span><span class="nt">+prepare</span><span class="p">:</span>
<span class="nt">_retry</span><span class="p">:</span>
<span class="nt">limit</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">3</span>
<span class="nt">interval</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">10</span>
<span class="nt">interval_type</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">exponential</span>
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">limit</span></code> is number of retry.
<code class="docutils literal notranslate"><span class="pre">interval</span></code> is interval time (seconds).
Additionaly you can choose <code class="docutils literal notranslate"><span class="pre">interval_type</span></code> as <code class="docutils literal notranslate"><span class="pre">constant</span></code> or <code class="docutils literal notranslate"><span class="pre">exponential</span></code>.
If you set <code class="docutils literal notranslate"><span class="pre">constant</span></code> (default) , interval time is constant as set by <code class="docutils literal notranslate"><span class="pre">limit</span></code>.
If you set <code class="docutils literal notranslate"><span class="pre">exponential</span></code>, interval time increases with each retry as <code class="docutils literal notranslate"><span class="pre">interval</span> <span class="pre">x</span> <span class="pre">2^(retry_count-1)</span></code>.
In the above example, first retry interval is 10 secs, second is 20 secs, third is 40 secs.</p>
</div>
<div class="section" id="sending-error-notification">
<h2><a class="toc-backref" href="#id14">Sending error notification</a><a class="headerlink" href="#sending-error-notification" title="Permalink to this headline">¶</a></h2>
<p>If an operator configuration is set at <code class="docutils literal notranslate"><span class="pre">_error:</span></code> parameter, the operator runs when the workflow fails.</p>
<div class="highlight-yaml notranslate"><div class="highlight"><pre><span></span><span class="c1"># this task runs when a workflow fails.</span>
<span class="nt">_error</span><span class="p">:</span>
<span class="nt">sh></span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">tasks/runs_when_workflow_failed.sh</span>
<span class="nt">+analyze</span><span class="p">:</span>
<span class="nt">sh></span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">tasks/analyze_prepared_data_sets.sh</span>
</pre></div>
</div>
<p>To send mails, you can use <a class="reference external" href="operators/mail.html">mail> operator</a>.</p>
</div>
</div>
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="scheduling_workflow.html" class="btn btn-neutral float-right" title="Scheduling workflow" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="concepts.html" class="btn btn-neutral float-left" title="Concepts" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<p>
© Copyright 2016-2021, Digdag Project
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
<br/>
<br/>
<p><a href="https://digdag.io/">Digdag</a> is an open source project, invented and sponsored by <a href="https://www.treasuredata.com/">Treasure Data, Inc.</a> under the Apache 2.0 Licence.</p>
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>