Skip to content

trading_agent.tools.cron_delete_tool

The cron_delete tool: removes one of the desk's scheduled jobs.

Typical usage example:

tool = CronDeleteTool(store)

CronDeleteArguments

Bases: BaseModel

The arguments of cron_delete.

Attributes:

Name Type Description
job_id str

The job's id, from cron_list.

CronDeleteTool

CronDeleteTool(store)

Bases: Tool

Deletes a job.

Creates the tool.

Parameters:

Name Type Description Default
store CronJobStore

The desk's jobs.

required
Source code in src/trading_agent/tools/cron_delete_tool.py
def __init__(self, store: cron_job_store_module.CronJobStore):
    """Creates the tool.

    Args:
        store (cron_job_store_module.CronJobStore): The desk's jobs.
    """
    self._store = store

run async

run(arguments)

Deletes the job.

Parameters:

Name Type Description Default
arguments CronDeleteArguments

The job's id.

required

Returns:

Type Description
ToolResult

A confirmation, or why nothing was deleted.

Source code in src/trading_agent/tools/cron_delete_tool.py
async def run(self, arguments: CronDeleteArguments) -> tool.ToolResult:
    """Deletes the job.

    Args:
        arguments (CronDeleteArguments): The job's id.

    Returns:
        tool.ToolResult: A confirmation, or why nothing was deleted.
    """
    built_in = arguments.job_id in ('heartbeat', 'rollover')
    if built_in or arguments.job_id.startswith('check-'):
        return tool.ToolResult.error(
            f'{arguments.job_id} is built in; the user sets it in trading_agent.toml.'
        )
    removed = self._store.delete(arguments.job_id)
    if removed is None:
        return tool.ToolResult.error(
            f'No job with id {arguments.job_id}; see cron_list.'
        )
    self._store.forget_run(arguments.job_id)
    return tool.ToolResult.success(f'Deleted {removed.describe()}.')