Skip to content
Snippets Groups Projects
Commit 3223d661 authored by André Anjos's avatar André Anjos :speech_balloon:
Browse files

[experiments] Small fixes

parent 3628ff37
No related branches found
No related tags found
1 merge request!194Scheduler
......@@ -601,8 +601,8 @@ class Experiment(Shareable):
def job_splits(self, status=None):
from ..backend.models import JobSplit
retval = JobSplit.objects.filter(job__block__in=self.blocks)
if state is not None:
retval = JobSplit.objects.filter(job__block__in=self.blocks.all())
if status is not None:
retval = retval.filter(status=status)
return retval
......@@ -642,6 +642,9 @@ class Experiment(Shareable):
),
)
def get_admin_change_url(self):
return reverse('admin:experiments_experiment_change', args=(self.id,))
def completion(self):
if self.start_date is None:
return 0
......@@ -744,18 +747,18 @@ class Experiment(Shareable):
# Process main state and state from job results
if Block.FAILED in block_statuses or Block.CANCELLED in block_statuses:
self.state = Experiment.FAILED
self.status = Experiment.FAILED
elif (Block.PROCESSING in block_statuses) or \
((Block.NOT_CACHED in block_statuses or \
Block.SKIPPED in block_states) and Block.CACHED in block_statuses):
self.state = Experiment.RUNNING
self.status = Experiment.RUNNING
elif Block.NOT_CACHED not in block_statuses:
self.state = Experiment.DONE
self.status = Experiment.DONE
else:
self.state = Experiment.SCHEDULED
self.status = Experiment.SCHEDULED
self.save()
......@@ -776,7 +779,7 @@ class Experiment(Shareable):
'''
# lock self - avoids concurrent update from scheduler/worker subsystem
Experiment.objects.select_for_update(pk=self.pk)
Experiment.objects.select_for_update().filter(pk=self.pk)
if self.status != Experiment.PENDING: return
......@@ -797,9 +800,9 @@ class Experiment(Shareable):
'''
# lock self - avoids concurrent update from scheduler/worker subsystem
Experiment.objects.select_for_update(pk=self.pk)
Experiment.objects.select_for_update().filter(pk=self.pk)
if self.status != (Experiment.SCHEDULED, Experiment.RUNNING): return
if self.status not in (Experiment.SCHEDULED, Experiment.RUNNING): return
for b in self.blocks.all(): b._cancel()
......@@ -955,7 +958,7 @@ class Block(models.Model):
'''
# lock self - avoids concurrent update from scheduler/worker subsystem
Block.objects.select_for_update(pk=self.pk)
Block.objects.select_for_update().filter(pk=self.pk)
if self.status != Block.NOT_CACHED: return
......@@ -976,7 +979,7 @@ class Block(models.Model):
def done(self):
'''Says whether the block has finished or not'''
return self.state not in (Block.NOT_CACHED, Block.PROCESSING)
return self.status not in (Block.NOT_CACHED, Block.PROCESSING)
@transaction.atomic
......@@ -987,11 +990,15 @@ class Block(models.Model):
'''
# lock self - avoids concurrent update from scheduler/worker subsystem
Block.objects.select_for_update(pk=self.pk)
Block.objects.select_for_update().filter(pk=self.pk)
if self.done(): return
self.job._cancel()
if hasattr(self, 'job'): self.job._cancel()
else:
self.status = Block.CANCELLED
self.save()
self.experiment.update_state()
@transaction.atomic
......@@ -1016,7 +1023,7 @@ class Block(models.Model):
'''
# lock self - avoids concurrent update from scheduler/worker subsystem
Block.objects.select_for_update(pk=self.pk)
Block.objects.select_for_update().filter(pk=self.pk)
if self.job.result and timings:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment