Skip to content

Commit

Permalink
Merge pull request #419 from guidow/fix_pause_job
Browse files Browse the repository at this point in the history
Stop tasks on agents after setting job to paused
  • Loading branch information
opalmer committed Apr 18, 2015
2 parents 2fec33f + d47b677 commit 8f71d6a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions pyfarm/master/user_interface/jobs.py
Expand Up @@ -527,14 +527,14 @@ def pause_single_job(job_id):
"pyfarm/error.html", error="Job %s not found" % job_id),
NOT_FOUND)

for task in job.tasks:
if task.state == WorkState.RUNNING:
stop_task.delay(task.id)

job.state = WorkState.PAUSED
db.session.add(job)
db.session.commit()

for task in job.tasks:
if task.state == WorkState.RUNNING:
stop_task.delay(task.id)

assign_tasks.delay()

flash("Job %s will be paused." % job.title)
Expand All @@ -547,6 +547,7 @@ def pause_single_job(job_id):
def pause_multiple_jobs():
job_ids = request.form.getlist("job_id")

task_ids_to_stop = []
for job_id in job_ids:
job = Job.query.filter_by(id=job_id).first()
if not job:
Expand All @@ -556,13 +557,15 @@ def pause_multiple_jobs():

for task in job.tasks:
if task.state == WorkState.RUNNING:
stop_task.delay(task.id)
task_ids_to_stop.append(task.id)

job.state = WorkState.PAUSED
db.session.add(job)

db.session.commit()

for task_id in task_ids_to_stop:
stop_task.delay(task.id)
assign_tasks.delay()

flash("Selected jobs will be paused.")
Expand Down
2 changes: 1 addition & 1 deletion pyfarm/models/job.py
Expand Up @@ -361,7 +361,7 @@ def update_state(self):
send_job_completion_mail.apply_async(args=[self.id, False],
countdown=5)
db.session.add(self)
else:
elif self.state != _WorkState.PAUSED:
logger.debug("Got at least one active task")
num_running_tasks = db.session.query(Task).\
filter(Task.job == self,
Expand Down

0 comments on commit 8f71d6a

Please sign in to comment.