|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# Schedule an endpoint" |
| 8 | + ] |
| 9 | + }, |
| 10 | + { |
| 11 | + "cell_type": "code", |
| 12 | + "execution_count": 5, |
| 13 | + "metadata": {}, |
| 14 | + "outputs": [], |
| 15 | + "source": [ |
| 16 | + "# Get the endpoint name from the AzureML studio in the Pipelines -> Pipeline endpoints\n", |
| 17 | + "pipeline_endpoint_name = \"forecast-with-r\"" |
| 18 | + ] |
| 19 | + }, |
| 20 | + { |
| 21 | + "cell_type": "code", |
| 22 | + "execution_count": 3, |
| 23 | + "metadata": {}, |
| 24 | + "outputs": [ |
| 25 | + { |
| 26 | + "name": "stdout", |
| 27 | + "output_type": "stream", |
| 28 | + "text": [ |
| 29 | + "Azure ML SDK Version: 1.35.0\n" |
| 30 | + ] |
| 31 | + } |
| 32 | + ], |
| 33 | + "source": [ |
| 34 | + "import azureml\n", |
| 35 | + "\n", |
| 36 | + "from azureml.core import Workspace\n", |
| 37 | + "\n", |
| 38 | + "print(\"Azure ML SDK Version: \", azureml.core.VERSION)\n", |
| 39 | + "# Connect to Workspace\n", |
| 40 | + "ws = Workspace.from_config()" |
| 41 | + ] |
| 42 | + }, |
| 43 | + { |
| 44 | + "cell_type": "code", |
| 45 | + "execution_count": 6, |
| 46 | + "metadata": {}, |
| 47 | + "outputs": [], |
| 48 | + "source": [ |
| 49 | + "from azureml.pipeline.core import PipelineEndpoint, Schedule \n", |
| 50 | + "\n", |
| 51 | + "pipeline_endpoint = PipelineEndpoint.get(workspace=ws, name=pipeline_endpoint_name)\n" |
| 52 | + ] |
| 53 | + }, |
| 54 | + { |
| 55 | + "cell_type": "code", |
| 56 | + "execution_count": 7, |
| 57 | + "metadata": {}, |
| 58 | + "outputs": [ |
| 59 | + { |
| 60 | + "name": "stdout", |
| 61 | + "output_type": "stream", |
| 62 | + "text": [ |
| 63 | + "Provisioning status: Completed\n", |
| 64 | + "Created schedule with id: d3fa9aa6-cf31-4d80-9152-becf4360ff20\n" |
| 65 | + ] |
| 66 | + } |
| 67 | + ], |
| 68 | + "source": [ |
| 69 | + "from azureml.pipeline.core.schedule import ScheduleRecurrence, Schedule, TimeZone\n", |
| 70 | + "from datetime import datetime\n", |
| 71 | + "\n", |
| 72 | + "recurrence = ScheduleRecurrence(frequency=\"Day\", \n", |
| 73 | + " interval=1, \n", |
| 74 | + " hours=[22], \n", |
| 75 | + " minutes=[30],\n", |
| 76 | + " time_zone=TimeZone.EEuropeStandardTime,\n", |
| 77 | + " start_time = datetime.now() # This will prevent starting the pipeline immediately after scheduling it\n", |
| 78 | + " ) # Runs every other day at 10:30pm Eastern European Standard Time (aka Greece)\n", |
| 79 | + "\n", |
| 80 | + "schedule = Schedule.create_for_pipeline_endpoint(workspace=ws, name=f\"{pipeline_endpoint_name}-schedule\",\n", |
| 81 | + " pipeline_endpoint_id=pipeline_endpoint.id, \n", |
| 82 | + " pipeline_parameters = { # These are the parameters that will be passed to the pipeline\n", |
| 83 | + " \"start_date\": \"2020-01-01\",\n", |
| 84 | + " \"key_vault\": \"my-key-vault\",\n", |
| 85 | + " },\n", |
| 86 | + " experiment_name=f\"{pipeline_endpoint_name}-schedule-run\",\n", |
| 87 | + " recurrence=recurrence,\n", |
| 88 | + " wait_for_provisioning=True,\n", |
| 89 | + " description=\"Scheduled pipeline run\")\n", |
| 90 | + "\n", |
| 91 | + "# You may want to make sure that the schedule is provisioned properly\n", |
| 92 | + "# before making any further changes to the schedule\n", |
| 93 | + "\n", |
| 94 | + "print(\"Created schedule with id: {}\".format(schedule.id))" |
| 95 | + ] |
| 96 | + }, |
| 97 | + { |
| 98 | + "cell_type": "code", |
| 99 | + "execution_count": 13, |
| 100 | + "metadata": {}, |
| 101 | + "outputs": [ |
| 102 | + { |
| 103 | + "name": "stdout", |
| 104 | + "output_type": "stream", |
| 105 | + "text": [ |
| 106 | + "Your workspace has the following schedules set up:\n", |
| 107 | + "Schedule Id: 79e8a585-4e9d-4060-849e-342553f108fd (Published pipeline: 3855df31-cff6-4341-9707-6841abc862fb, Published endpoint: None)\n" |
| 108 | + ] |
| 109 | + } |
| 110 | + ], |
| 111 | + "source": [ |
| 112 | + "from azureml.pipeline.core.schedule import Schedule\n", |
| 113 | + "# Use active_only=False to get all schedules including disabled schedules\n", |
| 114 | + "schedules = Schedule.list(ws, active_only=True) \n", |
| 115 | + "print(\"Your workspace has the following schedules set up:\")\n", |
| 116 | + "for schedule in schedules:\n", |
| 117 | + " print(\"Schedule Id: {} (Published pipeline: {}, Published endpoint: {})\".format(schedule.id, schedule.pipeline_id, schedule.pipeline_endpoint_id))\n", |
| 118 | + " if schedule.id == \"a specific schedule id you want to disable\":\n", |
| 119 | + " schedule.disable(wait_for_provisioning=True)" |
| 120 | + ] |
| 121 | + }, |
| 122 | + { |
| 123 | + "cell_type": "code", |
| 124 | + "execution_count": null, |
| 125 | + "metadata": {}, |
| 126 | + "outputs": [], |
| 127 | + "source": [] |
| 128 | + } |
| 129 | + ], |
| 130 | + "metadata": { |
| 131 | + "interpreter": { |
| 132 | + "hash": "aaf752ee7e264d07f2aa436f1fcdea415bc1d1a9b82629a37d86a1397f966a41" |
| 133 | + }, |
| 134 | + "kernelspec": { |
| 135 | + "display_name": "Python 3.6.9 ('azureml_py36_automl')", |
| 136 | + "language": "python", |
| 137 | + "name": "python3" |
| 138 | + }, |
| 139 | + "language_info": { |
| 140 | + "codemirror_mode": { |
| 141 | + "name": "ipython", |
| 142 | + "version": 3 |
| 143 | + }, |
| 144 | + "file_extension": ".py", |
| 145 | + "mimetype": "text/x-python", |
| 146 | + "name": "python", |
| 147 | + "nbconvert_exporter": "python", |
| 148 | + "pygments_lexer": "ipython3", |
| 149 | + "version": "3.6.9" |
| 150 | + }, |
| 151 | + "orig_nbformat": 4 |
| 152 | + }, |
| 153 | + "nbformat": 4, |
| 154 | + "nbformat_minor": 2 |
| 155 | +} |
0 commit comments