Skip to content

Commit 8710803

Browse files
committed
Update monitoring and doc for cancelation
1 parent 167fc1f commit 8710803

2 files changed

Lines changed: 53 additions & 31 deletions

File tree

dapi/jobs.py

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def generate_job_request(
198198
main_input_automount = True
199199
found_input_def = False
200200
actual_input_param_name = input_dir_param_name # Default fallback
201-
201+
202202
if hasattr(job_attrs, "fileInputs") and job_attrs.fileInputs:
203203
# First try to find exact match with provided name
204204
for fi_def in job_attrs.fileInputs:
@@ -211,10 +211,15 @@ def generate_job_request(
211211
f"Found exact match for input parameter: '{actual_input_param_name}'"
212212
)
213213
break
214-
214+
215215
# If no exact match found, try to auto-detect common input directory names
216216
if not found_input_def:
217-
common_input_names = ["Input Directory", "Case Directory", "inputDirectory", "inputDir"]
217+
common_input_names = [
218+
"Input Directory",
219+
"Case Directory",
220+
"inputDirectory",
221+
"inputDir",
222+
]
218223
for fi_def in job_attrs.fileInputs:
219224
fi_name = getattr(fi_def, "name", "")
220225
if fi_name in common_input_names:
@@ -226,7 +231,7 @@ def generate_job_request(
226231
f"Auto-detected input parameter: '{actual_input_param_name}' (provided: '{input_dir_param_name}')"
227232
)
228233
break
229-
234+
230235
# If still not found, use the first fileInput as fallback
231236
if not found_input_def and job_attrs.fileInputs:
232237
fi_def = job_attrs.fileInputs[0]
@@ -237,7 +242,7 @@ def generate_job_request(
237242
print(
238243
f"Using first available fileInput: '{actual_input_param_name}' (no match found for '{input_dir_param_name}')"
239244
)
240-
245+
241246
if not found_input_def:
242247
print(
243248
f"Warning: No fileInputs found in app definition. Using provided name '{input_dir_param_name}'"
@@ -319,11 +324,11 @@ def generate_job_request(
319324
arg_name = getattr(app_arg_def, "name", "")
320325
input_mode = getattr(app_arg_def, "inputMode", "")
321326
default_value = getattr(app_arg_def, "arg", "")
322-
327+
323328
# Skip if this is the script parameter (already handled above)
324329
if script_filename and arg_name in script_param_names:
325330
continue
326-
331+
327332
# Check if this arg is required and not already provided
328333
if input_mode == "REQUIRED" and arg_name:
329334
# Check if user already provided this arg
@@ -333,23 +338,26 @@ def generate_job_request(
333338
if user_arg.get("name") == arg_name:
334339
user_provided = True
335340
break
336-
341+
337342
# Also check if already added to job_req
338343
already_added = False
339344
for existing_arg in job_req["parameterSet"]["appArgs"]:
340345
if existing_arg.get("name") == arg_name:
341346
already_added = True
342347
break
343-
348+
344349
if not user_provided and not already_added:
345350
if default_value:
346-
print(f"Auto-adding required appArg '{arg_name}' with default: '{default_value}'")
347-
job_req["parameterSet"]["appArgs"].append({
348-
"name": arg_name,
349-
"arg": default_value
350-
})
351+
print(
352+
f"Auto-adding required appArg '{arg_name}' with default: '{default_value}'"
353+
)
354+
job_req["parameterSet"]["appArgs"].append(
355+
{"name": arg_name, "arg": default_value}
356+
)
351357
else:
352-
print(f"Warning: Required appArg '{arg_name}' has no default value.")
358+
print(
359+
f"Warning: Required appArg '{arg_name}' has no default value."
360+
)
353361

354362
# Process envVariables - add all required envVariables that aren't provided by user
355363
if hasattr(param_set_def, "envVariables") and param_set_def.envVariables:
@@ -358,11 +366,11 @@ def generate_job_request(
358366
input_mode = getattr(env_var_def, "inputMode", "")
359367
default_value = getattr(env_var_def, "value", "")
360368
enum_values = getattr(env_var_def, "enum_values", None)
361-
369+
362370
# Skip if this is the script parameter (already handled above)
363371
if script_filename and var_key in script_param_names:
364372
continue
365-
373+
366374
# Check if this variable is required and not already provided by user
367375
if input_mode == "REQUIRED" and var_key:
368376
# Check if user already provided this variable
@@ -372,33 +380,42 @@ def generate_job_request(
372380
if user_var.get("key") == var_key:
373381
user_provided = True
374382
break
375-
376-
# Also check if already added to job_req
383+
384+
# Also check if already added to job_req
377385
already_added = False
378386
for existing_var in job_req["parameterSet"]["envVariables"]:
379387
if existing_var.get("key") == var_key:
380388
already_added = True
381389
break
382-
390+
383391
if not user_provided and not already_added:
384392
# Use default value if available
385393
value_to_use = default_value
386-
394+
387395
# If no default but has enum values, use the first one
388-
if not value_to_use and enum_values and isinstance(enum_values, dict):
396+
if (
397+
not value_to_use
398+
and enum_values
399+
and isinstance(enum_values, dict)
400+
):
389401
value_to_use = list(enum_values.keys())[0]
390-
print(f"Auto-setting required env var '{var_key}' to first available option: '{value_to_use}'")
402+
print(
403+
f"Auto-setting required env var '{var_key}' to first available option: '{value_to_use}'"
404+
)
391405
elif value_to_use:
392-
print(f"Auto-setting required env var '{var_key}' to default: '{value_to_use}'")
406+
print(
407+
f"Auto-setting required env var '{var_key}' to default: '{value_to_use}'"
408+
)
393409
else:
394-
print(f"Warning: Required env var '{var_key}' has no default value.")
410+
print(
411+
f"Warning: Required env var '{var_key}' has no default value."
412+
)
395413
continue
396-
414+
397415
# Add to job request
398-
job_req["parameterSet"]["envVariables"].append({
399-
"key": var_key,
400-
"value": value_to_use
401-
})
416+
job_req["parameterSet"]["envVariables"].append(
417+
{"key": var_key, "value": value_to_use}
418+
)
402419

403420
# --- Handle extra parameters ---
404421
if extra_app_args:
@@ -820,7 +837,7 @@ def monitor(self, interval: int = 15, timeout_minutes: Optional[int] = None) ->
820837
pbar_monitoring = tqdm(
821838
total=total_iterations,
822839
desc="Monitoring job",
823-
ncols=100,
840+
dynamic_ncols=True,
824841
unit=" checks",
825842
leave=True,
826843
) # leave=True keeps bar after completion

docs/jobs.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,11 @@ status = job.get_status()
313313
print(f"Status after cancel: {status}")
314314
```
315315

316+
The `cancel()` method sends a cancellation request to Tapis. Note that:
317+
- Cancellation may not be immediate and depends on the job's current state
318+
- Jobs already in terminal states (FINISHED, FAILED, etc.) cannot be cancelled
319+
- The job status will eventually change to "CANCELLED" if the cancellation is successful
320+
316321
### Resuming Monitoring
317322

318323
```python

0 commit comments

Comments
 (0)