Skip to content
Snippets Groups Projects
Commit 24cc918c authored by Remi  PLANEL's avatar Remi PLANEL
Browse files

add a scheduled wf invocatin status

parent ad0e49d3
No related branches found
No related tags found
No related merge requests found
Pipeline #107581 passed
# Generated by Django 3.2.20 on 2023-07-19 08:34
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='galaxyworkflowinvocation',
name='status',
field=models.CharField(choices=[('scheduled', 'Scheduled'), ('running', 'Running'), ('paused', 'Paused'), ('error', 'Error'), ('done', 'Done')], default='scheduled', max_length=10),
),
]
...@@ -353,7 +353,8 @@ class GalaxyWorkflow(models.Model): ...@@ -353,7 +353,8 @@ class GalaxyWorkflow(models.Model):
class GalaxyWorkflowInvocation(models.Model): class GalaxyWorkflowInvocation(models.Model):
class WorkflowInvocationStatus(models.TextChoices): class WorkflowInvocationStatus(models.TextChoices):
RUNNING = ("running", "RUNNING") SCHEDULED = ("scheduled", "Scheduled")
RUNNING = ("running", "Running")
PAUSED = ("paused", "Paused") PAUSED = ("paused", "Paused")
ERROR = ("error", "Error") ERROR = ("error", "Error")
DONE = ("done", "Done") DONE = ("done", "Done")
...@@ -367,7 +368,7 @@ class GalaxyWorkflowInvocation(models.Model): ...@@ -367,7 +368,7 @@ class GalaxyWorkflowInvocation(models.Model):
status = models.CharField( status = models.CharField(
max_length=10, max_length=10,
choices=WorkflowInvocationStatus.choices, choices=WorkflowInvocationStatus.choices,
default=WorkflowInvocationStatus.RUNNING, default=WorkflowInvocationStatus.SCHEDULED,
) )
class Meta: class Meta:
...@@ -387,8 +388,11 @@ class GalaxyWorkflowInvocation(models.Model): ...@@ -387,8 +388,11 @@ class GalaxyWorkflowInvocation(models.Model):
workflow_id=self.galaxy_workflow.get_encoded_id(), workflow_id=self.galaxy_workflow.get_encoded_id(),
history_id=self.galaxy_history.get_encoded_id(), history_id=self.galaxy_history.get_encoded_id(),
) )
print(invocations)
if len(invocations) == 1: if len(invocations) == 1:
return invocations[0]["id"] return invocations[0]["id"]
elif len(invocations) == 0:
return None
else: else:
raise Exception(f"Multiple wf invocations for {self.galaxy_workflow}") raise Exception(f"Multiple wf invocations for {self.galaxy_workflow}")
...@@ -401,19 +405,34 @@ class GalaxyWorkflowInvocation(models.Model): ...@@ -401,19 +405,34 @@ class GalaxyWorkflowInvocation(models.Model):
def _get_galaxy_invocation(self): def _get_galaxy_invocation(self):
"""Get galaxy object using bioblend.""" """Get galaxy object using bioblend."""
return self.galaxy_workflow.galaxy_user.bioblend_gi.workflows.show_invocation( workflow_invocation_id = self.get_encoded_id()
workflow_id=self.galaxy_workflow.get_encoded_id(),
invocation_id=self.get_encoded_id(), if workflow_invocation_id is None:
) return None
else:
return (
self.galaxy_workflow.galaxy_user.bioblend_gi.workflows.show_invocation(
workflow_id=self.galaxy_workflow.get_encoded_id(),
invocation_id=workflow_invocation_id,
)
)
@property @property
def percentage_done(self) -> float: def percentage_done(self) -> float:
"""Retrieve percentage of jobs done for the invocation.""" """Retrieve percentage of jobs done for the invocation."""
if self.status == self.WorkflowInvocationStatus.DONE: if self.status == self.WorkflowInvocationStatus.DONE:
return 100.0 return 100.0
step_jobs_summary = self.galaxy_workflow.galaxy_user.bioblend_gi.invocations.get_invocation_step_jobs_summary(
self.get_encoded_id() workflow_invocation_id = self.get_encoded_id()
) if workflow_invocation_id:
step_jobs_summary = self.galaxy_workflow.galaxy_user.bioblend_gi.invocations.get_invocation_step_jobs_summary(
workflow_invocation_id
)
else:
self.status = self.WorkflowInvocationStatus.SCHEDULED
self.save()
return 0
count_states = defaultdict(int) count_states = defaultdict(int)
if len(step_jobs_summary) >= 1: if len(step_jobs_summary) >= 1:
for step in step_jobs_summary: for step in step_jobs_summary:
...@@ -429,8 +448,13 @@ class GalaxyWorkflowInvocation(models.Model): ...@@ -429,8 +448,13 @@ class GalaxyWorkflowInvocation(models.Model):
elif "paused" in count_states.keys(): elif "paused" in count_states.keys():
self.status = self.WorkflowInvocationStatus.PAUSED self.status = self.WorkflowInvocationStatus.PAUSED
self.save() self.save()
else:
self.status = self.WorkflowInvocationStatus.RUNNING
self.save()
return percentage_done * 100 return percentage_done * 100
else: else:
self.status = self.WorkflowInvocationStatus.SCHEDULED
self.save()
return 0 return 0
def synchronize(self): def synchronize(self):
...@@ -442,17 +466,14 @@ class GalaxyWorkflowInvocation(models.Model): ...@@ -442,17 +466,14 @@ class GalaxyWorkflowInvocation(models.Model):
}: }:
return return
galaxy_invocation = self._get_galaxy_invocation() if self.galaxy_invocation is not None:
self.galaxy_state = galaxy_invocation["state"] self.galaxy_state = self.galaxy_invocation["state"]
self.save() self.save()
def get_galaxy_invocation(self): def get_galaxy_invocation(self):
galaxy_user = self.galaxy_workflow.galaxy_user galaxy_user = self.galaxy_workflow.galaxy_user
gi = galaxy_user.bioblend_gi gi = galaxy_user.bioblend_gi
invocation = gi.workflows.show_invocation( invocation = self.galaxy_invocation
workflow_id=self.galaxy_workflow.get_encoded_id(),
invocation_id=self.get_encoded_id(),
)
def job_detail(steps): def job_detail(steps):
param_keys_to_remove = { param_keys_to_remove = {
...@@ -460,48 +481,56 @@ class GalaxyWorkflowInvocation(models.Model): ...@@ -460,48 +481,56 @@ class GalaxyWorkflowInvocation(models.Model):
"chromInfo", "chromInfo",
"dbkey", "dbkey",
} }
for step in invocation["steps"]: if invocation is not None:
if step["job_id"] is not None: for step in invocation["steps"]:
job = gi.jobs.show_job(step["job_id"], full_details=True) if step["job_id"] is not None:
tool = gi.tools.show_tool(job["tool_id"], io_details=True) job = gi.jobs.show_job(step["job_id"], full_details=True)
metrics = job["job_metrics"] if "job_metrics" in job else [] tool = gi.tools.show_tool(job["tool_id"], io_details=True)
yield ( metrics = job["job_metrics"] if "job_metrics" in job else []
{ yield (
"order_index": step["order_index"], {
"job_id": step["job_id"], "order_index": step["order_index"],
"step_id": step["order_index"], "job_id": step["job_id"],
"tool": tool, "step_id": step["order_index"],
"job": { "tool": tool,
"create_time": job["create_time"], "job": {
"update_time": job["update_time"], "create_time": job["create_time"],
"metrics": metrics, "update_time": job["update_time"],
"state": job["state"], "metrics": metrics,
"params": dict( "state": job["state"],
[ "params": dict(
(key, json.loads(param)) [
for (key, param) in job["params"].items() (key, json.loads(param))
if key not in param_keys_to_remove for (key, param) in job["params"].items()
] if key not in param_keys_to_remove
), ]
}, ),
} },
) }
)
return {
"invocation": invocation, if invocation is not None:
"steps": list(job_detail(invocation["steps"])), return {
} "invocation": invocation,
"steps": list(job_detail(invocation["steps"])),
}
else:
return None
def get_workflow_job_parameters(self): def get_workflow_job_parameters(self):
invocation = self.get_galaxy_invocation() invocation = self.get_galaxy_invocation()
def job_detail(steps): def job_detail(steps):
for step in invocation["steps"]: if invocation is not None:
if step["job"]["params"] is not None: for step in invocation["steps"]:
# job = gi.jobs.show_job(step["job_id"]) if step["job"]["params"] is not None:
yield (step["order_index"], step["job"]["params"]) # job = gi.jobs.show_job(step["job_id"])
yield (step["order_index"], step["job"]["params"])
return dict(job_detail(invocation["steps"]))
if invocation is not None:
return dict(job_detail(invocation["steps"]))
else:
return None
class GalaxyDataset(models.Model): class GalaxyDataset(models.Model):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment