Documentation

PHP, Python, Node.js

When reporting from inside the code beats wrapping the command.

One rule holds in every language: the monitoring call must not break the job. Wrap it in try and swallow the error — an unreachable Tickwatch has to stay our problem, not your backup’s.

Python
import contextlib
import traceback
import urllib.request

PING = "https://ping.tickwatch.dev/YOUR-KEY"


def ping(suffix: str = "", body: bytes | None = None) -> None:
    url = f"{PING}/{suffix}" if suffix else PING
    with contextlib.suppress(Exception):
        urllib.request.urlopen(url, data=body, timeout=10)


ping("start")
try:
    result = run_job()
    ping(body=str(result).encode()[:10_000])
except Exception:
    ping("fail", traceback.format_exc().encode()[:10_000])
    raise
PHP
<?php

function ping(string $suffix = '', string $body = ''): void
{
    $url = 'https://ping.tickwatch.dev/YOUR-KEY' . ($suffix !== '' ? '/' . $suffix : '');
    $ch = curl_init($url);
    curl_setopt_array($ch, [
        CURLOPT_TIMEOUT        => 10,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_POST           => true,
        CURLOPT_POSTFIELDS     => substr($body, 0, 10000),
    ]);
    curl_exec($ch);   // Ошибку намеренно игнорируем.
    curl_close($ch);
}

ping('start');
try {
    runJob();
    ping();
} catch (Throwable $e) {
    ping('fail', (string) $e);
    throw $e;
}
Node.js
const PING = 'https://ping.tickwatch.dev/YOUR-KEY'

const ping = (suffix = '', body = '') =>
  fetch(suffix ? `${PING}/${suffix}` : PING, {
    method: 'POST',
    body: body.slice(0, 10_000),
    signal: AbortSignal.timeout(10_000),
  }).catch(() => {})

await ping('start')
try {
  await runJob()
  await ping()
} catch (e) {
  await ping('fail', String(e?.stack ?? e))
  throw e
}
PHP, Python, Node.js · Tickwatch