Is your feature request related to a problem? Please describe.
Exorcist captures a last_modified on any status update. The intent of this was so that a lease system could be implemented on top of Exorcist, where tasks may have a lease time that represents "the task can't take longer than this" and, if a task is marked IN_PROGRESS for longer than that, it is assumed dead, and can get retried.
Currently, the code looks like this:
|
# create a dict of values to update |
|
values = { |
|
'status': status, |
|
'last_modified': datetime.now(), |
|
} |
However, datetime.now() gets the current system clock time. A user could change the time on their machine, and that would affect the lease lifetime. More generally, clock skew is a thing.
Describe the solution you'd like
The datetime.now() approach is convenient for most use cases. For the cases we're expecting, lease times are long enough that normal clock skew probably won't matter, and maybe we can dismiss a user manually changing the time as PEBKAC. So I'm not proposing changing the default behavior. However, I would like to make this behavior easily customizable in subclasses.
So I'd like add a method _get_now(), which defaults to just return datetime.now(). Exposing this would allow subclasses to customize the method by which they obtain the modification time, allowing them to use e.g., network time protocol. Then setting the last_modified would be done with self._get_now(), abstracting out the datetime.now() call.
Describe alternatives you've considered
The alternative is that subclasses that need this functionality would need to completely reimplement the _task_row_update_statement method in order to have a 1-line change.
Additional context
I don't think this has any negative consequences on maintenance here; only positive benefits to downstream users.
Is your feature request related to a problem? Please describe.
Exorcist captures a
last_modifiedon any status update. The intent of this was so that a lease system could be implemented on top of Exorcist, where tasks may have a lease time that represents "the task can't take longer than this" and, if a task is markedIN_PROGRESSfor longer than that, it is assumed dead, and can get retried.Currently, the code looks like this:
exorcist/exorcist/taskdb.py
Lines 423 to 427 in c016700
However,
datetime.now()gets the current system clock time. A user could change the time on their machine, and that would affect the lease lifetime. More generally, clock skew is a thing.Describe the solution you'd like
The
datetime.now()approach is convenient for most use cases. For the cases we're expecting, lease times are long enough that normal clock skew probably won't matter, and maybe we can dismiss a user manually changing the time as PEBKAC. So I'm not proposing changing the default behavior. However, I would like to make this behavior easily customizable in subclasses.So I'd like add a method
_get_now(), which defaults to justreturn datetime.now(). Exposing this would allow subclasses to customize the method by which they obtain the modification time, allowing them to use e.g., network time protocol. Then setting thelast_modifiedwould be done withself._get_now(), abstracting out thedatetime.now()call.Describe alternatives you've considered
The alternative is that subclasses that need this functionality would need to completely reimplement the
_task_row_update_statementmethod in order to have a 1-line change.Additional context
I don't think this has any negative consequences on maintenance here; only positive benefits to downstream users.