Skip to main content

JobBatch: Run batches of commands

Background

JobBatch is a simple tool for queuing up batches of commands and running N of them at a time.

The initial use case was scheduling software updates on a large number of remote devices, without getting all the support queries back in the same day! So we wanted to update 100 devices each night. But you might want to send 10 emails per minute, transcode 5 videos per hour, or whatever. You can set up a cron job or similar to run jobbatch, and it will split the tasks into these chunks for you and run them.

Here's how it works.

The flow is managed using the filesystem. You have a set of subdirectories:

  • queue
  • batch
  • successes
  • failures
  • output

You can put all of the jobs you want to run as individual files into the 'queue' directory. If you have them as lines in a single file, you can use jobbatch split to turn it into one file per job. Often, each job file is a shell script, but it doesn't have to be (see below).

Each time you want to run the next chunk of jobs, you do jobbatch select to take a selection of the files in the queue directory and move them into the batch directory. You can then take a look to check that things look right, and if you don't like what you see, you can just move all the files back into the queue directory. If the queue directory is empty, this command will do nothing.

Then you run jobbatch run, which will execute those the jobs in the batch directory one at a time. After execution, each file is moved to either successes or failures depending on its exit code. If the batch directory is empty, this command will do nothing.

Any standard output or error output from a job will be put in a file with a '.stdout' or '.stderr' extension within the output directory.

So, to summarise, each file eventually goes from:

queue -> batch -> successes or failures (possibly plus output)

Not just for scripts

Typically, each job file will be a shell script or program to be executed.

If the file has the 'executable' flag bit set, it will be executed directly. If it doesn't, it will be passed as the argument to a processor such as /bin/bash, but you can change this with a command-line option.

This means, therefore, that the jobs do not have to be scripts. Suppose you had a script for emailing thumbnails of your photographs to your friends, you could put the photographs into the 'queue' directory and specify your script as the processor, and then send them eight thumbnails per day.

For some tasks, the job files may not even need to have any contents, because the filename itself is the parameter. You might just created empty files named after the serial numbers of the devices to be updated. Note that jobbatch run will normally send the full pathname of the file to the processor, but there is an option just to send the base name within the subdirectory, if you wish to use it this way.

Author

Quentin Stafford-Fraser June 2022

Metadata

Release files for jobbatch 1.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jobbatch 1.0.5
File Size Uploaded
jobbatch-1.0.5.tar.gz 11.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jobbatch 1.0.5
File Interpreter ABI Platform
jobbatch-1.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 23.4 kB

Release files / jobbatch-1.0.5.tar.gz

Download URL jobbatch-1.0.5.tar.gz
Size 11.4 kB
Tags Source
SHA-256 checksum
How to use checksums
897c969c0a6beb70469bc345aef664eae276ba29732f398a865184fbcbb0fb6f
BLAKE2b-256 checksum
How to use checksums
295642938d13aae1fa06b389fdca711c53816df9fb5132ae1dbd87d129fb500a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.9.13 Darwin/21.5.0

Release files / jobbatch-1.0.5-py3-none-any.whl

Download URL jobbatch-1.0.5-py3-none-any.whl
Size 12.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8d4ba9539a7c55a29894cfe01ef0b853e224f1d01769fb71e20afedf89575ac1
BLAKE2b-256 checksum
How to use checksums
e046f9f9a9383a3489f4c47585322bacaf1af9cf5869fb2cb096aa5e0a2c14e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.9.13 Darwin/21.5.0

Release history Release notifications | RSS feed

This release

1.0.5 This release

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page