Scheduling

Rather than driving each sweep by hand, MccsStationCalibrator can run sweeps on a cron schedule. A scheduler thread lives in the component manager for the lifetime of the device and, on each tick, invokes the same code path as GenerateCalibrationSolution, described in Generating a Solution.

Scheduling is controlled entirely through attributes, there are no scheduler commands.

calibrationSchedule

A memorized JSON array of schedule entries. Every entry must have a cron field holding a standard 5-field cron expression, interpreted in UTC. Alongside it, an entry may carry any of the GenerateCalibrationSolution parameters, which are the parameters that run will be performed with:

[
  {"cron": "0 8 * * *"},
  {"cron": "0 13 * * *", "skymodel": "sun"},
  {"cron": "0 22 * * *", "skymodel": "gsm", "first_channel": 128}
]

Any parameter an entry does not specify takes its default, so an entry with nothing but a cron field runs a full default sweep. See Generating a Solution for the parameter set.

Writing an empty string clears the schedule.

Entries are validated on write: a missing or invalid cron expression, or a parameter that does not conform to the GenerateCalibrationSolution schema, is rejected and the existing schedule is left unchanged.

An entry cannot set calibration_id. Every run of the entry would reuse that ID, and the calibration store rejects an ID that is already in use, so every run after the first would fail. Each scheduled run gets a generated ID instead.

Because the attribute is memorized, a schedule survives a device restart.

scheduleState

A read-only attribute of type CalibrationScheduleState. It is derived from the other two attributes rather than set.

EMPTY

No schedule is set.

PAUSED

A schedule is set, but a pause window is open, so no runs will fire.

RUNNING

Runs fire at their scheduled times.

To suspend the scheduler, set a pause window. To resume it, clear that window.

pauseWindow

The period over which the scheduler holds off firing runs. It is a memorized, read-write JSON object with an optional start and an optional end, both ISO 8601 timestamps, or an empty string when no pause is set. The scheduler moves to PAUSED when the window opens and back to RUNNING when it closes, with no operator action needed at either boundary:

# Hold off scheduled sweeps over tomorrow morning's maintenance.
start = datetime(2025, 6, 11, 8, tzinfo=timezone.utc)
calibrator.pauseWindow = json.dumps(
    {
        "start": start.isoformat(),
        "end": (start + timedelta(hours=2)).isoformat(),
    }
)

Write both ends at once, as a single value. Either may be left out:

start left out

The pause takes effect immediately, and reads back naming the time it began. If the device restarts while the pause is still open, the pause begins again from the time the device came back.

end left out

The pause has no deadline and stays in force until it is cancelled.

Writing an empty string cancels the pause. Writing a new window replaces the one before it, whether that one had already finished, was open, or had yet to start.

A timestamp with no time zone is read as UTC, and the window always reads back in UTC. A value that is not a JSON object of valid timestamps is rejected, and so is a window whose end does not fall after its start. In either case the window already set is left unchanged. A window whose end has already passed is accepted, and holds off nothing.

A pause window survives a device restart. A pause that had already ended while the device was down does not come back, and calibration resumes as soon as the device does.

Runs missed over a pause are not caught up later. They are skipped. When a window reaches its end, the next calibration is the next one the schedule asks for.

Cancelling a pause resumes calibration at once. A run scheduled in the last minute may still go ahead, but nothing older than that does, so cancelling a long pause never sets off a backlog of missed calibrations.

Late runs are dropped

A cron expression names a minute, so a tick asks for a run in that minute and no later. A run that cannot start before the minute is out is dropped, and the entry waits for its next tick. That covers a tick reached while another run was in progress and one that fell inside a pause window.

scheduledSweeps

A read-only JSON array of every run due within the next 24 hours, sorted by time. Each item carries a scheduled_time (ISO 8601 UTC) plus that entry’s parameters, which makes it the quickest way to confirm a cron expression means what you intended:

[
  {"scheduled_time": "2025-06-10T13:00:00+00:00", "skymodel": "sun"},
  {"scheduled_time": "2025-06-10T22:00:00+00:00", "skymodel": "gsm"}
]

It reports what the cron expressions say, not what the scheduler will actually do. Runs are still listed while the state is PAUSED. That includes runs inside a pause window, which are skipped rather than deferred.

Interaction with manual runs

While scheduleState is RUNNING, manual GenerateCalibrationSolution calls are rejected, since the scheduler owns the station. Pause or clear the schedule before calibrating by hand.

The isLoopRunning attribute is True while a scheduled run is executing, and jobsInQueue reports the correlator files that run still has to process.