Skip to content

Commit

Permalink
feat(agent): Add action to cancel or stop a job
Browse files Browse the repository at this point in the history
  • Loading branch information
adityahase committed Jan 20, 2025
1 parent 368c379 commit f30aff6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions press/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,9 @@ def update_monitor_rules(self, rules, routes):
def get_job_status(self, id):
return self.get(f"jobs/{id}")

def cancel_job(self, id):
return self.post(f"jobs/{id}/cancel")

def get_site_sid(self, site, user=None):
if user:
data = {"user": user}
Expand Down
1 change: 1 addition & 0 deletions press/press/doctype/agent_job/agent_job.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ frappe.ui.form.on('Agent Job', {
__('Succeed and Process Job Updates'),
'succeed_and_process_job_updates',
],
[__('Cancel Job'), 'cancel_job', ['Pending', "Running"].includes(frm.doc.status)],
].forEach(([label, method, condition]) => {
frm.add_custom_button(
label,
Expand Down
5 changes: 5 additions & 0 deletions press/press/doctype/agent_job/agent_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,11 @@ def fail_and_process_job_updates(self):
def process_job_updates(self):
process_job_updates(self.name)

@frappe.whitelist()
def cancel_job(self):
agent = Agent(self.server, server_type=self.server_type)
agent.cancel_job(self.job_id)

def on_trash(self):
steps = frappe.get_all("Agent Job Step", filters={"agent_job": self.name})
for step in steps:
Expand Down

0 comments on commit f30aff6

Please sign in to comment.