Skip to content
Snippets Groups Projects
Commit efec99a5 authored by Flavio TARSETTI's avatar Flavio TARSETTI
Browse files

Merge branch 'improve_block_state_change' into '1.4.x'

Improve block state change

See merge request !253
parents a2b8fca4 0332a1c2
No related branches found
No related tags found
2 merge requests!2551.4.x,!253Improve block state change
Pipeline #24561 passed
...@@ -712,9 +712,7 @@ def update_job(job): ...@@ -712,9 +712,7 @@ def update_job(job):
cached_file.update(Block.FAILED) cached_file.update(Block.FAILED)
# Update the block # Update the block
job.block.status = Block.FAILED job.block.set_failed(job.end_date)
job.block.end_date = job.end_date
job.block.save()
# Cancel all the remaining blocks of the experiment # Cancel all the remaining blocks of the experiment
splits_to_cancel.extend(cancel_all_blocks(job.block.experiment)) splits_to_cancel.extend(cancel_all_blocks(job.block.experiment))
...@@ -728,9 +726,7 @@ def update_job(job): ...@@ -728,9 +726,7 @@ def update_job(job):
mirror_job.end_date = job.end_date mirror_job.end_date = job.end_date
mirror_job.save() mirror_job.save()
mirror_job.block.status = Block.FAILED mirror_job.block.set_failed(job.end_date)
mirror_job.block.end_date = job.end_date
mirror_job.block.save()
# Cancel all the remaining blocks of the experiment # Cancel all the remaining blocks of the experiment
splits_to_cancel.extend(cancel_all_blocks(mirror_job.block.experiment)) splits_to_cancel.extend(cancel_all_blocks(mirror_job.block.experiment))
...@@ -795,9 +791,7 @@ def update_job(job): ...@@ -795,9 +791,7 @@ def update_job(job):
cached_file.update(Block.CANCELLED) cached_file.update(Block.CANCELLED)
# Update the block # Update the block
job.block.status = Block.CANCELLED job.block.set_canceled(job.end_date)
job.block.end_date = job.end_date
job.block.save()
# Update the experiment # Update the experiment
update_experiment(job.block.experiment) update_experiment(job.block.experiment)
...@@ -874,12 +868,7 @@ def cancel_all_blocks(experiment): ...@@ -874,12 +868,7 @@ def cancel_all_blocks(experiment):
# (If possible) Mark the block as cancelled # (If possible) Mark the block as cancelled
if block.job.splits.filter(status=JobSplit.CANCELLING).count() == 0: if block.job.splits.filter(status=JobSplit.CANCELLING).count() == 0:
block.status = Block.CANCELLED block.set_canceled()
block.end_date = datetime.now()
if block.start_date is None:
block.start_date = block.end_date
block.save()
block.job.delete() block.job.delete()
...@@ -888,15 +877,9 @@ def cancel_all_blocks(experiment): ...@@ -888,15 +877,9 @@ def cancel_all_blocks(experiment):
.filter(job__mirror=True) .filter(job__mirror=True)
for block in mirror_blocks_to_cancel: for block in mirror_blocks_to_cancel:
block.status = Block.CANCELLED block.set_canceled()
block.end_date = datetime.now()
if block.start_date is None:
block.start_date = block.end_date
block.save()
block.job.delete() block.job.delete()
return splits_to_cancel return splits_to_cancel
......
...@@ -248,3 +248,36 @@ class Block(models.Model): ...@@ -248,3 +248,36 @@ class Block(models.Model):
def is_runnable(self): def is_runnable(self):
'''Checks if a block is runnable presently''' '''Checks if a block is runnable presently'''
return all([ k.status == Block.DONE for k in self.dependencies.all() ]) return all([ k.status == Block.DONE for k in self.dependencies.all() ])
def set_canceled(self, end_date=None):
"""Update the block state to canceled
Parameters:
end_date (datetime): If provided sets the end_date otherwise
datetime.now() will be used.
"""
self.status = Block.CANCELLED
if end_date is None:
end_date = datetime.now()
self.end_date = end_date
if self.start_date is None:
self.start_date = self.end_date
self.save()
def set_failed(self, end_date):
"""Update the block state to failed
Parameters:
end_date (datetime): end date on failure
"""
self.status = Block.FAILED
self.end_date = end_date
self.save()
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