Commit ac559ecd authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[experiments][models][blocks] Add helper for canceling and failure

parent a2b8fca4
......@@ -248,3 +248,36 @@ class Block(models.Model):
def is_runnable(self):
'''Checks if a block is runnable presently'''
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()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment