MIRTEL

Your own code

If you wrote the job yourself, reporting is one web request at the end. Put it in a finally block, so it runs whether the job worked or not.

1. Add the agent

In the dashboard, add the agent with its schedule and what success looks like. Copy the link Mirtel shows you; she shows it only once. Keep it in an environment variable, not in your code:

export MIRTEL_LINK='https://YOUR-MIRTEL-HOST/r/mrt_agent_…'

Node

Node 18 or later has fetch built in. This works in a plain CommonJS .js file.

async function report(body) {
  try {
    await fetch(process.env.MIRTEL_LINK, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify(body),
      signal: AbortSignal.timeout(10000), // give up after 10 seconds
    });
  } catch {} // never let reporting break the job
}

async function main() {
  let result = { status: 'failed', error: 'stopped before finishing' };
  try {
    const items = await runJob();
    result = { status: items.length ? 'done' : 'empty', items: items.length, output: `${items.length} items` };
  } catch (err) {
    result = { status: 'failed', error: String(err.message || err) };
    throw err;
  } finally {
    await report(result);
  }
}

main().catch(() => { process.exitCode = 1; });

Python

This uses requests. If you don't have it yet: pip install requests.

import os, requests

def report(**body):
    try:
        requests.post(os.environ["MIRTEL_LINK"], json=body, timeout=10)
    except requests.RequestException:
        pass  # never let reporting break the job

result = {"status": "failed", "error": "stopped before finishing"}
try:
    items = run_job()
    result = {"status": "done" if items else "empty", "items": len(items)}
except Exception as e:
    result = {"status": "failed", "error": str(e)}
    raise
finally:
    report(**result)

What to send

No Authorization header is needed. The link is the key. The full field rules are in the API reference.

Check it worked

Run the job once by hand and look at the ledger. Then make it throw on purpose and check that the run shows as Failed, not Missed.

Anyone with the link can report as this agent. If it leaks, rotate the agent's key in the dashboard; the old link stops working at once.