# openloops.whenthen_job

Handing the periodic jobs to whenthen: register a job, take over from the launchd agent.

whenthen is the fleet’s scheduler (one clock, run records, `whenthen status`). Each job
this package used to install as a launchd agent (the digest sync, the reminder tick, the
pile nudge, the board receiver, the board refresh) can instead be a whenthen job; this
module is the one place that knows how. It is used when `python -m whenthen --help`
works under the interpreter openloops runs in, and never required: without it the
installers behave as before.

A job’s name is its launchd label with the dots turned into dashes
(`openloops.remind-tick` -> `openloops-remind-tick`), so the label still names it.

### Functions

| [`job_name`](#openloops.whenthen_job.job_name)(label)                              | The whenthen job for a launchd label.                                                   |
|-----------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------|
| [`every_flag`](#openloops.whenthen_job.every_flag)(seconds)                          | An interval as whenthen's `--every` value.                                              |
| [`whenthen`](#openloops.whenthen_job.whenthen)(\*args)                             | `python -m whenthen <args>` under this interpreter: `(exit code, parsed JSON or text)`. |
| [`available`](#openloops.whenthen_job.available)()                                  | Whether whenthen can be run under this interpreter (never a hard dependency).           |
| [`register`](#openloops.whenthen_job.register)(\*, label, intent_file, intent_key) | Add the job for `label` and stop its launchd agent (`take_over`).                       |
| [`status`](#openloops.whenthen_job.status)(label)                                | The whenthen job's state for `label`; `None` when whenthen or the job is absent.        |
| [`remove`](#openloops.whenthen_job.remove)(label)                                | Remove the whenthen job for `label` if there is one.                                    |

### openloops.whenthen_job.available()

Whether whenthen can be run under this interpreter (never a hard dependency).

* **Return type:**
  [`bool`](https://docs.python.org/3/builtins/functions.html#bool)

### openloops.whenthen_job.every_flag(seconds)

An interval as whenthen’s `--every` value.

```pycon
>>> every_flag(900), every_flag(21600), every_flag(60)
('15m', '6h', '1m')
```

* **Return type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

### openloops.whenthen_job.job_name(label)

The whenthen job for a launchd label.

```pycon
>>> job_name("openloops.remind-tick")
'openloops-remind-tick'
```

* **Return type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

### openloops.whenthen_job.register(, label, intent_file, intent_key, params=None, interval, env=None, cwd=None, env_file=None, timeout='30m', delay=None, source, quote='', take_over, restore, dry_run=False, run_once=False)

Add the job for `label` and stop its launchd agent (`take_over`).

Order: vocabulary entry, dry run, `take_over`, add. A failed add calls `restore`
(the old agent installed again) and raises. Returns `scheduler`, `job`, `echo`,
`interval` and, with `run_once`, `first_run` (its status).

* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]

### openloops.whenthen_job.remove(label)

Remove the whenthen job for `label` if there is one. True when one was removed.

* **Return type:**
  [`bool`](https://docs.python.org/3/builtins/functions.html#bool)

### openloops.whenthen_job.status(label)

The whenthen job’s state for `label`; `None` when whenthen or the job is absent.

* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`object`](https://docs.python.org/3/builtins/functions.html#object)] | [`None`](https://docs.python.org/3/builtins/constants.html#None)

### openloops.whenthen_job.whenthen(\*args)

`python -m whenthen <args>` under this interpreter: `(exit code, parsed JSON or text)`.

* **Return type:**
  [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[`int`](https://docs.python.org/3/builtins/functions.html#int), [`object`](https://docs.python.org/3/builtins/functions.html#object)]
