You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

17 lines
1.4 KiB

  1. <div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">requests</span>
  2. <span class="n">URL</span> <span class="o">=</span> <span class="s2">&quot;{{ ping_url }}&quot;</span>
  3. <span class="k">def</span> <span class="nf">do_work</span><span class="p">():</span>
  4. <span class="c1"># Do your number crunching, backup dumping, newsletter sending work here.</span>
  5. <span class="c1"># Return a truthy value on success.</span>
  6. <span class="c1"># Return a falsy value or throw an exception on failure.</span>
  7. <span class="k">return</span> <span class="bp">True</span>
  8. <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
  9. <span class="k">try</span><span class="p">:</span>
  10. <span class="n">success</span> <span class="o">=</span> <span class="n">do_work</span><span class="p">()</span>
  11. <span class="k">finally</span><span class="p">:</span>
  12. <span class="c1"># On success, requests {{ ping_url }}</span>
  13. <span class="c1"># On failure, requests {{ ping_url }}/fail</span>
  14. <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>
  15. </pre></div>