Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script to run interrupt command #359

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions examples/mapdl_tyre_performance/interrupt_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ def interrupt_running_task(client, project_id) -> Project:
{"task_definition_id": task_def.id, "eval_status": "running"}
)
if not running_tasks:
log.info("No tasks are running.")
log.error("No tasks are running.")

task = running_tasks[0]
if not task.eval_status == "running":
log.info("Task is not running.")
log.error("Task is not running.")
return

log.info(f"Found running Task: {task.id}")
Expand All @@ -64,19 +64,28 @@ def interrupt_running_task(client, project_id) -> Project:
resp = client.session.get(command_defs_url)
command_defs = resp.json()["task_command_definitions"]
if not command_defs:
log.info(f"No command definitions found")
log.error(f"No command definitions found")
Copy link
Member

@PipKat PipKat May 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
log.error(f"No command definitions found")
log.error(f"No command definitions are found.")

Messages must be complete, with a subject AND a verb AND concluding punctuation.

return

cmd_def = None
for cmd in command_defs:
if cmd['name'] == 'interrupt':
cmd_def = cmd

log.info(f"Command definition id: {command_defs[0]['id']}")
if not cmd_def:
log.error(f"Interrupt command not found")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
log.error(f"Interrupt command not found")
log.error(f"Interrupt command is not found.")


log.info(f"Command definition id: {cmd_def['id']}")

command_url = f"{project_url}/task_commands"
data_str = f"""{{"task_commands" :
[
{{"task_id": "{task.id}",
"command_definition_id": "{command_defs[0]["id"]}",
"command_definition_id": "{cmd_def["id"]}",
"arguments": {{}}}}
]}}"""

log.debug(data_str)

resp = client.session.post(command_url, data=data_str)
if not resp.status_code == 201:
log.info("Failed to submit task command.")
Expand Down
Loading