Skip to content

Commit

Permalink
Merge pull request #248 from bioinformatics-ua/bug/running-tasks-no-s…
Browse files Browse the repository at this point in the history
…top-fail

Resolve cancellation issue on running tasks service
  • Loading branch information
bastiao authored Sep 29, 2016
2 parents 6a916df + 9d839b3 commit 479ad9d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {

resp.setContentType("application/json");
try {
resp.getWriter().write(RunningIndexTasks.getInstance().toJson());
} catch (InterruptedException | ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
resp.getWriter().write(RunningIndexTasks.getInstance().toJson());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class TaskStatus extends React.Component {
item: PropTypes.shape({
taskUid: PropTypes.string.isRequired,
complete: PropTypes.bool,
canceled: PropTypes.bool,
taskProgress: PropTypes.number,
elapsedTime: PropTypes.number,
nIndexed: PropTypes.number,
Expand All @@ -23,9 +24,9 @@ class TaskStatus extends React.Component {

render() {
const {item, onCloseStopClicked} = this.props;
const {complete} = item;
const {complete, canceled} = item;
const unknownPercentage = (typeof item.taskProgress !== 'number' || item.taskProgress < 0);
const percentage = (complete || unknownPercentage) ? '100%'
const percentage = (complete || canceled || unknownPercentage) ? '100%'
: (Math.round(item.taskProgress * 100) + '%');

let barstate = "indexprogress progress-bar progress-bar-striped";
Expand All @@ -37,24 +38,30 @@ class TaskStatus extends React.Component {
barstate += " progress-bar-info active";
} else {
barstate += " progress-bar-success";
if (!complete) {
if (!complete && !canceled) {
barstate += " active";
}
}
const barStyle = {
width: percentage
};
if (canceled) {
barStyle.backgroundColor = '#CCCCCC';
}

return (
<div key={item.taskUid} className="well well-sm">
<div className="row">
<div className="col-sm-10">
<div className="progress indexstatusprogress">
<div style={{width: percentage}} className={barstate} role="progressbar" aria-valuemin="0" aria-valuemax="100">
{!unknownPercentage && percentage}
<div style={barStyle} className={barstate} role="progressbar" aria-valuemin="0" aria-valuemax="100">
{canceled ? 'canceled' : (!unknownPercentage && percentage)}
</div>
</div>
</div>
<div className="col-sm-2">
<button className="btn btn-danger" onClick={onCloseStopClicked}>
{complete ? "Close" : "Stop"}
{(complete || canceled) ? "Close" : "Stop"}
</button>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,10 @@ public boolean removeTask(String taskUid) {

public boolean stopTask(String taskUid) {
Task<Report> task = taskRunningList.get(taskUid);
if (task != null)
{
boolean canceled = task.cancel(true);
if(canceled)
{
//removeTask(taskUid);
return true;
}
}
else {
logger.warn("Attempt to stop unexistent task {}, ignoring", taskUid);
if (task != null) {
return task.cancel(true);
} else {
logger.info("Attempt to stop unexistent task {}, ignoring", taskUid);
}

return false;
Expand All @@ -86,22 +79,20 @@ public Map<String, Task<Report>> getRunningTasks() {
return taskRunningList;
}

public String toJson() throws InterruptedException, ExecutionException {
JSONObject object = new JSONObject();
JSONArray array = new JSONArray();
public String toJson() {
JSONObject object = new JSONObject();
JSONArray array = new JSONArray();

Iterator<Map.Entry<String, Task<Report>>> it = taskRunningList.entrySet().iterator();
int countComplete = 0;
int countCancelled = 0;
while (it.hasNext()) {
Map.Entry<String, Task<Report>> pair = it.next();
Task<Report> task = pair.getValue();
for (Map.Entry<String, Task<Report>> pair : taskRunningList.entrySet()) {
Task<Report> task = pair.getValue();
JSONObject entry = new JSONObject();
entry.put("taskUid", pair.getKey());
entry.put("taskName", task.getName());
entry.put("taskProgress", task.getProgress());
if (task.isDone()) {
entry.put("taskUid", pair.getKey());
entry.put("taskName", task.getName());
entry.put("taskProgress", task.getProgress());

if (task.isDone() && !task.isCancelled()) {
entry.put("complete", true);
countComplete += 1;
try {
Expand All @@ -117,14 +108,13 @@ public String toJson() throws InterruptedException, ExecutionException {
}
if (task.isCancelled()) {
countCancelled += 1;
entry.put("canceled", true);
}
array.add(entry);
}
array.add(entry);
}

object.put("results", array);
object.put("count", array.size() - countComplete - countCancelled);

return object.toString();

}
object.put("count", array.size() - countComplete - countCancelled);
return object.toString();
}
}

0 comments on commit 479ad9d

Please sign in to comment.