skip to content
==> include/mesh/jobs/spec.h <==
1/* @ajax/mesh-jobs-spec: what a job is (jobs.rs `JobSpec`, `Mode`): a program (or several joined
2 * by commas), an op, its items, a priority, a retry policy, a deadline, a result mode, setup tasks,
3 * when it was submitted and which members may run it; and its one-line text form (`encode`,
4 * `decode`), which is how a Submit op carries it. */
5#ifndef MESH_JOBS_SPEC_H
6#define MESH_JOBS_SPEC_H
7
8#include "mesh/jobs/id.h"
9#include "mesh/jobs/ranges.h"
10#include "mesh/strbuf.h"
11
12#include <stdbool.h>
13#include <stddef.h>
14#include <stdint.h>
15
16/* collect: every item's result and bytes; nonzero: only the items whose result isn't 0; none: only
17 * which items are done. */
18typedef enum { MJ_MODE_COLLECT, MJ_MODE_NONZERO, MJ_MODE_NONE } mj_mode;
19
20const char *mj_mode_word(mj_mode m);
21bool mj_mode_parse(const char *s, mj_mode *out);
22
23typedef struct {
24    uint32_t op, arg;
25} mj_setup;
26
27typedef struct {
28    mj_job_id id;
29    char *program;
30    uint32_t op;
31    mj_ranges items;
32    int32_t priority;      /* higher first; ties: the older job */
33    uint32_t attempts;     /* tries an item gets before it is recorded failed (>= 1) */
34    uint64_t deadline_ms;  /* unix ms after which what is left is given up (0: none) */
35    mj_mode mode;
36    mj_setup *setup;       /* (op, arg) tasks a member runs before its first item of this job */
37    size_t nsetup;
38    uint64_t submitted_ms;
39    uint32_t members;      /* bit k: may run on member k (0: every member that runs the program) */
40} mj_spec;
41
42void mj_spec_free(mj_spec *s);
43mj_spec mj_spec_clone(const mj_spec *s);
44bool mj_spec_eq(const mj_spec *a, const mj_spec *b);
45mj_setup *mj_setup_clone(const mj_setup *s, size_t n);
46
47/* Its items never end (the last range is endless). */
48bool mj_spec_endless(const mj_spec *s);
49/* Whether `name` is one of its programs. */
50bool mj_spec_runs(const mj_spec *s, const char *name);
51/* Its first program (up to the first comma): a pointer into s->program and a length. */
52size_t mj_spec_first_program(const mj_spec *s, const char **p);
53
54/* `id 4294967297 program p op 254 items 0-10 priority 0 attempts 3 deadline 0 mode collect setup 6:0
55 * submitted 5 members 0x5` */
56void mj_spec_encode(const mj_spec *s, msb *out);
57/* The encoded form back; false with *err (the caller frees it) when it isn't one. */
58bool mj_spec_decode(const char *t, mj_spec *out, char **err);
59
60#endif