Skip to content

Commit

Permalink
Further change the task GUI to have buttons for task ids #154
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo Peng committed Dec 7, 2018
1 parent 5fe5a33 commit d24ee83
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 70 deletions.
88 changes: 37 additions & 51 deletions src/sos_notebook/kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ define([
cell.output_area.append_output(data);
}
return;
}
}
// if there is an existing status table, try to retrieve its information
// the new data does not have it
let timer_text = '';
Expand All @@ -672,16 +672,6 @@ define([
}
}

let action_class = {
'pending': 'fa-stop',
'submitted': 'fa-stop',
'running': 'fa-stop',
'completed': 'fa-play',
'failed': 'fa-play',
'aborted': 'fa-play',
'missing': 'fa-question',
}

let status_class = {
'pending': 'fa-square-o',
'submitted': 'fa-spinner',
Expand All @@ -692,20 +682,15 @@ define([
'missing': 'fa-question',
}

let action_func = {
'pending': 'kill',
'submitted': 'kill',
'running': 'kill',
'completed': 'resume',
'failed': 'resume',
'aborted': 'resume',
'missing': '',
}

// look for status etc and update them.
let onmouseover = `onmouseover="this.classList='fa fa-2x fa-fw ${action_class[info.status]}'"`;
let onmouseleave = `onmouseleave="this.classList='fa fa-2x fa-fw ${status_class[info.status]}'"`;
let onclick = `onclick="task_action({action: '${action_func[info.status]}', task: '${info.task_id}', queue:'${info.queue}'});"`;
let id_elems = `<pre>${info.task_id}` +
`<div class="task_id_actions">` +
`<i class="fa fa-fw fa-refresh" onclick="task_action({action:'status', task:'${info.task_id}', queue: '${info.queue}'})"></i>` +
`<i class="fa fa-fw fa-play" onclick="task_action({action:'execute', task:'${info.task_id}', queue: '${info.queue}'})"></i>` +
`<i class="fa fa-fw fa-stop"" onclick="task_action({action:'kill', task:'${info.task_id}', queue: '${info.queue}'})"></i>` +
`<i class="fa fa-fw fa-trash"" onclick="task_action({action:'purge', task:'${info.task_id}', queue: '${info.queue}'})"></i>` +
`</div></pre>`;

let tags = info.tags.split(/\s+/g);
let tags_elems = ''
for (let ti=0; ti < tags.length; ++ti) {
Expand All @@ -730,13 +715,10 @@ define([
<table id="task_${elem_id}" class="task_table ${info.status}">
<tr>
<td class="task_icon">
<i id="task_status_icon_${elem_id}" class="fa fa-2x fa-fw ${status_class[info.status]}"
${onmouseover} ${onmouseleave} ${onclick}></i>
<i id="task_status_icon_${elem_id}" class="fa fa-2x fa-fw ${status_class[info.status]}"</i>
</td>
<td class="task_id">
<div onclick="task_action({action:'status', task:'${info.task_id}', queue:'${info.queue}'})">
<pre><i class="fa fa-fw fa-sitemap"></i>${info.task_id}</pre>
</div>
<span><pre><i class="fa fa-fw fa-sitemap"></i></pre>${id_elems}</span>
</td>
<td class="task_tags">
<span id="status_tags_${elem_id}"><pre><i class="fa fa-fw fa-info-circle"></i></pre>${tags_elems}</span>
Expand Down Expand Up @@ -2023,18 +2005,6 @@ table.task_table {
border: 0px;
}
.task_tag_actions {
display: none;
}
.task_tag_actions .fa:hover {
color: blue;
}
.task_tags:hover .task_tag_actions {
display: flex;
flex-direction: row;
}
table.workflow_table i,
table.task_table i {
Expand All @@ -2059,6 +2029,18 @@ td.task_id
text-align: left;
}
td.task_tags
{
text-align: left;
max-width: 33em;
}
td.task_id
{
text-align: left;
}
td.task_id span,
td.task_tags span {
display: inline-flex;
}
Expand All @@ -2071,10 +2053,20 @@ td.task_tags i {
margin-right: 0px;
}
.task_id pre:hover
{
cursor: pointer;
text-decoration: underline;
.task_id_actions,
.task_tag_actions {
display: none;
}
.task_id_actions .fa:hover,
.task_tag_actions .fa:hover {
color: blue;
}
.task_id:hover .task_id_actions,
.task_tags:hover .task_tag_actions {
display: flex;
flex-direction: row;
}
td.workflow_index
Expand Down Expand Up @@ -2103,12 +2095,6 @@ td.task_timer pre
}
td.task_tags
{
text-align: left;
max-width: 33em;
}
td.task_icon {
font-size: 0.75em;
}
Expand Down
10 changes: 0 additions & 10 deletions src/sos_notebook/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,16 +502,6 @@ def handle_frontend_msg(msg):
elif k == 'execute-workflow':
from .workflow_executor import execute_pending_workflow
execute_pending_workflow(v, self)
elif k == 'resume-task':
# kill specified task
from sos.hosts import Host
Host(v[1])._task_engine.resume_task(v[0])
self.send_frontend_msg('task_status',
{
'task_id': v[0],
'queue': v[1],
'status': 'pending'
})
elif k == 'update-task-status':
if not isinstance(v, list):
continue
Expand Down
34 changes: 25 additions & 9 deletions src/sos_notebook/magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1933,20 +1933,25 @@ def get_parser(self):
help=argparse.SUPPRESS)
status.set_defaults(func=self.status)

resume = subparsers.add_parser('resume', help='task status')
resume.add_argument('tasks', nargs='*', help='''ID of the tasks to be removed.
execute = subparsers.add_parser('execute', help='execute task')
execute.add_argument('tasks', nargs='*', help='''ID of the tasks to be removed.
There is no need to specify compelete task IDs because SoS will match specified
name with tasks starting with these names. If no task ID is specified,
all tasks related to specified workflows (option -w) will be removed.''')
resume.add_argument('-q', '--queue',
execute.add_argument('-q', '--queue',
help='''Remove tasks on specified tasks queue or remote host
if the tasks . The queue can be defined in global or local sos
configuration file, or a file specified by option --config. A host is
assumed to be a remote machine with process type if no configuration
is found. ''')
resume.set_defaults(func=self.resume)
execute.add_argument('-c', '--config', help='''A configuration file with host
definitions, in case the definitions are not defined in global sos config.yml files.''')
execute.add_argument('-v', dest='verbosity', type=int, choices=range(5), default=2,
help='''Output error (0), warning (1), info (2), debug (3) and trace (4)
information to standard output (default to 2).''')
execute.set_defaults(func=self.execute)

kill = subparsers.add_parser('kill', help='task status')
kill = subparsers.add_parser('kill', help='kill single task or tasks with the same tags')
kill.add_argument('tasks', nargs='*', help='''IDs of the tasks
that will be killed. There is no need to specify compelete task IDs because
SoS will match specified name with tasks starting with these names.''')
Expand All @@ -1967,7 +1972,7 @@ def get_parser(self):
information to standard output (default to 2).''')
kill.set_defaults(func=self.kill)

purge = subparsers.add_parser('purge', help='task status')
purge = subparsers.add_parser('purge', help='kill and purge task')
purge.add_argument('tasks', nargs='*', help='''ID of the tasks to be removed.
There is no need to specify compelete task IDs because SoS will match specified
name with tasks starting with these names. If no task ID is specified,
Expand Down Expand Up @@ -2051,9 +2056,20 @@ def status(self, args):
env.logger.warning(
f'Unrecognized response "{line}" ({e.__class__.__name__}): {e}')

def resume(self, args):
self.sos_kernel.warn(args)
return
def execute(self, args):
from sos.hosts import Host
host = Host(args.queue)

for task in args.tasks:
result = host._task_engine.submit_task(task)
self.sos_kernel.send_frontend_msg('task_status',
{
'update_only': True,
'queue': args.queue,
'task_id': task,
'status': 'pening',
}
)

def kill(self, args):
# kill specified task
Expand Down

0 comments on commit d24ee83

Please sign in to comment.