healthchecks_healthchecks/templates/front/snippets/python_requests_fail.html
2020-03-02 13:37:29 +02:00

18 lines
1.4 KiB
HTML

<div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">requests</span>
<span class="n">URL</span> <span class="o">=</span> <span class="s2">&quot;{{ ping_url }}&quot;</span>
<span class="k">def</span> <span class="nf">do_work</span><span class="p">():</span>
<span class="c1"># Do your number crunching, backup dumping, newsletter sending work here.</span>
<span class="c1"># Return a truthy value on success.</span>
<span class="c1"># Return a falsy value or throw an exception on failure.</span>
<span class="k">return</span> <span class="kc">True</span>
<span class="n">success</span> <span class="o">=</span> <span class="kc">False</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">success</span> <span class="o">=</span> <span class="n">do_work</span><span class="p">()</span>
<span class="k">finally</span><span class="p">:</span>
<span class="c1"># On success, requests {{ ping_url }}</span>
<span class="c1"># On failure, requests {{ ping_url }}/fail</span>
<span class="n">requests</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">URL</span> <span class="k">if</span> <span class="n">success</span> <span class="k">else</span> <span class="n">URL</span> <span class="o">+</span> <span class="s2">&quot;/fail&quot;</span><span class="p">)</span>
</pre></div>