Jobs
Job submission, monitoring, and management functionality for DesignSafe computational workflows.
Job Request Generation
Generate a Tapis job request dictionary based on app definition and inputs.
Creates a properly formatted job request dictionary by retrieving the specified application details and applying user-provided overrides and additional parameters. The function automatically maps the script filename (if provided) and input directory to the appropriate app parameters. It dynamically reads the app definition to detect parameter names, determines whether to use appArgs or envVariables, and automatically populates all required parameters with default values when available.
PARAMETER | DESCRIPTION |
---|---|
tapis_client
|
Authenticated Tapis client instance.
TYPE:
|
app_id
|
The ID of the Tapis application to use for the job.
TYPE:
|
input_dir_uri
|
Tapis URI to the input directory containing job files.
TYPE:
|
script_filename
|
Name of the main script file to execute. If None (default), no script parameter is added. This is suitable for apps like OpenFOAM that don't take a script argument.
TYPE:
|
app_version
|
Specific app version to use. If None, uses latest.
TYPE:
|
job_name
|
Custom job name. If None, auto-generates based on app ID and timestamp.
TYPE:
|
description
|
Job description. If None, uses app description.
TYPE:
|
tags
|
List of tags to associate with the job.
TYPE:
|
max_minutes
|
Maximum runtime in minutes. Overrides app default.
TYPE:
|
node_count
|
Number of compute nodes. Overrides app default.
TYPE:
|
cores_per_node
|
Cores per node. Overrides app default.
TYPE:
|
memory_mb
|
Memory in MB. Overrides app default.
TYPE:
|
queue
|
Execution queue name. Overrides app default.
TYPE:
|
allocation
|
TACC allocation to charge for compute time.
TYPE:
|
archive_system
|
Archive system for job outputs. If "designsafe" is specified, uses "designsafe.storage.default". If None, uses app default.
TYPE:
|
archive_path
|
Archive directory path. Can be a full path or just a directory name in MyData (e.g., "tapis-jobs-archive"). If None and archive_system is "designsafe", defaults to "${EffectiveUserId}/tapis-jobs-archive/${JobCreateDate}/${JobUUID}".
TYPE:
|
extra_file_inputs
|
Additional file inputs beyond the main input directory.
TYPE:
|
extra_app_args
|
Additional application arguments. Use for parameters expected in 'appArgs' by the Tapis app.
TYPE:
|
extra_env_vars
|
Additional environment variables. Use for parameters expected in 'envVariables' by the Tapis app (e.g., OpenFOAM solver, mesh). Each item should be a dict like {"key": "VAR_NAME", "value": "var_value"}.
TYPE:
|
extra_scheduler_options
|
Additional scheduler options.
TYPE:
|
script_param_names
|
Parameter names/keys to check for script placement if script_filename is provided. Defaults to ["Input Script", "Main Script", "tclScript"].
TYPE:
|
input_dir_param_name
|
The 'name' of the fileInput in the Tapis app definition that corresponds to input_dir_uri. Defaults to "Input Directory". The function will auto-detect the correct name from the app definition.
TYPE:
|
allocation_param_name
|
Parameter name for TACC allocation. Defaults to "TACC Allocation".
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Dict[str, Any]
|
Dict[str, Any]: Complete job request dictionary ready for submission to Tapis. |
RAISES | DESCRIPTION |
---|---|
AppDiscoveryError
|
If the specified app cannot be found or details cannot be retrieved. |
ValueError
|
If required parameters are missing, invalid, or if script_filename is provided but a suitable placement (matching script_param_names) cannot be found in the app's parameterSet. |
JobSubmissionError
|
If unexpected errors occur during job request generation. |
Source code in dapi/jobs.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 |
|
Job Submission
Submit a pre-generated job request dictionary to Tapis.
Takes a complete job request dictionary (typically generated by generate_job_request) and submits it to the Tapis jobs service for execution. Prints the job request details before submission for debugging purposes.
PARAMETER | DESCRIPTION |
---|---|
tapis_client
|
Authenticated Tapis client instance.
TYPE:
|
job_request
|
Complete job request dictionary containing all necessary job parameters, file inputs, and configuration.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
SubmittedJob
|
A SubmittedJob object for monitoring and managing the submitted job.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If job_request is not a dictionary. |
JobSubmissionError
|
If the Tapis job submission fails, with additional context from the HTTP request and response when available. |
Example
job_request = generate_job_request(...) submitted_job = submit_job_request(client, job_request)
--- Submitting Tapis Job Request --- { "name": "matlab-r2023a-20231201_143022", "appId": "matlab-r2023a", ... }
Job submitted successfully. UUID: 12345678-1234-1234-1234-123456789abc
Source code in dapi/jobs.py
Job Monitoring
Get the current status of a job by UUID.
Standalone convenience function that creates a temporary SubmittedJob instance to retrieve the current status of an existing job.
PARAMETER | DESCRIPTION |
---|---|
t
|
Authenticated Tapis client instance.
TYPE:
|
job_uuid
|
The UUID of the job to check.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
Current job status (e.g., "QUEUED", "RUNNING", "FINISHED", "FAILED").
TYPE:
|
RAISES | DESCRIPTION |
---|---|
JobMonitorError
|
If status retrieval fails. |
TypeError
|
If t is not a Tapis instance. |
ValueError
|
If job_uuid is empty or invalid. |
Example
status = get_job_status(client, "12345678-1234-1234-1234-123456789abc") print(f"Job status: {status}")
Source code in dapi/jobs.py
Print a runtime summary for a job by UUID.
Standalone convenience function that creates a temporary SubmittedJob instance to analyze and print the runtime summary of an existing job.
PARAMETER | DESCRIPTION |
---|---|
t
|
Authenticated Tapis client instance.
TYPE:
|
job_uuid
|
The UUID of the job to analyze.
TYPE:
|
verbose
|
If True, prints detailed job history events in addition to the runtime summary. Defaults to False.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
JobMonitorError
|
If job details cannot be retrieved. |
TypeError
|
If t is not a Tapis instance. |
ValueError
|
If job_uuid is empty or invalid. |
Example
get_runtime_summary(client, "12345678-1234-1234-1234-123456789abc")
Runtime Summary
QUEUED time: 00:05:30 RUNNING time: 01:23:45 TOTAL time: 01:29:15
Source code in dapi/jobs.py
Print a user-friendly interpretation of a job status.
Provides human-readable explanations for various job status values, including both standard Tapis states and special monitoring states.
PARAMETER | DESCRIPTION |
---|---|
final_status
|
The job status to interpret. Can be a standard Tapis status ("FINISHED", "FAILED", etc.) or a special monitoring status (STATUS_TIMEOUT, STATUS_INTERRUPTED, etc.).
TYPE:
|
job_uuid
|
The job UUID to include in the message for context. If None, uses generic "Job" in the message. Defaults to None.
TYPE:
|
Example
interpret_job_status("FINISHED", "12345678-1234-1234-1234-123456789abc") Job 12345678-1234-1234-1234-123456789abc completed successfully.
interpret_job_status("FAILED") Job failed. Check logs or job details.
interpret_job_status(STATUS_TIMEOUT, "12345678-1234-1234-1234-123456789abc") Job 12345678-1234-1234-1234-123456789abc monitoring timed out.
Source code in dapi/jobs.py
SubmittedJob Class
Represents a submitted Tapis job with methods for monitoring and management.
This class provides a high-level interface for interacting with Tapis jobs, including status monitoring, output retrieval, job cancellation, and runtime analysis. It caches job details and status to minimize API calls.
ATTRIBUTE | DESCRIPTION |
---|---|
uuid |
The unique identifier of the Tapis job.
TYPE:
|
TERMINAL_STATES |
List of job states that indicate completion.
TYPE:
|
Example
job = SubmittedJob(client, "12345678-1234-1234-1234-123456789abc") status = job.status if status in job.TERMINAL_STATES: ... print("Job completed") final_status = job.monitor(timeout_minutes=60)
Initialize a SubmittedJob instance for an existing Tapis job.
PARAMETER | DESCRIPTION |
---|---|
tapis_client
|
Authenticated Tapis client instance.
TYPE:
|
job_uuid
|
The UUID of an existing Tapis job.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
TypeError
|
If tapis_client is not a Tapis instance. |
ValueError
|
If job_uuid is empty or not a string. |
Source code in dapi/jobs.py
details
property
Get cached job details, fetching from Tapis if not already cached.
RETURNS | DESCRIPTION |
---|---|
Tapis
|
Complete job details object containing all job metadata, configuration, and current state information.
TYPE:
|
status
property
Get the current job status, using cached value when appropriate.
For terminal states, returns the cached status without making an API call. For non-terminal states, may fetch fresh status depending on cache state.
RETURNS | DESCRIPTION |
---|---|
str
|
Current job status (e.g., "QUEUED", "RUNNING", "FINISHED", "FAILED"). Returns STATUS_UNKNOWN if status cannot be determined.
TYPE:
|
last_message
property
Get the last status message recorded for the job.
Retrieves the most recent status message from the job details, which typically contains information about the current job state or any errors that have occurred.
RETURNS | DESCRIPTION |
---|---|
Optional[str]
|
str or None: The last status message if available and non-empty, otherwise None. Empty strings are treated as None. |
Note
Returns None if job details cannot be retrieved or if no message is available. Does not raise exceptions for retrieval failures.
archive_uri
property
Get the Tapis URI of the job's archive directory.
Returns the URI where job outputs are stored after completion. The archive directory contains all job outputs, logs, and metadata.
RETURNS | DESCRIPTION |
---|---|
Optional[str]
|
str or None: Tapis URI of the archive directory if available, otherwise None if archive information is not set. |
Example
uri = job.archive_uri if uri: ... print(f"Job outputs at: {uri}") ... files = client.files.list(uri)
get_status
Get the current job status from Tapis API.
PARAMETER | DESCRIPTION |
---|---|
force_refresh
|
If True, always makes a fresh API call. If False, may return cached status. Defaults to True.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
Current job status from Tapis API.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
JobMonitorError
|
If status cannot be retrieved from Tapis. |
Source code in dapi/jobs.py
monitor
Monitor job status with progress bars until completion or timeout.
Continuously monitors the job status using tqdm progress bars to show progress through different job phases (waiting, running). Handles interruptions and errors gracefully.
PARAMETER | DESCRIPTION |
---|---|
interval
|
Status check interval in seconds. Defaults to 15.
TYPE:
|
timeout_minutes
|
Maximum monitoring time in minutes. If None, uses the job's maxMinutes from its configuration. Use -1 or 0 for unlimited monitoring. Defaults to None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
Final job status. Can be a standard Tapis status ("FINISHED", "FAILED", etc.) or a special monitoring status: - STATUS_TIMEOUT: Monitoring timed out - STATUS_INTERRUPTED: User interrupted monitoring (Ctrl+C) - STATUS_MONITOR_ERROR: Error occurred during monitoring
TYPE:
|
Example
job = SubmittedJob(client, job_uuid) final_status = job.monitor(interval=30, timeout_minutes=120) Monitoring Job: 12345678-1234-1234-1234-123456789abc Waiting for job to start: 100%|████████| 12 checks Monitoring job: 100%|████████████| 45/45 checks Status: FINISHED if final_status == "FINISHED": ... print("Job completed successfully!")
Source code in dapi/jobs.py
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 |
|
print_runtime_summary
Print a summary of job runtime phases and total execution time.
Analyzes the job's execution history to show time spent in different phases (queued, running) and calculates the total runtime from submission to completion.
PARAMETER | DESCRIPTION |
---|---|
verbose
|
If True, prints detailed job history events in addition to the runtime summary. Defaults to False.
TYPE:
|
Example
job.print_runtime_summary()
Runtime Summary
QUEUED time: 00:05:30 RUNNING time: 01:23:45 TOTAL time: 01:29:15
job.print_runtime_summary(verbose=True)
Detailed Job History: Event: JOB_NEW_STATUS, Detail: PENDING, Time: 2023-12-01T14:30:22.123456Z Event: JOB_NEW_STATUS, Detail: QUEUED, Time: 2023-12-01T14:30:25.234567Z ...
Summary: QUEUED time: 00:05:30 RUNNING time: 01:23:45 TOTAL time: 01:29:15
Source code in dapi/jobs.py
list_outputs
List files and directories in the job's archive directory.
PARAMETER | DESCRIPTION |
---|---|
path
|
Relative path within the job archive to list. Defaults to "/" (archive root).
TYPE:
|
limit
|
Maximum number of items to return. Defaults to 100.
TYPE:
|
offset
|
Number of items to skip for pagination. Defaults to 0.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
List[Tapis]
|
List[Tapis]: List of file and directory objects in the specified path. |
RAISES | DESCRIPTION |
---|---|
FileOperationError
|
If archive information is not available, the path cannot be accessed, or listing fails. |
Example
outputs = job.list_outputs() for item in outputs: ... print(f"{item.name} ({item.type})") tapisjob.out (file) tapisjob.err (file) results/ (dir)
results = job.list_outputs(path="results/")
Source code in dapi/jobs.py
download_output
Download a specific file from the job's archive directory.
PARAMETER | DESCRIPTION |
---|---|
remote_path
|
Relative path to the file within the job archive.
TYPE:
|
local_target
|
Local filesystem path where the file should be saved.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
FileOperationError
|
If archive information is not available or download fails. |
Example
job.download_output("tapisjob.out", "/local/job_output.txt") job.download_output("results/data.txt", "/local/results/data.txt")
Source code in dapi/jobs.py
get_output_content
Retrieve the content of a specific output file from the job's archive.
Fetches and returns the content of a file from the job's archive directory as a string. Useful for examining log files, output files, and error files.
PARAMETER | DESCRIPTION |
---|---|
output_filename
|
Name of the file in the job's archive root (e.g., "tapisjob.out", "tapisjob.err", "results.txt").
TYPE:
|
max_lines
|
If specified, returns only the last N lines of the file. Useful for large log files. Defaults to None (full file).
TYPE:
|
missing_ok
|
If True and the file is not found, returns None. If False and not found, raises FileOperationError. Defaults to True.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Optional[str]
|
str or None: Content of the file as a string, or None if the file is not found and missing_ok=True. |
RAISES | DESCRIPTION |
---|---|
FileOperationError
|
If the job archive is not available, the file is not found (and missing_ok=False), or if there's an error fetching the file. |
Example
Get job output log
output = job.get_output_content("tapisjob.out") if output: ... print(output)
Get last 50 lines of error log
errors = job.get_output_content("tapisjob.err", max_lines=50)
Require file to exist (raise error if missing)
results = job.get_output_content("results.txt", missing_ok=False)
Source code in dapi/jobs.py
1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 |
|
cancel
Attempt to cancel the job execution.
Sends a cancellation request to Tapis. Note that cancellation may not be immediate and depends on the job's current state and the execution system.
RAISES | DESCRIPTION |
---|---|
JobMonitorError
|
If the cancellation request fails or encounters an error. |
Note
Jobs that are already in terminal states cannot be cancelled. The method will print the current status if cancellation is not possible.
Example
job.cancel() Attempting to cancel job 12345678-1234-1234-1234-123456789abc... Cancel request sent for job 12345678-1234-1234-1234-123456789abc. Status may take time to update.