0
# Job Schedule Operations
1
2
Job schedule management capabilities for creating and managing recurring batch jobs with time-based or interval-based scheduling. Job schedules automatically create jobs based on predefined schedules and job specifications.
3
4
## Capabilities
5
6
### Job Schedule Lifecycle Management
7
8
Create, retrieve, update, and delete job schedules with comprehensive configuration options.
9
10
```python { .api }
11
def add(cloud_job_schedule, job_schedule_add_options=None, custom_headers=None, raw=False, **operation_config):
12
"""
13
Add a job schedule to the specified account.
14
15
Args:
16
cloud_job_schedule: The job schedule to add (JobScheduleAddParameter)
17
job_schedule_add_options: Additional options for the operation
18
custom_headers: Custom headers to include in request
19
raw: Return raw response if True
20
21
Returns:
22
None
23
"""
24
25
def list(job_schedule_list_options=None, custom_headers=None, raw=False, **operation_config):
26
"""
27
List all job schedules in the account.
28
29
Args:
30
job_schedule_list_options: Additional options for listing
31
32
Returns:
33
ItemPaged[CloudJobSchedule]: Paginated list of job schedules
34
"""
35
36
def get(job_schedule_id, job_schedule_get_options=None, custom_headers=None, raw=False, **operation_config):
37
"""
38
Get information about the specified job schedule.
39
40
Args:
41
job_schedule_id: ID of the job schedule to retrieve
42
job_schedule_get_options: Additional options for the operation
43
44
Returns:
45
CloudJobSchedule: Job schedule information
46
"""
47
48
def delete(job_schedule_id, job_schedule_delete_options=None, custom_headers=None, raw=False, **operation_config):
49
"""
50
Delete the specified job schedule.
51
52
Args:
53
job_schedule_id: ID of the job schedule to delete
54
job_schedule_delete_options: Additional options for deletion
55
56
Returns:
57
None
58
"""
59
60
def exists(job_schedule_id, job_schedule_exists_options=None, custom_headers=None, raw=False, **operation_config):
61
"""
62
Check if a job schedule exists.
63
64
Args:
65
job_schedule_id: ID of the job schedule to check
66
67
Returns:
68
bool: True if job schedule exists, False otherwise
69
"""
70
```
71
72
### Job Schedule Configuration Updates
73
74
Update job schedule properties and configuration after creation.
75
76
```python { .api }
77
def patch(job_schedule_id, job_schedule_patch_parameter, job_schedule_patch_options=None, custom_headers=None, raw=False, **operation_config):
78
"""
79
Update properties of the specified job schedule.
80
81
Args:
82
job_schedule_id: ID of the job schedule to update
83
job_schedule_patch_parameter: Properties to update
84
job_schedule_patch_options: Additional options
85
86
Returns:
87
None
88
"""
89
90
def update(job_schedule_id, job_schedule_update_parameter, job_schedule_update_options=None, custom_headers=None, raw=False, **operation_config):
91
"""
92
Update the properties of the specified job schedule.
93
94
Args:
95
job_schedule_id: ID of the job schedule to update
96
job_schedule_update_parameter: Properties to update
97
98
Returns:
99
None
100
"""
101
```
102
103
### Job Schedule State Control
104
105
Control job schedule execution state including enabling, disabling, and terminating schedules.
106
107
```python { .api }
108
def enable(job_schedule_id, job_schedule_enable_options=None, custom_headers=None, raw=False, **operation_config):
109
"""
110
Enable the specified job schedule.
111
112
Args:
113
job_schedule_id: ID of the job schedule to enable
114
job_schedule_enable_options: Additional options
115
116
Returns:
117
None
118
"""
119
120
def disable(job_schedule_id, job_schedule_disable_options=None, custom_headers=None, raw=False, **operation_config):
121
"""
122
Disable the specified job schedule.
123
124
Args:
125
job_schedule_id: ID of the job schedule to disable
126
job_schedule_disable_options: Additional options
127
128
Returns:
129
None
130
"""
131
132
def terminate(job_schedule_id, job_schedule_terminate_options=None, custom_headers=None, raw=False, **operation_config):
133
"""
134
Terminate the specified job schedule.
135
136
Args:
137
job_schedule_id: ID of the job schedule to terminate
138
job_schedule_terminate_options: Additional options
139
140
Returns:
141
None
142
"""
143
```
144
145
## Usage Examples
146
147
### Creating a Recurring Job Schedule
148
149
```python
150
from azure.batch.models import (
151
JobScheduleAddParameter, Schedule, JobSpecification,
152
PoolInformation, RecurrencePattern
153
)
154
import datetime
155
156
# Create a job schedule that runs daily at 2 AM
157
daily_schedule = Schedule(
158
do_not_run_until=datetime.datetime.utcnow() + datetime.timedelta(hours=1),
159
do_not_run_after=datetime.datetime.utcnow() + datetime.timedelta(days=365),
160
start_window=datetime.timedelta(hours=1), # Job can start within 1 hour
161
recurrence_interval=datetime.timedelta(days=1) # Run every day
162
)
163
164
# Define the job specification for scheduled jobs
165
job_spec = JobSpecification(
166
pool_info=PoolInformation(pool_id="processing-pool"),
167
display_name="Daily Processing Job",
168
priority=100,
169
constraints=JobConstraints(
170
max_wall_clock_time=datetime.timedelta(hours=8)
171
)
172
)
173
174
# Create the job schedule
175
job_schedule = JobScheduleAddParameter(
176
id="daily-processing-schedule",
177
display_name="Daily Data Processing Schedule",
178
schedule=daily_schedule,
179
job_specification=job_spec
180
)
181
182
client.job_schedule.add(job_schedule)
183
```
184
185
### Creating a Weekly Job Schedule
186
187
```python
188
from azure.batch.models import Schedule
189
import datetime
190
191
# Create a job schedule that runs every Monday at 3 AM
192
weekly_schedule = Schedule(
193
do_not_run_until=datetime.datetime.utcnow(),
194
start_window=datetime.timedelta(minutes=30),
195
recurrence_interval=datetime.timedelta(weeks=1)
196
)
197
198
job_spec = JobSpecification(
199
pool_info=PoolInformation(pool_id="weekly-reports-pool"),
200
display_name="Weekly Report Generation"
201
)
202
203
weekly_job_schedule = JobScheduleAddParameter(
204
id="weekly-reports-schedule",
205
schedule=weekly_schedule,
206
job_specification=job_spec
207
)
208
209
client.job_schedule.add(weekly_job_schedule)
210
```
211
212
### Managing Job Schedule State
213
214
```python
215
# List all job schedules
216
schedules = client.job_schedule.list()
217
for schedule in schedules:
218
print(f"Schedule {schedule.id}: {schedule.state}")
219
print(f" Next run: {schedule.execution_info.next_run_time}")
220
print(f" Recent job ID: {schedule.execution_info.recent_job.id if schedule.execution_info.recent_job else 'None'}")
221
222
# Check if schedule exists
223
if client.job_schedule.exists("daily-processing-schedule"):
224
# Get schedule details
225
schedule = client.job_schedule.get("daily-processing-schedule")
226
print(f"Schedule state: {schedule.state}")
227
228
# Temporarily disable the schedule
229
client.job_schedule.disable("daily-processing-schedule")
230
231
# Re-enable when ready
232
client.job_schedule.enable("daily-processing-schedule")
233
234
# Terminate the schedule (completes current job but stops future runs)
235
# client.job_schedule.terminate("daily-processing-schedule")
236
237
# Delete the schedule entirely
238
# client.job_schedule.delete("daily-processing-schedule")
239
```
240
241
### Updating Job Schedule Configuration
242
243
```python
244
from azure.batch.models import (
245
JobSchedulePatchParameter, Schedule, JobSpecification
246
)
247
248
# Update schedule timing
249
new_schedule = Schedule(
250
recurrence_interval=datetime.timedelta(hours=12), # Run twice daily instead of daily
251
start_window=datetime.timedelta(minutes=45)
252
)
253
254
# Update job specification
255
new_job_spec = JobSpecification(
256
pool_info=PoolInformation(pool_id="new-processing-pool"),
257
priority=200 # Higher priority
258
)
259
260
patch_params = JobSchedulePatchParameter(
261
schedule=new_schedule,
262
job_specification=new_job_spec
263
)
264
265
client.job_schedule.patch("daily-processing-schedule", patch_params)
266
```
267
268
### Advanced Schedule Configuration with Job Manager
269
270
```python
271
from azure.batch.models import (
272
JobScheduleAddParameter, Schedule, JobSpecification,
273
JobManagerTask, UserIdentity, AutoUserSpecification
274
)
275
276
# Job manager to coordinate scheduled job execution
277
job_manager = JobManagerTask(
278
id="schedule-manager",
279
command_line="python schedule_coordinator.py",
280
display_name="Schedule Coordinator",
281
user_identity=UserIdentity(
282
auto_user=AutoUserSpecification(
283
scope="pool",
284
elevation_level="nonadmin"
285
)
286
),
287
kill_job_on_completion=True
288
)
289
290
# Job specification with manager task
291
managed_job_spec = JobSpecification(
292
pool_info=PoolInformation(pool_id="managed-pool"),
293
job_manager_task=job_manager,
294
priority=150
295
)
296
297
# Schedule for complex managed jobs
298
complex_schedule = JobScheduleAddParameter(
299
id="managed-processing-schedule",
300
display_name="Managed Processing Schedule",
301
schedule=Schedule(
302
recurrence_interval=datetime.timedelta(hours=6),
303
start_window=datetime.timedelta(minutes=15)
304
),
305
job_specification=managed_job_spec,
306
metadata=[
307
MetadataItem(name="purpose", value="automated-processing"),
308
MetadataItem(name="owner", value="data-team")
309
]
310
)
311
312
client.job_schedule.add(complex_schedule)
313
```
314
315
## Types
316
317
### Job Schedule Configuration Types
318
319
```python { .api }
320
class JobScheduleAddParameter:
321
"""Job schedule creation specification."""
322
def __init__(self):
323
self.id: str
324
self.display_name: str
325
self.schedule: Schedule
326
self.job_specification: JobSpecification
327
self.metadata: List[MetadataItem]
328
329
class Schedule:
330
"""Schedule configuration for job execution."""
331
def __init__(self):
332
self.do_not_run_until: datetime.datetime
333
self.do_not_run_after: datetime.datetime
334
self.start_window: datetime.timedelta
335
self.recurrence_interval: datetime.timedelta
336
337
class CloudJobSchedule:
338
"""Job schedule information and state."""
339
def __init__(self):
340
self.id: str
341
self.display_name: str
342
self.url: str
343
self.e_tag: str
344
self.last_modified: datetime.datetime
345
self.creation_time: datetime.datetime
346
self.state: str # active, completed, disabled, terminating, deleting
347
self.state_transition_time: datetime.datetime
348
self.previous_state: str
349
self.previous_state_transition_time: datetime.datetime
350
self.schedule: Schedule
351
self.job_specification: JobSpecification
352
self.execution_info: JobScheduleExecutionInformation
353
self.metadata: List[MetadataItem]
354
self.stats: JobScheduleStatistics
355
356
class JobScheduleExecutionInformation:
357
"""Job schedule execution information."""
358
def __init__(self):
359
self.next_run_time: datetime.datetime
360
self.recent_job: RecentJob
361
self.end_time: datetime.datetime
362
363
class RecentJob:
364
"""Information about recently created job from schedule."""
365
def __init__(self):
366
self.id: str
367
self.url: str
368
```
369
370
### Job Schedule Update Types
371
372
```python { .api }
373
class JobSchedulePatchParameter:
374
"""Parameters for patching job schedule properties."""
375
def __init__(self):
376
self.schedule: Schedule
377
self.job_specification: JobSpecification
378
self.metadata: List[MetadataItem]
379
380
class JobScheduleUpdateParameter:
381
"""Parameters for updating job schedule properties."""
382
def __init__(self):
383
self.schedule: Schedule
384
self.job_specification: JobSpecification
385
self.metadata: List[MetadataItem]
386
```
387
388
### Job Schedule Option Types
389
390
```python { .api }
391
class JobScheduleListOptions:
392
"""Options for listing job schedules."""
393
def __init__(self):
394
self.filter: str
395
self.select: str
396
self.expand: str
397
self.max_results: int
398
self.timeout: int
399
400
class JobScheduleGetOptions:
401
"""Options for getting job schedule information."""
402
def __init__(self):
403
self.select: str
404
self.expand: str
405
self.timeout: int
406
407
class JobScheduleAddOptions:
408
"""Options for adding job schedules."""
409
def __init__(self):
410
self.timeout: int
411
412
class JobScheduleDeleteOptions:
413
"""Options for deleting job schedules."""
414
def __init__(self):
415
self.timeout: int
416
417
class JobScheduleExistsOptions:
418
"""Options for checking job schedule existence."""
419
def __init__(self):
420
self.timeout: int
421
```
422
423
## Notes
424
425
- Job schedules automatically create jobs based on the specified schedule and job specification
426
- Each scheduled job gets a unique ID based on the schedule ID and creation time
427
- Schedules can be temporarily disabled without deleting them
428
- The start window defines how long after the scheduled time a job can still be created
429
- Jobs created by schedules inherit the job specification properties
430
- Terminated schedules complete their current job but don't create new ones
431
- Deleted schedules cannot be recovered; create a new schedule if needed