Guides
Scheduled job
Record a job that runs on a schedule and read what it caught and skipped, what it wrote, and what it logged that the level never let out.
A job that runs at night prints OK and exits with 0. Ormaos records what happened inside: which items went through each step, which exceptions were caught and skipped, what the job wrote and where, and which log records the level dropped. The example is order-sync, the job of the Quickstart.
Record it where it runs#
Put ormaos run -- in front of the command the scheduler runs. The exit code is the job's own, so the scheduler sees the same result.
ormaos run -- python job.py$ ormaos run -- python job.py
sync finished: OK
ormaos: r1 exit 0 in …: 1 Python process, 322 calls, 7 exceptions (6 swallowed), 182 io
ormaos: swallowed 6x validate.SkuFormatError at job.py:57, raised at validate.py:24 [r1:e1]
ormaos: not collected: io: reads of the 1 file opened at fetch.py:26: opened for reading, and no `read` call by Python code was seen on a file of that name: if it was read, that was inside C code (a file that is iterated, `for line in f`, `csv.reader`)
ormaos: saved in .ormaos/r1, next: ormaos exceptions r1:e1 | ormaos tree r1:c1It printed OK: what was caught and skipped?#
$ ormaos exceptions r1
r1: 7 exceptions (6 swallowed, 0 uncaught)
r1:e1 swallowed validate.SkuFormatError raised at validate.py:24 handled at job.py:57 in sync_orders
r1:e2 swallowed validate.SkuFormatError raised at validate.py:24 handled at job.py:57 in sync_orders
r1:e3 swallowed validate.SkuFormatError raised at validate.py:24 handled at job.py:57 in sync_orders
r1:e4 swallowed validate.SkuFormatError raised at validate.py:24 handled at job.py:57 in sync_orders
r1:e5 swallowed validate.SkuFormatError raised at validate.py:24 handled at job.py:57 in sync_orders
r1:e6 swallowed validate.SkuFormatError raised at validate.py:24 handled at job.py:57 in sync_orders
r1:e7 exit SystemExit raised at job.py:86
next: ormaos exceptions r1:e1 | ormaos exceptions r1:e2 | ormaos tree r1:c130How many items went through each step?#
$ ormaos tree r1 --function check_order --limit 5
r1: 36 of the 322 calls match --function check_order (36 check_order; 6 raised)
r1:c131 check_order(order: parse.Order) -> NoneType validate.py:47 … calls below: 3
r1:c137 check_order(order: parse.Order) -> NoneType validate.py:47 … calls below: 3
r1:c143 check_order(order: parse.Order) -> NoneType validate.py:47 … calls below: 3
r1:c149 check_order(order: parse.Order) -> NoneType validate.py:47 … calls below: 3
r1:c155 check_order(order: parse.Order) -> NoneType validate.py:47 … calls below: 3
... 31 more: --offset 5
next: ormaos tree r1:c131 | ormaos tree r1:c137 | ormaos tree r1 --offset 5 --function check_order | ormaos tree r1 | ormaos exceptions r136 orders were checked, and 6 checks raised. The calls of the step after it:
$ ormaos tree r1:c130 --depth 1 --limit 4
inside: r1:c1 <module> > r1:c16 main
r1:c130 sync_orders(conn: sqlite3.Connection, orders: list[36 parse.Order]) -> int job.py:49 … io 180 logs 6 [swallowed 6x validate.SkuFormatError: r1:e1] calls below: 66
r1:c131 check_order(order: parse.Order) -> NoneType validate.py:47 … calls below: 3
r1:c135 apply_order(conn: sqlite3.Connection, order: parse.Order) -> bool inventory.py:78 … io 6 calls below: 1
r1:c137 check_order(order: parse.Order) -> NoneType validate.py:47 … calls below: 3
... 63 of the 66 calls directly below r1:c130 are not shown (34 check_order, 29 apply_order; 6 raised): --offset 3
next: ormaos exceptions r1:e1 | ormaos tree r1:c130 --offset 3 | ormaos tree r1:c131 | ormaos tree r1:c16 | ormaos exceptions r1:c130What did it write, and where?#
$ ormaos io r1:e1
r1:e1 sync_orders and the calls below it: 180 io events (sqlite 180)
30x sqlite "SELECT on_hand, pack_size FROM stock WHERE sku = ?" at inventory.py:87 in apply_order [r1:i3]
30x sqlite "SELECT ? FROM applied_orders WHERE order_id = ?" at inventory.py:92 in apply_order [r1:i4]
30x sqlite BEGIN at inventory.py:101 in apply_order [r1:i5]
30x sqlite "UPDATE stock SET on_hand = on_hand - ? WHERE sku = ?" at inventory.py:101 in apply_order [r1:i6]
30x sqlite "INSERT INTO applied_orders (order_id, sku, quantity, applied_at) VALU..." at inventory.py:105 in apply_order [r1:i7]
30x sqlite COMMIT at inventory.py:100 in apply_order [r1:i8]
calls directly below: 36 check_order (6 raised, no io), 30 apply_order (180 io)
next: ormaos io r1:i3 | ormaos io r1:i4 | ormaos tree r1:c130 | ormaos io r1:c16$ ormaos io r1 --kind file
r1: 182 io events (sqlite 181, file 1), showing file
1x file open data/orders.csv (read) at fetch.py:26 in from_csv [r1:i2]
next: ormaos io r1:i2 | ormaos io r1:c20 | ormaos exceptions r1What did it log that the level never let out?#
$ ormaos logs r1
r1: 8 logging records (WARNING 6, INFO 2), 8 dropped by the level
1x INFO order_sync "reading orders from %s" dropped by the level at job.py:44 in load_orders [r1:l1]
6x WARNING order_sync "order %s skipped: %s" dropped by the level at job.py:58 in sync_orders [r1:l2]
1x INFO order_sync "%d orders read, %d applied in this run" dropped by the level at job.py:80 in main [r1:l3]
next: ormaos logs r1:l1 | ormaos logs r1:l2 | ormaos tree r1:c19 | ormaos exceptions r1The level of the job's logger dropped all eight records, INFO and WARNING: no handler saw them. Ormaos records them where your code asked for them, with the template and how many arguments, never the arguments.
The next night#
Recordings are numbered; ormaos list shows them, newest first, and ormaos diff compares two nights by place in the code:
$ ormaos diff r1 r3
r1 -> r3, matched by place in the code and order, not by address
r1: exit 0, 322 calls, 7 exceptions, 182 io events, 8 logging records
r3: exit 0, 346 calls, 1 exception, 218 io events, 2 logging records
calls: 6 of 31 places differ
check_order at validate.py:47: 36 calls in both; 6 raised in r1, none in r3; call 7 raised in r1 and returned in r3 [r1:c167 r3:c167]
check_sku at validate.py:22: 36 calls in both; 6 raised in r1, none in r3; call 7 raised in r1 and returned in r3 [r1:c168 r3:c168]
check_quantity at validate.py:27: 30 calls in r1, 36 in r3 [r1:c133 r3:c133]
check_unit at validate.py:42: 30 calls in r1, 36 in r3 [r1:c134 r3:c134]
apply_order at inventory.py:78: 30 calls in r1, 36 in r3 [r1:c135 r3:c135]
to_units at inventory.py:71: 30 calls in r1, 36 in r3 [r1:c136 r3:c136]
exceptions: 1 of 2 groups differ
swallowed validate.SkuFormatError, raised at validate.py:24, handled at job.py:57: 6 in r1, none in r3 [r1:e1]
io: 6 of 8 groups differ
sqlite "SELECT on_hand, pack_size FROM stock WHERE sku = ?" at inventory.py:87 in apply_order: 30 in r1, 36 in r3 [r1:i3 r3:i3]
sqlite "SELECT ? FROM applied_orders WHERE order_id = ?" at inventory.py:92 in apply_order: 30 in r1, 36 in r3 [r1:i4 r3:i4]
sqlite BEGIN at inventory.py:101 in apply_order: 30 in r1, 36 in r3 [r1:i5 r3:i5]
sqlite "UPDATE stock SET on_hand = on_hand - ? WHERE sku = ?" at inventory.py:101 in apply_order: 30 in r1, 36 in r3 [r1:i6 r3:i6]
sqlite "INSERT INTO applied_orders (order_id, sku, quantity, applied_at) VALU..." at inventory.py:105 in apply_order: 30 in r1, 36 in r3 [r1:i7 r3:i7]
sqlite COMMIT at inventory.py:100 in apply_order: 30 in r1, 36 in r3 [r1:i8 r3:i8]
logs: 1 of 3 groups differ
WARNING order_sync "order %s skipped: %s" dropped by the level at job.py:58 in sync_orders: 6 in r1, none in r3 [r1:l2]
data: the same in both (0 places)
not compared: values, shapes of arguments and results, durations, cpu and memory, the lines of `path`, which process or thread an event was in, the versions of the code
next: ormaos exceptions r1:e1 | ormaos tree r1:c167 | ormaos io r1:i3 | ormaos logs r1:l2 | ormaos tree r3:c167Notes for jobs#
.ormaos/grows with every run; Ormaos deletes nothing.ormaos statussays how much space it uses.- A job killed by the scheduler leaves an
incompleterecording that can still be read;ormaos showsays which signal ended it and who sent it. - The version of the code is recorded when the job runs inside a git repository.