Skip to main content

TaskScheduler

class automation.TaskScheduler()#

Task Scheduling controller. Notice time-zone is ALWAYS UTC

Create a Task scheduler service

  • Parameters

    sync_frequency_minutes (float) – Sync task scheduler configuration every X minutes.

Allow to change scheduler in runtime by editing the Task configuration object :type force_create_task_name: Optional[str] :param force_create_task_name: Optional, force creation of Task Scheduler service, even if main Task.init already exists. :type force_create_task_project: Optional[str] :param force_create_task_project: Optional, force creation of Task Scheduler service, even if main Task.init already exists.


add_task#

add_task(schedule_task_id=None, schedule_function=None, queue=None, name=None, target_project=None, minute=None, hour=None, day=None, weekdays=None, month=None, year=None, limit_execution_time=None, single_instance=False, recurring=True, execute_immediately=False, reuse_task=False, task_parameters=None, task_overrides=None)

Create a cron job-like scheduling for a pre-existing Task. Notice, it is recommended to give the schedule entry a descriptive unique name, if not provided, a name is randomly generated.

When timespec parameters are specified exclusively, they define the time between task launches (see year and weekdays exceptions). When multiple timespec parameter are specified, the parameter representing the longest duration defines the time between task launches, and the shorter timespec parameters define specific times.

Examples: Launch every 15 minutes

add_task(schedule_task_id=’1235’, queue=’default’, minute=15)

Launch every 1 hour

add_task(schedule_task_id=’1235’, queue=’default’, hour=1)

Launch every 1 hour at hour:30 minutes (i.e. 1:30, 2:30 etc.)

add_task(schedule_task_id=’1235’, queue=’default’, hour=1, minute=30)

Launch every day at 22:30 (10:30 pm)

add_task(schedule_task_id=’1235’, queue=’default’, minute=30, hour=22, day=1)

Launch every other day at 7:30 (7:30 am)

add_task(schedule_task_id=’1235’, queue=’default’, minute=30, hour=7, day=2)

Launch every Saturday at 8:30am (notice day=0)

add_task(schedule_task_id=’1235’, queue=’default’, minute=30, hour=8, day=0, weekdays=[‘saturday’])

Launch every 2 hours on the weekends Saturday/Sunday (notice day is not passed)

add_task(schedule_task_id=’1235’, queue=’default’, hour=2, weekdays=[‘saturday’, ‘sunday’])

Launch once a month at the 5th of each month

add_task(schedule_task_id=’1235’, queue=’default’, month=1, day=5)

Launch once a year on March 4th

add_task(schedule_task_id=’1235’, queue=’default’, year=1, month=3, day=4)
  • Parameters

    • schedule_task_id (Union[str, Task, None]) – ID of Task to be cloned and scheduled for execution

    • schedule_function (Optional[Callable]) – Optional, instead of providing Task ID to be scheduled, provide a function to be called. Notice the function is called from the scheduler context (i.e. running on the same machine as the scheduler)

    • queue (Optional[str]) – Name or ID of queue to put the Task into (i.e. schedule)

    • name (Optional[str]) – Name or description for the cron Task (should be unique if provided, otherwise randomly generated)

    • target_project (Optional[str]) – Specify target project to put the cloned scheduled Task in.

    • minute (Optional[int]) – Time (in minutes) between task launches. If specified together with hour, day, month, and / or year, it defines the minute of the hour

    • hour (Optional[int]) – Time (in hours) between task launches. If specified together with day, month, and / or year, it defines the hour of day.

    • day (Optional[int]) – Time (in days) between task executions. If specified together with month and / or year, it defines the day of month

    • weekdays (Optional[List[str]]) – Days of week to launch task (accepted inputs: ‘monday’, ‘tuesday’, ‘wednesday’, ‘thursday’, ‘friday’, ‘saturday’, ‘sunday’)

    • month (Optional[int]) – Time (in months) between task launches. If specified with year, it defines a specific month

    • year (Optional[int]) – Specific year if value >= current year. Time (in years) between task launches if value <= 100

    • limit_execution_time (Optional[float]) – Limit the execution time (in hours) of the specific job.

    • single_instance (bool) – If True, do not launch the Task job if the previous instance is still running

    • recurring (bool ) –

    • execute_immediately (bool ) –

    • reuse_task (bool ) –

    • task_parameters (Optional [ dict ] ) –

    • task_overrides (Optional [ dict ] ) –

  • Return type

    bool

(skip until the next scheduled time period). Default False. :type recurring: bool :param recurring: If False only launch the Task once (default: True, repeat) :type execute_immediately: bool :param execute_immediately: If True, schedule the Task to be executed immediately then recurring based on the timing schedule arguments. Default False. :type reuse_task: bool :param reuse_task: If True, re-enqueue the same Task (i.e. do not clone it) every time, default False. :type task_parameters: Optional[dict] :param task_parameters: Configuration parameters to the executed Task. for example: {‘Args/batch’: ‘12’} Notice: not available when reuse_task=True :type task_overrides: Optional[dict] :param task_overrides: Change task definition. for example {‘script.version_num’: None, ‘script.branch’: ‘main’} Notice: not available when reuse_task=True

  • Return type

    bool

  • Returns

    True if job is successfully added to the scheduling list

  • Parameters

    • schedule_task_id (Optional [ Union [ str , clearml.task.Task ] ] ) –

    • schedule_function (Optional [ Callable ] ) –

    • queue (Optional [ str ] ) –

    • name (Optional [ str ] ) –

    • target_project (Optional [ str ] ) –

    • minute (Optional [ int ] ) –

    • hour (Optional [ int ] ) –

    • day (Optional [ int ] ) –

    • weekdays (Optional [ List [ str ] ] ) –

    • month (Optional [ int ] ) –

    • year (Optional [ int ] ) –

    • limit_execution_time (Optional [ float ] ) –

    • single_instance (bool ) –

    • recurring (bool ) –

    • execute_immediately (bool ) –

    • reuse_task (bool ) –

    • task_parameters (Optional [ dict ] ) –

    • task_overrides (Optional [ dict ] ) –


get_scheduled_tasks#

get_scheduled_tasks()

Return the current set of scheduled jobs

  • Return type

    List[ScheduleJob]

  • Returns

    List of ScheduleJob instances


remove_task#

remove_task(task_id)

Remove a Task ID from the scheduled task list.

  • Parameters

    task_id (Union[str, Task, Callable]) – Task or Task ID to be removed

  • Return type

    bool

  • Returns

    return True of the Task ID was found in the scheduled jobs list and was removed.


start#

start()

Start the Task TaskScheduler loop (notice this function does not return)

  • Return type

    None


start_remotely#

start_remotely(queue='services')

Start the Task TaskScheduler loop (notice this function does not return)

  • Parameters

    queue (str) – Remote queue to run the scheduler on, default ‘services’ queue.

  • Return type

    None