tracker#

This module implements the last operational time tracker and concurrency locker mechanism.

exception sayt.tracker.TrackerIsLockedError[source]#
class sayt.tracker.Tracker(path: Path, start: Optional[str] = None, end: Optional[str] = None, locked: Optional[bool] = None, expire: Optional[str] = None)[source]#

Usage:

# suppose you have many worker may work on the same job # this is the code for first worker # before it run the job, it checks if it is locked # and moves forward only if it is not locked # wrap the work logic in a try finally and unlock it anyway >>> tracker = Tracker.new(“/path/to/tracker.json”) >>> if tracker.is_locked() is False: … tracker.lock_it(expire=10) … try: … # do something … finally: … tracker.unlock_it()

# this is the code for other workers attempt to work on the same job >>> tracker = Tracker.new(“/path/to/tracker.json”) # it will return True, so the second worker won’t do anything >>> if tracker.is_locked() is False: >>> …

Parameters:
  • path – path to the local tracker json file.

  • start – work start datetime in ISO format, also the lock time.

  • end – work end datetime in ISO format.

  • locked – boolean value to indicate whether it is locked, if it is True, it doesn’t mean that it is locked, you also have to check the expire time

  • expire – the lock expire datetime in ISO format.