An archive you cannot see is not empty

Part 6 of 7 of ./blog.sh v1.5

This site's approved comments and its post counters are two small JSON files, refreshed by a cron job every half hour and uploaded with the rest of the site.

Through 1.4, a tick that ran while the archive was not there would narrow both files to nothing and upload them. An absent or empty content directory answers with an empty list and no error, and an empty list reads exactly like "every announced post was deleted". The live site lost every approved comment and every counter at once. Exit 0, nothing said, nothing mailed.

The archive lives on a synced volume. A volume that has not mounted yet, or a working copy whose files are still arriving, is not an unusual Tuesday.

Not being able to tell is a reason to keep everything

That sentence is the fix, and it now runs in two tiers.

If the content directory is not there — or if the archive reads as empty while the previous files held anything at all — nothing is narrowed, and the run says why.

And if only part of the archive is unreadable, a post file that will not parse this minute, a half-written save, a cloud copy still arriving, nothing is narrowed either. Otherwise that gap would be read as a post that was deleted, and its approved discussion deleted along with it. Only a run that could read the whole archive is allowed to decide that something is gone.

The same mistake, one job over

The scheduled-publish cron had a sibling of this. It took a snapshot of the due posts when it started and wrote that snapshot back when it finished, so everything that happened in between was overwritten. An edit made while it worked was silently replaced with the older text. A post deleted in the meantime was recreated from the snapshot, published, and announced to a timeline that cannot be recalled.

Each post is re-read at the moment it is written now.

Why these two are worth a post

Neither of them is a crash. Both jobs ran, both exited 0, both reported success, and one of them was announcing things to the world while it did.

That is the failure worth being afraid of in a tool that runs unattended: not the job that stops, but the job that carries on confidently with a wrong idea of what your archive contains. A crash you find out about. This kind you find out about when somebody asks where their comment went.

Comments