Skip to content

Provide TaskStatusDB._get_now() method #43

Description

@dwhswenson

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:

exorcist/exorcist/taskdb.py

Lines 423 to 427 in c016700

# 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions