ADF Documentation/Example using a Scheduled Trigger?
As always, thanks for this library.
This an azure.mgmt.datafactory question. This is not necessarily an issue, maybe something that is not clear in the documentation.
Not sure what I'm doing wrong here and unfortunately the documentation is not enough to guide me through the process, or maybe I'm missing something. The below code is how I build all the elements required to create and start a scheduled trigger.
My question is, do you have a simple example of a scheduled trigger creation using the Python SDK?
params_for_pipeline = {}
adf_client = DataFactoryManagementClient(credentials, subscription_id)
pl_resource_object = PipelineResource(activities=[act2,act3,act4],
parameters=params_for_pipeline)
pl_resource = adf_client.pipelines.create_or_update(resource_group_name=rg_name,
factory_name=df_name,
pipeline_name=pipeline_name,
pipeline=pl_resource_object)
# Schedule Runs
pl_reference = PipelineReference(reference_name=pipeline_name)
trigger_pl_reference = TriggerPipelineReference(pl_reference, parameters=params_for_pipeline)
pl_scheduled = [trigger_pl_reference]
str_start_date = '2017-10-31T18:23:00'
str_end_date = '2099-12-31T05:00:00'
start_time = datetime.strptime(str_start_date, "%Y-%m-%dT%H:%M:%S").isoformat()
end_time = datetime.strptime(str_start_date, "%Y-%m-%dT%H:%M:%S").isoformat()
recurrence = ScheduleTriggerRecurrence(frequency='Minute', interval=4,
start_time=start_time,
end_time=end_time,
time_zone='UTC')
schedule_trigger = ScheduleTrigger(pipelines=pl_scheduled, recurrence=recurrence)
adf_client.triggers.create_or_update(resource_group_name=rg_name,
factory_name=df_name,
trigger_name='test',
properties=schedule_trigger)
trigger_start = adf_client.triggers.start(resource_group_name=rg_name, factory_name=df_name, trigger_name='test')
Error message: Caused by ResponseError('too many 500 error responses',)
given the details of the error message is very hard to tell what's going on, however I'm able to run the same pipeline manually using the create_run()
Note: I'm not putting details on linked services and data sets, those are working in the manual run so I'm assuming the problem is in the scheduled trigger implementation.
I'm trying to follow this [documentation] (https://docs.microsoft.com/en-us/azure/data-factory/concepts-pipeline-execution-triggers#scheduler-trigger)
Never mind, I figured this one out, however the errors messages weren't helping :) , for documentation purposes only, the problem is the way I formatted the dates in the recurrence (ScheduleTriggerRecurrence object)
python isoformat() does not include the time zone offset (-08:00, -04:00, etc.)
I had to add the UTC offset and voila!
for example:
str_start_date = '2017-10-31T17:17:00-04:00'
str_end_date = '2099-12-31T05:30:00-04:00'
This post also helped me to get there:
https://stackoverflow.com/questions/19654578/python-utc-datetime-objects-iso-format-doesnt-include-z-zulu-or-zero-offset
I'm still curious to see how to use the time_zone argument as I was originally using 'UTC', for now I removed it and hard-coded the UTC offset.
@saulcruz, thank you for reporting we will open internal items to improve our error messaging. @sharonlo101 will follow up with documentation.
@saulcruz By default, Python does not set the tzinfo (too dangerous and not obvious). But if you do it yourself, isoformat will do it:
In [8]: datetime.datetime(2017,10,10,12,45,16,tzinfo=datetime.timezone.utc).isoformat()
Out[8]: '2017-10-10T12:45:16+00:00'
In [10]: datetime.datetime(2017,10,10,12,45,16).isoformat()
Out[10]: '2017-10-10T12:45:16'
Note that the SDK installs python-dateutil, which can help as well:
In [11]: from dateutil.tz import tzlocal
In [13]: datetime.datetime(2017,10,10,12,45,16,tzinfo=tzlocal()).isoformat() # Seattle
Out[13]: '2017-10-10T12:45:16-07:00'
Note that the last one will use the tz of the system. It's nice for a desktop machine, usually more dangerous for a VM or a server.
More deeper: https://dateutil.readthedocs.io/en/stable/examples.html#tzutc-examples