#job #json #task #events #dispatch #sorting #inotify

json-job-dispatch

Dispatch jobs described by JSON files and sort them according to their status

11 stable releases

3.0.2 May 30, 2023
3.0.1 Apr 10, 2022
3.0.0 Nov 22, 2021
2.0.1 Nov 19, 2019
1.0.1 Jan 18, 2017

#215 in Compression

31 downloads per month

MIT/Apache

78KB
2K SLoC

JSON Job Dispatch

A library which watches a directory using inotify for .json job files and dispatches them to registered handlers. Jobs are archived into accept/ and reject/ directories for auditing purposes. Additionally, companion files with a datestamp of when the job was handled and, for rejected jobs, a file containing the reason for the rejection is also created.

The design goal is to allow the daemon handling jobs to crash and be resiliant against crashes by using the filesystem as a simple object store for jobs which need handled and an archive of completed jobs. Atomic renames are used to relocate files, so the input directory must reside on the same filesystem as the archival directories.


lib.rs:

A small library to dispatch job files to relevant handlers.

This library implements the core logic of a Director which dispatches jobs described in JSON files to a relevant Handler and then archives the job based on whether it was accepted or rejected.

Job files

Job files are files ending in a .json extension in JSON format. Two keys are required:

  • kind: this string value is used to determine which handler will be used to handle the job.
  • data: this value is passed to the handler.

Other keys may be used (e.g., a timestamp to indicate when the job was created).

Job files are treated as read-only by the director.

Dependencies

~8–19MB
~264K SLoC