Skip to content

Commit

Permalink
capture exit code (#37)
Browse files Browse the repository at this point in the history
* capture exit code

more attempts at getting timeout test failure reason
bump version

* update page title
  • Loading branch information
aclowes authored May 29, 2018
1 parent e808736 commit ed2680f
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion frontend/src/TaskDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class TaskDetail extends React.Component {
API.get(`/api/tasks/${this.props.params.id}/`, (payload, error) => {
let execution = null;
if (payload) {
document.title = `YAWN - Task ${payload.name}`;
document.title = `YAWN - Task: ${payload.name}`;
// keep the currently selected execution, or get the latest
execution = this.state.execution || payload.executions.length;

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/UserDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class UserDetail extends React.Component {
} else {
API.get(`/api/users/${this.props.params.id}/`, (payload, error) => {
if (payload) {
document.title = `YAWN - User ${payload.username}`;
document.title = `YAWN - User: ${payload.username}`;
}
this.setState({user: payload, error});
});
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/WorkerDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class WorkerDetail extends React.Component {
this.setState({worker: payload, error});

if (payload) { // only get if worker returns... not strictly necessary
document.title = `YAWN - Worker ${payload.name}`;
document.title = `YAWN - Worker: ${payload.name}`;
API.get(`/api/executions/?worker=${this.props.params.id}`, (payload, error) => {
this.setState({executions: payload, error});
});
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/WorkerList.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default class WorkerList extends React.Component {
if (this.state.workers === null) {
return (
<tr>
<td colSpan="3">Loading...</td>
<td colSpan="4">Loading...</td>
</tr>
)
} else {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/WorkflowDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class WorkflowDetail extends React.Component {
loadWorkflow(version) {
API.get(`/api/workflows/${version}/`, (payload, error) => {
if (payload) {
document.title = `YAWN - Workflow ${payload.name}`;
document.title = `YAWN - Workflow: ${payload.name}`;
}
this.setState({workflow: payload, error});
});
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/tests/__snapshots__/WorkerList.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ exports[`WorkerList failure 1`] = `
<tbody>
<tr>
<td
colSpan="3"
colSpan="4"
>
Loading...
</td>
Expand Down Expand Up @@ -70,7 +70,7 @@ exports[`WorkerList loading 1`] = `
<tbody>
<tr>
<td
colSpan="3"
colSpan="4"
>
Loading...
</td>
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='0.2.1',
version='0.2.2',

description='Yet Another Workflow Engine, a subprocess-based DAG execution system',
long_description=long_description,
Expand Down
3 changes: 2 additions & 1 deletion yawn/task/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,6 @@ def mark_finished(self, exit_code=None, lost=False):
self.task.run.update_status()

self.stop_timestamp = functions.Now()
self.exit_code = exit_code
# need to be careful not to overwrite stdout/stderr
self.save(update_fields=['status', 'stop_timestamp'])
self.save(update_fields=['status', 'stop_timestamp', 'exit_code'])
15 changes: 6 additions & 9 deletions yawn/worker/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, execution_id):

def __str__(self):
return 'Result(id={}, stdout={}, stderr={}, returncode={})'.format(
self.execution_id, bool(self.stdout), bool(self.stderr), self.returncode)
self.execution_id, self.stdout, self.stderr, self.returncode)


class Execution:
Expand All @@ -39,7 +39,7 @@ def __init__(self, process, execution_id, timeout):

def __str__(self):
return 'Result(id={}, stdout={}, stderr={}, returncode={})'.format(
self.id, bool(self.process.stdout), bool(self.process.stderr), self.process.returncode)
self.id, self.process.stdout, self.process.stderr, self.process.returncode)


class Manager:
Expand Down Expand Up @@ -71,8 +71,6 @@ def start_subprocess(self, execution_id: int, command: str, environment: dict, t
# all variables must be strings, be explicit so it fail in our code
process_environment[key] = str(value)

logger.info('Starting execution #%s', execution_id)

process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
preexec_fn=os.setpgrp, env=process_environment, shell=True)

Expand Down Expand Up @@ -155,14 +153,13 @@ def read_output(self, timeout=0.1) -> typing.List[Result]:
continue # we'll check again later

# we may not have read everything available, so only cleanup after all pipes are closed
open_pipes = {execution.process.stdout.raw, execution.process.stderr.raw
} & set(self.pipes.keys())
open_pipes = (
{execution.process.stdout.raw, execution.process.stderr.raw}
& set(self.pipes.keys())
)
if not open_pipes:
result = all_results.setdefault(execution.id, Result(execution.id))
result.returncode = execution.process.returncode
run_time = time.monotonic() - execution.start_time
logger.info('Execution #%s exited with code %s after %s seconds',
execution.id, result.returncode, run_time)
del self.running[execution.id]

return list(all_results.values())
Expand Down
2 changes: 1 addition & 1 deletion yawn/worker/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class State(enum.Enum):


class Main:
results = None # type: typing.List[Result]
results = None # type: typing.Deque[Result]
executor = None
state = State.stopped
worker = None
Expand Down

0 comments on commit ed2680f

Please sign in to comment.