Examples
order-sync
A job that applies orders to an inventory in SQLite and prints sync finished OK, the demo of the ormaos-python README.
A job that reads orders from a CSV file, checks each one, and applies it to an inventory in SQLite. It prints sync finished: OK. It is the demo of the README of ormaos-python, and the program of the Quickstart.
- Source:
ormaos-examples/order-sync - Guide: Scheduled job
Run it#
./reset.sh puts the data back as it was, so that every run starts from the same inventory.
./reset.sh
python job.py$ python job.py
sync finished: OKRecorded#
./reset.sh
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:c1$ ormaos show
r1 exit 0 in …: 1 Python process, 322 calls, 7 exceptions (6 swallowed, 0 uncaught)
command: python job.py
code: git commit not read (the working directory is not inside a git repository)
swallowed 6x validate.SkuFormatError at job.py:57 in sync_orders, raised at validate.py:24 [r1:e1]
io: 182 events (sqlite 181, file 1)
io: 30x sqlite "SELECT on_hand, pack_size FROM stock WHERE sku = ?" from inventory.py:87 [r1:i3]
io: 30x sqlite "SELECT ? FROM applied_orders WHERE order_id = ?" from inventory.py:92 [r1:i4]
io: 30x sqlite BEGIN from inventory.py:101 [r1:i5]
io: 30x sqlite "UPDATE stock SET on_hand = on_hand - ? WHERE sku = ?" from inventory.py:101 [r1:i6]
io: 30x sqlite "INSERT INTO applied_orders (order_id, sku, quantity, applied_at) VALU..." from inventory.py:105 [r1:i7]
... 1 more lines of code repeated io: ormaos io r1
logs: 8 logging records (WARNING 6, INFO 2), 8 dropped by the level
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`)
never recorded: values, and 20 more kinds of things (`ormaos show --full` lists them with the reason)
next: ormaos exceptions r1:e1 | ormaos tree r1:c1 | ormaos io r1 | ormaos io r1:i3 | ormaos logs r1The recordings on this site#
| Recording | Command | What changed |
|---|---|---|
r1 | ormaos run -- python job.py | nothing: the job as it is |
r2 | ormaos run --path job.py:sync_orders -- python job.py | lines recorded inside sync_orders |
r3 | ormaos run -- python job.py | parse.py cleans the SKU when a row is read (sku=row["sku"].strip().upper(),) |
r4 | ormaos run --values -- python job.py | parse.py as it was; values recorded |
r5 | ormaos run --only context,exceptions,io --json-out overview.json -- python job.py | only context, exceptions and I/O |
./reset.sh runs before each of them.
$ 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:c167