|
|
- <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="c1"># "/start" kicks off a timer: if the job takes longer than</span>
- <span class="c1"># the configured grace time, the check will be marked as "down"</span>
- <span class="k">try</span><span class="p">:</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="o">+</span> <span class="s2">"/start"</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
- <span class="k">except</span> <span class="n">requests</span><span class="o">.</span><span class="n">exceptions</span><span class="o">.</span><span class="n">RequestException</span><span class="p">:</span>
- <span class="c1"># If the network request fails for any reason, we don't want</span>
- <span class="c1"># it to prevent the main job from running</span>
- <span class="k">pass</span>
-
-
- <span class="c1"># TODO: run the job here</span>
- <span class="n">fib</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">n</span><span class="p">:</span> <span class="n">n</span> <span class="k">if</span> <span class="n">n</span> <span class="o"><</span> <span class="mi">2</span> <span class="k">else</span> <span class="n">fib</span><span class="p">(</span><span class="n">n</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="n">fib</span><span class="p">(</span><span class="n">n</span> <span class="o">-</span> <span class="mi">2</span><span class="p">)</span>
- <span class="nb">print</span><span class="p">(</span><span class="s2">"F(42) = </span><span class="si">%d</span><span class="s2">"</span> <span class="o">%</span> <span class="n">fib</span><span class="p">(</span><span class="mi">42</span><span class="p">))</span>
-
- <span class="c1"># Signal success:</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="p">)</span>
- </pre></div>
|