0
# Job Operations
1
2
Job management capabilities for creating, configuring, and controlling logical containers that organize and manage task execution within batch pools. Jobs define the execution environment, constraints, and lifecycle management for groups of related tasks.
3
4
## Capabilities
5
6
### Job Lifecycle Management
7
8
Create, retrieve, update, and delete jobs with comprehensive configuration options.
9
10
```python { .api }
11
def add(job, job_add_options=None, custom_headers=None, raw=False, **operation_config):
12
"""
13
Add a job to the specified account.
14
15
Args:
16
job: The job to add (JobSpecification)
17
job_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_list_options=None, custom_headers=None, raw=False, **operation_config):
26
"""
27
List all jobs in the account.
28
29
Args:
30
job_list_options: Additional options for listing
31
32
Returns:
33
ItemPaged[CloudJob]: Paginated list of jobs
34
"""
35
36
def get(job_id, job_get_options=None, custom_headers=None, raw=False, **operation_config):
37
"""
38
Get information about the specified job.
39
40
Args:
41
job_id: ID of the job to retrieve
42
job_get_options: Additional options for the operation
43
44
Returns:
45
CloudJob: Job information
46
"""
47
48
def delete(job_id, job_delete_options=None, custom_headers=None, raw=False, **operation_config):
49
"""
50
Delete the specified job.
51
52
Args:
53
job_id: ID of the job to delete
54
job_delete_options: Additional options for deletion
55
56
Returns:
57
None
58
"""
59
```
60
61
### Job Configuration Updates
62
63
Update job properties and configuration after creation.
64
65
```python { .api }
66
def patch(job_id, job_patch_parameter, job_patch_options=None, custom_headers=None, raw=False, **operation_config):
67
"""
68
Update properties of the specified job.
69
70
Args:
71
job_id: ID of the job to update
72
job_patch_parameter: Properties to update
73
job_patch_options: Additional options
74
75
Returns:
76
None
77
"""
78
79
def update(job_id, job_update_parameter, job_update_options=None, custom_headers=None, raw=False, **operation_config):
80
"""
81
Update the properties of the specified job.
82
83
Args:
84
job_id: ID of the job to update
85
job_update_parameter: Properties to update
86
87
Returns:
88
None
89
"""
90
```
91
92
### Job State Control
93
94
Control job execution state including enabling, disabling, and terminating jobs.
95
96
```python { .api }
97
def enable(job_id, job_enable_options=None, custom_headers=None, raw=False, **operation_config):
98
"""
99
Enable the specified job, allowing new tasks to run.
100
101
Args:
102
job_id: ID of the job to enable
103
job_enable_options: Additional options
104
105
Returns:
106
None
107
"""
108
109
def disable(job_id, disable_job_parameter, job_disable_options=None, custom_headers=None, raw=False, **operation_config):
110
"""
111
Disable the specified job, preventing new tasks from running.
112
113
Args:
114
job_id: ID of the job to disable
115
disable_job_parameter: Disable parameters including what to do with active tasks
116
job_disable_options: Additional options
117
118
Returns:
119
None
120
"""
121
122
def terminate(job_id, job_terminate_parameter=None, job_terminate_options=None, custom_headers=None, raw=False, **operation_config):
123
"""
124
Terminate the specified job, marking it as completed.
125
126
Args:
127
job_id: ID of the job to terminate
128
job_terminate_parameter: Termination parameters including reason
129
job_terminate_options: Additional options
130
131
Returns:
132
None
133
"""
134
```
135
136
## Usage Examples
137
138
### Creating a Basic Job
139
140
```python
141
from azure.batch.models import JobSpecification, PoolInformation
142
143
# Create job specification
144
job_spec = JobSpecification(
145
id="my-processing-job",
146
priority=100,
147
pool_info=PoolInformation(pool_id="my-pool"),
148
display_name="Data Processing Job"
149
)
150
151
# Add the job
152
client.job.add(job_spec)
153
```
154
155
### Creating a Job with Constraints and Environment
156
157
```python
158
from azure.batch.models import (
159
JobSpecification, PoolInformation, JobConstraints,
160
EnvironmentSetting, JobManagerTask, UserIdentity,
161
AutoUserSpecification
162
)
163
164
# Define job constraints
165
job_constraints = JobConstraints(
166
max_wall_clock_time=datetime.timedelta(hours=24),
167
max_task_retry_count=3
168
)
169
170
# Environment settings for all tasks in the job
171
common_env_settings = [
172
EnvironmentSetting(name="DATA_PATH", value="/mnt/data"),
173
EnvironmentSetting(name="LOG_LEVEL", value="INFO")
174
]
175
176
# Job manager task to coordinate job execution
177
job_manager = JobManagerTask(
178
id="job-manager",
179
command_line="python job_manager.py",
180
display_name="Job Manager",
181
user_identity=UserIdentity(
182
auto_user=AutoUserSpecification(
183
scope="pool",
184
elevation_level="nonadmin"
185
)
186
),
187
kill_job_on_completion=True,
188
run_exclusive=False
189
)
190
191
job_spec = JobSpecification(
192
id="complex-job",
193
priority=200,
194
pool_info=PoolInformation(pool_id="my-pool"),
195
constraints=job_constraints,
196
common_environment_settings=common_env_settings,
197
job_manager_task=job_manager,
198
display_name="Complex Processing Job"
199
)
200
201
client.job.add(job_spec)
202
```
203
204
### Creating a Job with Preparation and Release Tasks
205
206
```python
207
from azure.batch.models import (
208
JobPreparationTask, JobReleaseTask, ResourceFile
209
)
210
211
# Job preparation task - runs once on each node before any job tasks
212
job_prep = JobPreparationTask(
213
id="job-prep",
214
command_line="mkdir -p /tmp/jobdata && download_data.sh",
215
resource_files=[
216
ResourceFile(
217
http_url="https://mystorageaccount.blob.core.windows.net/scripts/download_data.sh",
218
file_path="download_data.sh"
219
)
220
],
221
user_identity=UserIdentity(
222
auto_user=AutoUserSpecification(
223
scope="pool",
224
elevation_level="admin"
225
)
226
),
227
wait_for_success=True
228
)
229
230
# Job release task - runs after all tasks complete on each node
231
job_release = JobReleaseTask(
232
id="job-release",
233
command_line="cleanup.sh && rm -rf /tmp/jobdata",
234
resource_files=[
235
ResourceFile(
236
http_url="https://mystorageaccount.blob.core.windows.net/scripts/cleanup.sh",
237
file_path="cleanup.sh"
238
)
239
]
240
)
241
242
job_spec = JobSpecification(
243
id="job-with-prep-release",
244
pool_info=PoolInformation(pool_id="my-pool"),
245
job_preparation_task=job_prep,
246
job_release_task=job_release
247
)
248
249
client.job.add(job_spec)
250
```
251
252
### Managing Job State
253
254
```python
255
from azure.batch.models import DisableJobParameter
256
257
# List all jobs
258
jobs = client.job.list()
259
for job in jobs:
260
print(f"Job {job.id}: {job.state}")
261
262
# Get specific job details
263
job = client.job.get("my-processing-job")
264
print(f"Job priority: {job.priority}")
265
print(f"Creation time: {job.creation_time}")
266
267
# Disable job (stop new tasks, but let running tasks complete)
268
disable_params = DisableJobParameter(
269
disable_tasks="taskcompletion" # wait for running tasks to complete
270
)
271
client.job.disable("my-processing-job", disable_params)
272
273
# Re-enable job
274
client.job.enable("my-processing-job")
275
276
# Terminate job with reason
277
from azure.batch.models import JobTerminateParameter
278
terminate_params = JobTerminateParameter(
279
terminate_reason="Manual termination for maintenance"
280
)
281
client.job.terminate("my-processing-job", terminate_params)
282
283
# Delete completed job
284
client.job.delete("my-processing-job")
285
```
286
287
### Updating Job Properties
288
289
```python
290
from azure.batch.models import JobPatchParameter, JobConstraints
291
292
# Update job priority and constraints
293
patch_params = JobPatchParameter(
294
priority=50, # Lower priority
295
constraints=JobConstraints(
296
max_wall_clock_time=datetime.timedelta(hours=12),
297
max_task_retry_count=5
298
)
299
)
300
301
client.job.patch("my-processing-job", patch_params)
302
```
303
304
## Types
305
306
### Job Configuration Types
307
308
```python { .api }
309
class JobSpecification:
310
"""Job creation specification."""
311
def __init__(self):
312
self.id: str
313
self.display_name: str
314
self.priority: int # -1000 to 1000, higher is more priority
315
self.constraints: JobConstraints
316
self.job_manager_task: JobManagerTask
317
self.job_preparation_task: JobPreparationTask
318
self.job_release_task: JobReleaseTask
319
self.common_environment_settings: List[EnvironmentSetting]
320
self.pool_info: PoolInformation
321
self.on_all_tasks_complete: str # noaction, terminatejob
322
self.on_task_failure: str # noaction, performexitoptionsjobaction
323
self.metadata: List[MetadataItem]
324
self.uses_task_dependencies: bool
325
326
class JobConstraints:
327
"""Job execution constraints."""
328
def __init__(self):
329
self.max_wall_clock_time: datetime.timedelta
330
self.max_task_retry_count: int
331
332
class PoolInformation:
333
"""Pool information for job execution."""
334
def __init__(self):
335
self.pool_id: str
336
self.auto_pool_specification: AutoPoolSpecification
337
338
class JobManagerTask:
339
"""Job manager task specification."""
340
def __init__(self):
341
self.id: str
342
self.display_name: str
343
self.command_line: str
344
self.resource_files: List[ResourceFile]
345
self.environment_settings: List[EnvironmentSetting]
346
self.constraints: TaskConstraints
347
self.kill_job_on_completion: bool
348
self.user_identity: UserIdentity
349
self.run_exclusive: bool
350
self.application_package_references: List[ApplicationPackageReference]
351
self.authentication_token_settings: AuthenticationTokenSettings
352
353
class JobPreparationTask:
354
"""Job preparation task specification."""
355
def __init__(self):
356
self.id: str
357
self.command_line: str
358
self.resource_files: List[ResourceFile]
359
self.environment_settings: List[EnvironmentSetting]
360
self.constraints: TaskConstraints
361
self.wait_for_success: bool
362
self.user_identity: UserIdentity
363
self.rerun_on_node_reboot_after_success: bool
364
365
class JobReleaseTask:
366
"""Job release task specification."""
367
def __init__(self):
368
self.id: str
369
self.command_line: str
370
self.resource_files: List[ResourceFile]
371
self.environment_settings: List[EnvironmentSetting]
372
self.max_wall_clock_time: datetime.timedelta
373
self.retention_time: datetime.timedelta
374
self.user_identity: UserIdentity
375
```
376
377
### Job State Types
378
379
```python { .api }
380
class CloudJob:
381
"""Job information and state."""
382
def __init__(self):
383
self.id: str
384
self.display_name: str
385
self.uses_task_dependencies: bool
386
self.url: str
387
self.e_tag: str
388
self.last_modified: datetime.datetime
389
self.creation_time: datetime.datetime
390
self.state: str # active, disabling, disabled, enabling, terminating, completed, deleting
391
self.state_transition_time: datetime.datetime
392
self.previous_state: str
393
self.previous_state_transition_time: datetime.datetime
394
self.priority: int
395
self.constraints: JobConstraints
396
self.job_manager_task: JobManagerTask
397
self.job_preparation_task: JobPreparationTask
398
self.job_release_task: JobReleaseTask
399
self.common_environment_settings: List[EnvironmentSetting]
400
self.pool_info: PoolInformation
401
self.on_all_tasks_complete: str
402
self.on_task_failure: str
403
self.metadata: List[MetadataItem]
404
self.execution_info: JobExecutionInformation
405
self.stats: JobStatistics
406
407
class JobExecutionInformation:
408
"""Job execution information."""
409
def __init__(self):
410
self.start_time: datetime.datetime
411
self.end_time: datetime.datetime
412
self.pool_id: str
413
self.scheduling_error: JobSchedulingError
414
self.terminate_reason: str
415
416
class DisableJobParameter:
417
"""Parameters for disabling a job."""
418
def __init__(self):
419
self.disable_tasks: str # requeue, terminate, wait
420
421
class JobTerminateParameter:
422
"""Parameters for terminating a job."""
423
def __init__(self):
424
self.terminate_reason: str
425
426
class JobPatchParameter:
427
"""Parameters for patching job properties."""
428
def __init__(self):
429
self.priority: int
430
self.constraints: JobConstraints
431
self.pool_info: PoolInformation
432
self.metadata: List[MetadataItem]
433
self.on_all_tasks_complete: str
434
```