class crab.service.CrabMinutely

A thread which will call its run_minutely method for each minute which passes.

The problem which this class seeks to address is that other methods of pausing a program (eg. threading.Timer, time.sleep) can’t guarantee not to pause for longer than expected. Therefore in the context of cron jobs, it might be possible to miss a cron scheduling point.


Thread run function.

This calls _check_minute on regular intervals.


This is the method which will be called each minute. It should be overridden by subclasses.

Will be called with a datetime object for the relevant minute with the seconds and microseconds set to zero.

crab.service.minute_equal(a, b)

Determine whether one time is in the same minute as another.

crab.service.minute_before(a, b)

Determine whether one time is in a minute before another.


class crab.service.clean.CrabCleanService(config, store)

Service to clean the store by removing old events.


Performs cleaning if scheduled for the given minute.


exception crab.service.monitor.JobDeleted

Exception raised by _initialize_job if the job can not be found.

class crab.service.monitor.CrabMonitor(store, passive=False)

A class implementing the crab monitor thread.


Monitor thread main run function.

When the thread is started, this function will run. It begins by fetching a list of jobs and using them to populate its data structures. When this is complete, the Event status_ready is fired.

It then goes into a loop, and every few seconds it checks for new events, processing any which are found. The new_event Condition is fired if there were any new events.

We call _check_minute from CrabMinutely to check whether the minute has changed since the last time round the loop.


Every minute the job scheduling is checked.

At this stage we also check for new / deleted / updated jobs.


Fetches the status of all jobs as a dict.

For efficiency this returns a reference to our job status dict. Callers should not modify it. If a job ID is specified, the status entry for that job is returned, or a dummy entry if it is not in the status dict.

wait_for_event_since(startid, alarmid, finishid, timeout=120)

Function which waits for new events.

It does this by comparing the IDs with our maximum values seen so far. If no new events have already be seen, wait for the new_event Condition to fire.

A random time up to 20s is added to the timeout to stagger requests.


class crab.service.notify.CrabNotifyService(config, store, notify)

Service to send notifications as required.

Currently only a single daily schedule is implemented.


Issues notifications if any are scheduled for the given minute.