mirror of
https://github.com/healthchecks/healthchecks.git
synced 2024-11-23 16:07:39 +00:00
18 lines
1.4 KiB
HTML
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">"{{ ping_url }}"</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">"/fail"</span><span class="p">)</span>
|
|
</pre></div>
|