Commit 42a86ff1 authored by Jerome Mariette's avatar Jerome Mariette

No commit message

No commit message
parent bc60db1f
......@@ -28,6 +28,7 @@ except ImportError:
sys.exc_clear()
from jflow.workflows_manager import WorkflowsManager
from jflow.workflow import Workflow
import jflow.utils as utils
from cctools.util import time_format
......@@ -50,7 +51,8 @@ class JFlowServer (object):
else: return json.dumps(value)
return wrapper
def jsonify_workflow_status(self, workflow):
def jsonify_workflow_status(self, workflow, init_to_zero=False):
if workflow.start_time: start_time = time.asctime(time.localtime(workflow.start_time))
else: start_time = "-"
if workflow.start_time and workflow.end_time: elapsed_time = str(workflow.end_time-workflow.start_time)
......@@ -58,36 +60,45 @@ class JFlowServer (object):
else: elapsed_time = "-"
if workflow.end_time: end_time = time.asctime(time.localtime(workflow.end_time))
else: end_time = "-"
components = []
for i, component in enumerate(workflow.get_components_nameid()):
status_info = workflow.get_component_status(component)
try: perc_waiting = (status_info["waiting"]*100.0)/status_info["tasks"]
except: perc_waiting = 0
try: perc_running = (status_info["running"]*100.0)/status_info["tasks"]
except: perc_running = 0
try: perc_failed = (status_info["failed"]*100.0)/status_info["tasks"]
except: perc_failed = 0
try: perc_aborted = (status_info["aborted"]*100.0)/status_info["tasks"]
except: perc_aborted = 0
try: perc_completed = (status_info["completed"]*100.0)/status_info["tasks"]
except: perc_completed = 0
components.append({"name": component,
"elapsed_time": time_format(status_info["time"]),
"total": status_info["tasks"],
"waiting": status_info["waiting"],
"failed": status_info["failed"],
"running": status_info["running"],
"aborted": status_info["aborted"],
"completed": status_info["completed"]})
status = {"id":utils.get_nb_string(workflow.id),
"name": workflow.name,
"status": workflow.get_status(),
"elapsed_time": str(elapsed_time),
"start_time": start_time,
"end_time": end_time,
"components": components}
return status
if init_to_zero:
return {"id":utils.get_nb_string(workflow.id),
"name": workflow.name,
"status": Workflow.STATUS_STARTED,
"elapsed_time": str(elapsed_time),
"start_time": start_time,
"end_time": end_time,
"components": []}
else :
components = []
for i, component in enumerate(workflow.get_components_nameid()):
status_info = workflow.get_component_status(component)
try: perc_waiting = (status_info["waiting"]*100.0)/status_info["tasks"]
except: perc_waiting = 0
try: perc_running = (status_info["running"]*100.0)/status_info["tasks"]
except: perc_running = 0
try: perc_failed = (status_info["failed"]*100.0)/status_info["tasks"]
except: perc_failed = 0
try: perc_aborted = (status_info["aborted"]*100.0)/status_info["tasks"]
except: perc_aborted = 0
try: perc_completed = (status_info["completed"]*100.0)/status_info["tasks"]
except: perc_completed = 0
components.append({"name": component,
"elapsed_time": time_format(status_info["time"]),
"total": status_info["tasks"],
"waiting": status_info["waiting"],
"failed": status_info["failed"],
"running": status_info["running"],
"aborted": status_info["aborted"],
"completed": status_info["completed"]})
status = {"id":utils.get_nb_string(workflow.id),
"name": workflow.name,
"status": workflow.get_status(),
"elapsed_time": str(elapsed_time),
"start_time": start_time,
"end_time": end_time,
"components": components}
return status
def extend_parameters(self, workflow_class, kwargs):
extended_kwargs = {}
......@@ -132,7 +143,7 @@ class JFlowServer (object):
def run_workflow(self, **kwargs):
args = self.extend_parameters(kwargs["workflow_class"], kwargs)
workflow = self.wfmanager.run_workflow(kwargs["workflow_class"], args)
return self.jsonify_workflow_status(workflow)
return self.jsonify_workflow_status(workflow, True)
@cherrypy.expose
@jsonify
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment