trading_agent.scheduling.cron_job_store
¶
Keeps one desk's scheduled jobs and the record of their runs.
desks/
jobs.json is JSON rather than the plan's TOML, because the desk's tools write it and Python's standard library reads TOML but cannot write it. The user can still edit it by hand.
Typical usage example:
store = CronJobStore(Path('workspace/desks/main/cron')) store.add(job) store.record_run(job, moment, 'started', '')
CronJobStore
¶
One desk's cron folder.
Describes the folder without touching the disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory
|
Path
|
The desk's cron folder. |
required |
Source code in src/trading_agent/scheduling/cron_job_store.py
jobs
¶
Reads the jobs; a job that is not valid is logged and left out.
Returns:
| Type | Description |
|---|---|
list[CronJob]
|
The jobs, in file order. |
Source code in src/trading_agent/scheduling/cron_job_store.py
delete
¶
Removes a job.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_id
|
str
|
The job's identifier. |
required |
Returns:
| Type | Description |
|---|---|
CronJob | None
|
The removed job, or None when there was none with that id. |
Source code in src/trading_agent/scheduling/cron_job_store.py
last_run
¶
When a job last ran.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_id
|
str
|
The job's identifier. |
required |
Returns:
| Type | Description |
|---|---|
datetime | None
|
The moment, or None when it never ran. |
Source code in src/trading_agent/scheduling/cron_job_store.py
record_run
¶
Records that a job ran, or was skipped, at a moment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job
|
CronJob
|
The job. |
required |
moment
|
datetime
|
The scheduled moment it ran for. |
required |
outcome
|
str
|
Such as "started", "skipped" or "failed". |
required |
detail
|
str
|
More about it, or an empty string. |
required |
Source code in src/trading_agent/scheduling/cron_job_store.py
recent_runs
¶
The latest runs and skips, newest first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
limit
|
int
|
The most runs. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
Each run's time, job id, name, outcome and detail. |
Source code in src/trading_agent/scheduling/cron_job_store.py
forget_run
¶
Drops a job's last-run time, after the job is deleted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_id
|
str
|
The job's identifier. |
required |