Skip to content

AzureMLScheduleClient

kedro_azureml_pipeline.scheduler.AzureMLScheduleClient

Client for creating and updating Azure ML schedules.

See Also

AzureMLPipelinesClient : Immediate job submission. build_job_schedule : Builds schedules for this client. ScheduleConfig : Schedule trigger configuration.

Source Code

Show/Hide source
class AzureMLScheduleClient:
    """Client for creating and updating Azure ML schedules.

    See Also
    --------
    [AzureMLPipelinesClient][kedro_azureml_pipeline.client.AzureMLPipelinesClient] : Immediate job submission.
    [build_job_schedule][kedro_azureml_pipeline.scheduler.build_job_schedule] : Builds schedules for this client.
    [ScheduleConfig][kedro_azureml_pipeline.config.ScheduleConfig] : Schedule trigger configuration.
    """

    def create_or_update_schedule(
        self,
        schedule: JobSchedule,
        config: WorkspaceConfig,
    ) -> JobSchedule:
        """Create or update a schedule in the Azure ML workspace.

        Parameters
        ----------
        schedule : JobSchedule
            The schedule to create or update.
        config : WorkspaceConfig
            Workspace configuration for the ``MLClient``.

        Returns
        -------
        JobSchedule
            The schedule as returned by the Azure ML service.
        """
        with _get_azureml_client(config) as ml_client:
            result = ml_client.schedules.begin_create_or_update(
                schedule=schedule,
            ).result()
            logger.info(f"Schedule '{result.name}' created/updated successfully")
            return result

    def delete_schedule(
        self,
        name: str,
        config: WorkspaceConfig,
    ) -> None:
        """Disable and delete a schedule from the Azure ML workspace.

        Azure ML requires a schedule to be disabled before it can be
        deleted.  If the schedule does not exist, a warning is logged
        and the call is treated as a no-op.

        Parameters
        ----------
        name : str
            Schedule name to delete.
        config : WorkspaceConfig
            Workspace configuration for the ``MLClient``.
        """
        from azure.core.exceptions import ResourceNotFoundError

        with _get_azureml_client(config) as ml_client:
            try:
                ml_client.schedules.begin_disable(name=name).result()
                ml_client.schedules.begin_delete(name=name).result()
                logger.info(f"Schedule '{name}' deleted successfully")
            except ResourceNotFoundError:
                logger.warning(f"Schedule '{name}' not found, skipping delete")

Methods

create_or_update_schedule(schedule, config)

Create or update a schedule in the Azure ML workspace.

Parameters
Name Type Description Default
schedule JobSchedule

The schedule to create or update.

required
config WorkspaceConfig

Workspace configuration for the MLClient.

required
Returns
Type Description
JobSchedule

The schedule as returned by the Azure ML service.

Source Code
Show/Hide source
def create_or_update_schedule(
    self,
    schedule: JobSchedule,
    config: WorkspaceConfig,
) -> JobSchedule:
    """Create or update a schedule in the Azure ML workspace.

    Parameters
    ----------
    schedule : JobSchedule
        The schedule to create or update.
    config : WorkspaceConfig
        Workspace configuration for the ``MLClient``.

    Returns
    -------
    JobSchedule
        The schedule as returned by the Azure ML service.
    """
    with _get_azureml_client(config) as ml_client:
        result = ml_client.schedules.begin_create_or_update(
            schedule=schedule,
        ).result()
        logger.info(f"Schedule '{result.name}' created/updated successfully")
        return result

delete_schedule(name, config)

Disable and delete a schedule from the Azure ML workspace.

Azure ML requires a schedule to be disabled before it can be deleted. If the schedule does not exist, a warning is logged and the call is treated as a no-op.

Parameters
Name Type Description Default
name str

Schedule name to delete.

required
config WorkspaceConfig

Workspace configuration for the MLClient.

required
Source Code
Show/Hide source
def delete_schedule(
    self,
    name: str,
    config: WorkspaceConfig,
) -> None:
    """Disable and delete a schedule from the Azure ML workspace.

    Azure ML requires a schedule to be disabled before it can be
    deleted.  If the schedule does not exist, a warning is logged
    and the call is treated as a no-op.

    Parameters
    ----------
    name : str
        Schedule name to delete.
    config : WorkspaceConfig
        Workspace configuration for the ``MLClient``.
    """
    from azure.core.exceptions import ResourceNotFoundError

    with _get_azureml_client(config) as ml_client:
        try:
            ml_client.schedules.begin_disable(name=name).result()
            ml_client.schedules.begin_delete(name=name).result()
            logger.info(f"Schedule '{name}' deleted successfully")
        except ResourceNotFoundError:
            logger.warning(f"Schedule '{name}' not found, skipping delete")