Skip to content

Commit

Permalink
Deployed 1dd5d7c with MkDocs version: 1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ncrocfer committed Nov 26, 2020
1 parent a09dfe1 commit c1fddf8
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 92 deletions.
149 changes: 78 additions & 71 deletions api/index.html

Large diffs are not rendered by default.

26 changes: 23 additions & 3 deletions guides/build-workflows/index.html
Expand Up @@ -496,6 +496,7 @@ <h1 id="build-workflows">Build Workflows</h1>
<span class="k">pass</span>
</code></pre></div>


<h2 id="chaining-multiple-tasks">Chaining multiple tasks</h2>
<p>Chaining these tasks in the <code>workflows.yml</code> file is pretty simple :</p>
<div class="codehilite"><pre><span></span><code><span class="c1"># Chain example</span>
Expand All @@ -511,6 +512,7 @@ <h2 id="chaining-multiple-tasks">Chaining multiple tasks</h2>
<span class="p p-Indicator">-</span> <span class="l l-Scalar l-Scalar-Plain">C</span>
</code></pre></div>


<p>In this example each task will be executed one after the other : first the task A will
be executed, then the task B and finally the task C.</p>
<h2 id="launch-tasks-in-parallel">Launch tasks in parallel</h2>
Expand All @@ -534,12 +536,14 @@ <h2 id="launch-tasks-in-parallel">Launch tasks in parallel</h2>
<span class="p p-Indicator">-</span> <span class="l l-Scalar l-Scalar-Plain">C</span>
</code></pre></div>


<p>In this example the group is named <strong>GROUP_1</strong> but it can be anything. The important
is to keep unique names in case of multiple groups in your workflow.</p>
<h2 id="periodic-workflows">Periodic workflows</h2>
<p>Celery provides a scheduler used to periodically execute some tasks. This scheduler is named
the <a href="https://docs.celeryproject.org/en/latest/userguide/periodic-tasks.html">Celery beat</a>.</p>
<p>Director allows you to periodically schedule a whole workflow using a simple YAML syntax :</p>
<p>Director allows you to periodically schedule a whole workflow using a simple YAML syntax.</p>
<p>First example:</p>
<div class="codehilite"><pre><span></span><code><span class="nt">example.CHAIN</span><span class="p">:</span>
<span class="nt">tasks</span><span class="p">:</span>
<span class="p p-Indicator">-</span> <span class="l l-Scalar l-Scalar-Plain">A</span>
Expand All @@ -549,12 +553,27 @@ <h2 id="periodic-workflows">Periodic workflows</h2>
<span class="nt">schedule</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">60</span>
</code></pre></div>

<p>The <code>periodic &gt; schedule</code> key takes an integer argument (unity is the second). So in this example
the <em>example.CHAIN</em> worflow will be executed <strong>every 60 seconds</strong>.</p>

<p>Second example:</p>
<div class="codehilite"><pre><span></span><code><span class="nt">example.CHAIN_CRONTAB</span><span class="p">:</span>
<span class="nt">tasks</span><span class="p">:</span>
<span class="p p-Indicator">-</span> <span class="l l-Scalar l-Scalar-Plain">A</span>
<span class="p p-Indicator">-</span> <span class="l l-Scalar l-Scalar-Plain">B</span>
<span class="p p-Indicator">-</span> <span class="l l-Scalar l-Scalar-Plain">C</span>
<span class="nt">periodic</span><span class="p">:</span>
<span class="nt">schedule</span><span class="p">:</span> <span class="s">&quot;*</span><span class="nv"> </span><span class="s">*/3</span><span class="nv"> </span><span class="s">*</span><span class="nv"> </span><span class="s">*</span><span class="nv"> </span><span class="s">*&quot;</span>
</code></pre></div>


<p>The <code>periodic &gt; schedule</code> key takes an integer (unity is the second) or a string argument
(<a href="https://docs.celeryproject.org/en/latest/userguide/periodic-tasks.html#crontab-schedules">crontab</a>
syntax). So in the first example, the <em>example.CHAIN</em> worflow will be executed <strong>every 60 seconds</strong>
and the second one, <em>example.CHAIN_CRONTAB</em>, <strong>every three hours</strong>.</p>
<p>Please note that the scheduler must be started to handle periodic workflows :</p>
<div class="codehilite"><pre><span></span><code>$ director celery beat
</code></pre></div>


<div class="admonition tip">
<p class="admonition-title">Tip</p>
<p>Celery also accepts the <code>-B</code> option when launching a worker :</p>
Expand All @@ -573,6 +592,7 @@ <h2 id="use-of-queues-in-workflows">Use of queues in Workflows</h2>
<span class="nt">queue</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">q1</span>
</code></pre></div>


<p>You need the start Celery worker instance with the <code>--queues</code> option:</p>
<div class="codehilite"><pre><span></span><code>$ director celery worker --loglevel<span class="o">=</span>INFO --queues<span class="o">=</span>q1
</code></pre></div>
Expand Down
1 change: 1 addition & 0 deletions guides/enable-authentication/index.html
Expand Up @@ -441,6 +441,7 @@ <h2 id="manage-user">Manage user</h2>
<div class="codehilite"><pre><span></span><code>$ director user <span class="o">[</span>create<span class="p">|</span>list<span class="p">|</span>update<span class="p">|</span>delete<span class="o">]</span>
</code></pre></div>


<p>Create user example:</p>
<div class="codehilite"><pre><span></span><code>$ director user create john
</code></pre></div>
Expand Down
3 changes: 3 additions & 0 deletions guides/error-tracking/index.html
Expand Up @@ -395,6 +395,7 @@ <h1 id="error-tracking">Error Tracking</h1>
<div class="codehilite"><pre><span></span><code><span class="nv">DIRECTOR_SENTRY_DSN</span><span class="o">=</span><span class="s2">&quot;https://xyz@sentry.example.com/0&quot;</span>
</code></pre></div>


<p>Let's imagine the following workflow :</p>
<div class="codehilite"><pre><span></span><code><span class="c1"># workflows.yml</span>
<span class="nn">---</span>
Expand All @@ -404,6 +405,7 @@ <h1 id="error-tracking">Error Tracking</h1>
<span class="p p-Indicator">-</span> <span class="l l-Scalar l-Scalar-Plain">ERROR_TASK</span>
</code></pre></div>


<p>With the associated tasks :</p>
<div class="codehilite"><pre><span></span><code><span class="c1"># tasks/example.py</span>
<span class="kn">from</span> <span class="nn">director</span> <span class="kn">import</span> <span class="n">task</span>
Expand All @@ -417,6 +419,7 @@ <h1 id="error-tracking">Error Tracking</h1>
<span class="nb">print</span><span class="p">(</span><span class="mi">1</span><span class="o">/</span><span class="mi">0</span><span class="p">)</span>
</code></pre></div>


<p>When a Celery worker will execute this code, an issue will be created in Sentry with the <code>ZeroDivisionError</code> :</p>
<p><img alt="Sentry issue" src="../../img/sentry_issue.png" /></p>
<p>In order to group the issues by workflow's name or by project, Director associated some tags to the event :</p>
Expand Down
10 changes: 6 additions & 4 deletions guides/run-workflows/index.html
Expand Up @@ -471,16 +471,18 @@ <h2 id="using-the-cli">Using the CLI</h2>
<div class="codehilite"><pre><span></span><code>$ director workflow run ovh.MY_WORKFLOW
</code></pre></div>


<h2 id="using-the-api">Using the API</h2>
<p>You can run a workflow using a POST request on the Director API. This is very
convenient if your applications are based on webservices.</p>
<p>The request is a <strong>POST</strong> on the <code>/api/workflows</code> endpoint :</p>
<div class="codehilite"><pre><span></span><code><span class="o">$</span> <span class="n">curl</span> <span class="o">--</span><span class="n">header</span> <span class="s2">&quot;Content-Type: application/json&quot;</span> \
<span class="o">--</span><span class="n">request</span> <span class="n">POST</span> \
<span class="o">--</span><span class="n">data</span> <span class="s1">&#39;{&quot;project&quot;:&quot;ovh&quot;, &quot;name&quot;: &quot;MY_WORKFLOW&quot;, &quot;payload&quot;: {}}&#39;</span> \
<span class="n">http</span><span class="p">:</span><span class="o">//</span><span class="n">localhost</span><span class="p">:</span><span class="mi">8000</span><span class="o">/</span><span class="n">api</span><span class="o">/</span><span class="n">workflows</span>
<div class="codehilite"><pre><span></span><code>$ curl --header <span class="s2">&quot;Content-Type: application/json&quot;</span> <span class="se">\</span>
--request POST <span class="se">\</span>
--data <span class="s1">&#39;{&quot;project&quot;:&quot;ovh&quot;, &quot;name&quot;: &quot;MY_WORKFLOW&quot;, &quot;payload&quot;: {}}&#39;</span> <span class="se">\</span>
http://localhost:8000/api/workflows
</code></pre></div>


<div class="admonition info">
<p class="admonition-title">Technical explanation</p>
<p>To really understand this feature it's important to know how native Celery works.</p>
Expand Down
17 changes: 13 additions & 4 deletions guides/use-payload/index.html
Expand Up @@ -486,6 +486,7 @@ <h1 id="use-payload">Use Payload</h1>
<span class="p p-Indicator">-</span> <span class="l l-Scalar l-Scalar-Plain">SEND_MAIL</span>
</code></pre></div>


<p>This usecase is simple :</p>
<ol>
<li>the fist task creates an order about a specific product,</li>
Expand All @@ -497,13 +498,15 @@ <h2 id="send-payload">Send payload</h2>
<div class="codehilite"><pre><span></span><code>$ director workflow run product.ORDER <span class="s1">&#39;{&quot;user&quot;: 1234, &quot;product&quot;: 1000}&#39;</span>
</code></pre></div>


<p>or</p>
<div class="codehilite"><pre><span></span><code><span class="o">$</span> <span class="n">curl</span> <span class="o">--</span><span class="n">header</span> <span class="s2">&quot;Content-Type: application/json&quot;</span> \
<span class="o">--</span><span class="n">request</span> <span class="n">POST</span> \
<span class="o">--</span><span class="n">data</span> <span class="s1">&#39;{&quot;project&quot;: &quot;product&quot;, &quot;name&quot;: &quot;ORDER&quot;, &quot;payload&quot;: {&quot;user&quot;: 1234, &quot;product&quot;: 1000}}&#39;</span> \
<span class="n">http</span><span class="p">:</span><span class="o">//</span><span class="n">localhost</span><span class="p">:</span><span class="mi">8000</span><span class="o">/</span><span class="n">api</span><span class="o">/</span><span class="n">workflows</span>
<div class="codehilite"><pre><span></span><code>$ curl --header <span class="s2">&quot;Content-Type: application/json&quot;</span> <span class="se">\</span>
--request POST <span class="se">\</span>
--data <span class="s1">&#39;{&quot;project&quot;: &quot;product&quot;, &quot;name&quot;: &quot;ORDER&quot;, &quot;payload&quot;: {&quot;user&quot;: 1234, &quot;product&quot;: 1000}}&#39;</span> <span class="se">\</span>
http://localhost:8000/api/workflows
</code></pre></div>


<h2 id="handle-payload">Handle payload</h2>
<p>You can handle the payload in the code using the <strong>kwargs</strong> dictionnary :</p>
<div class="codehilite"><pre><span></span><code><span class="nd">@task</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s2">&quot;ORDER_PRODUCT&quot;</span><span class="p">)</span>
Expand All @@ -524,6 +527,7 @@ <h2 id="handle-payload">Handle payload</h2>
<span class="n">mail</span><span class="o">.</span><span class="n">send</span><span class="p">()</span>
</code></pre></div>


<p>As you can see the payload is forwarded to <strong>all the tasks</strong> contained in
your workflow.</p>
<h2 id="create-the-schema">Create the schema</h2>
Expand All @@ -542,6 +546,7 @@ <h2 id="create-the-schema">Create the schema</h2>
<span class="o">}</span>
</code></pre></div>


<p>Then you can reference it in your workflow using the <code>schema</code> keyword :</p>
<div class="codehilite"><pre><span></span><code><span class="nt">product.ORDER</span><span class="p">:</span>
<span class="nt">tasks</span><span class="p">:</span>
Expand All @@ -550,6 +555,7 @@ <h2 id="create-the-schema">Create the schema</h2>
<span class="nt">schema</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">order</span>
</code></pre></div>


<div class="admonition tip">
<p class="admonition-title">Tip</p>
<p>You can host your schemas into subfolders (ie <code>$DIRECTOR_HOME/schemas/foo/bar/baz.json</code>)
Expand All @@ -562,6 +568,7 @@ <h2 id="create-the-schema">Create the schema</h2>
Aborted!
</code></pre></div>


<p>The API returns a <code>400 Bad request</code> error.</p>
<h2 id="periodic-workflows">Periodic workflows</h2>
<p>Celery Director provides a YAML syntax to <a href="../build-workflows/#periodic-workflows">periodically schedule a workflow</a>.
Expand All @@ -574,6 +581,7 @@ <h2 id="periodic-workflows">Periodic workflows</h2>
<span class="nt">payload</span><span class="p">:</span> <span class="p p-Indicator">{</span><span class="s">&quot;user&quot;</span><span class="p p-Indicator">:</span> <span class="nv">False</span><span class="p p-Indicator">}</span>
</code></pre></div>


<p>The corresponding task can easily handle this default value :</p>
<div class="codehilite"><pre><span></span><code><span class="nd">@task</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s2">&quot;UPDATE_CACHE&quot;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">update_cache</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
Expand All @@ -584,6 +592,7 @@ <h2 id="periodic-workflows">Periodic workflows</h2>
<span class="k">return</span> <span class="n">update_user</span><span class="p">(</span><span class="n">user</span><span class="p">)</span>
</code></pre></div>


<p>This way the whole list of users will be updated every hours, and a manual update
can be done on a specific user :</p>
<div class="codehilite"><pre><span></span><code>$ director workflow run users.UPDATE_CACHE <span class="s1">&#39;{&quot;user&quot;: &quot;john.doe&quot;}&#39;</span>
Expand Down
4 changes: 4 additions & 0 deletions guides/write-tasks/index.html
Expand Up @@ -493,6 +493,7 @@ <h2 id="create-a-task">Create a task</h2>
<span class="k">pass</span>
</code></pre></div>


<div class="admonition warning task naming">
<p class="admonition-title">Warning</p>
<p>The <code>name</code> parameter in the task decorator is mandatory. Because it will be used in the YAML
Expand Down Expand Up @@ -530,6 +531,7 @@ <h2 id="task-signature">Task signature</h2>
<span class="nb">print</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>
</code></pre></div>


<p>The following workflows present different usecases and the output of the C task (see the
<a href="../build-workflows/">Build Workflows</a> guide to understand the YAML format) :</p>
<div class="codehilite"><pre><span></span><code><span class="nt">example.NO_PARENT</span><span class="p">:</span>
Expand All @@ -555,6 +557,7 @@ <h2 id="task-signature">Task signature</h2>
<span class="c1"># Result : ([{&#39;result&#39;: &#39;a_data&#39;}, {&#39;result&#39;: &#39;b_data&#39;}],)</span>
</code></pre></div>


<h2 id="bound-tasks">Bound Tasks</h2>
<p>Celery allows use to <a href="https://docs.celeryproject.org/en/latest/userguide/tasks.html#bound-tasks">bind a task</a>,
providing the task instance itself as the first parameter.</p>
Expand All @@ -567,6 +570,7 @@ <h2 id="bound-tasks">Bound Tasks</h2>
<span class="nb">print</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
</code></pre></div>


<h2 id="celery-task-options">Celery Task Options</h2>
<p>The <code>task()</code> decorator provided by Director is just a wrapper of the native <code>app.task()</code> decorator
provided by Celery, so all the <a href="https://docs.celeryproject.org/en/latest/userguide/tasks.html#list-of-options">original options</a> are still available.</p>
Expand Down
6 changes: 6 additions & 0 deletions index.html
Expand Up @@ -568,6 +568,7 @@ <h2 id="installation">Installation</h2>
<div class="codehilite"><pre><span></span><code>pip install celery-director
</code></pre></div>


<h2 id="usage">Usage</h2>
<h3 id="write-your-code-in-python">Write your code in Python</h3>
<div class="codehilite"><pre><span></span><code><span class="c1"># tasks/orders.py</span>
Expand All @@ -592,6 +593,7 @@ <h3 id="write-your-code-in-python">Write your code in Python</h3>
<span class="n">mail</span><span class="o">.</span><span class="n">send</span><span class="p">()</span>
</code></pre></div>


<h3 id="build-your-workflows-in-yaml">Build your workflows in YAML</h3>
<div class="codehilite"><pre><span></span><code><span class="c1"># workflows.yml</span>
<span class="nt">product.ORDER</span><span class="p">:</span>
Expand All @@ -600,18 +602,21 @@ <h3 id="build-your-workflows-in-yaml">Build your workflows in YAML</h3>
<span class="p p-Indicator">-</span> <span class="l l-Scalar l-Scalar-Plain">SEND_MAIL</span>
</code></pre></div>


<h3 id="run-it">Run it</h3>
<p>You can simply test your workflow in local :</p>
<div class="codehilite"><pre><span></span><code>$ director workflow run product.ORDER <span class="s1">&#39;{&quot;user&quot;: 1234, &quot;product&quot;: 1000}&#39;</span>
</code></pre></div>


<p>And run it in production using the director API :</p>
<div class="codehilite"><pre><span></span><code>$ curl --header <span class="s2">&quot;Content-Type: application/json&quot;</span> <span class="se">\</span>
--request POST <span class="se">\</span>
--data <span class="s1">&#39;{&quot;project&quot;: &quot;product&quot;, &quot;name&quot;: &quot;ORDER&quot;, &quot;payload&quot;: {&quot;user&quot;: 1234, &quot;product&quot;: 1000}}&#39;</span> <span class="se">\</span>
http://localhost:8000/api/workflows
</code></pre></div>


<h2 id="project-layout">Project layout</h2>
<div class="codehilite"><pre><span></span><code><span class="na">.env</span> <span class="c1"># The configuration file.</span>
<span class="nf">workflows.yml</span> <span class="c1"># The workflows definition.</span>
Expand All @@ -620,6 +625,7 @@ <h2 id="project-layout">Project layout</h2>
<span class="na">...</span> <span class="c1"># Other files containing other tasks.</span>
</code></pre></div>


<h2 id="commands">Commands</h2>
<ul>
<li><code>director init [path]</code> - Create a new project.</li>
Expand Down

0 comments on commit c1fddf8

Please sign in to comment.