| 96 | return f"<{self.__class__.__name__}: {self.id!r}>" |
| 97 | |
| 98 | def _create_lock(self, *, exclusive=None, update_last_refresh=False): |
| 99 | assert exclusive is not None |
| 100 | now = datetime.datetime.now(datetime.timezone.utc) |
| 101 | timestamp = now.isoformat(timespec="milliseconds") |
| 102 | lock = dict(exclusive=exclusive, hostid=self.id[0], processid=self.id[1], threadid=self.id[2], time=timestamp) |
| 103 | value = json.dumps(lock).encode("utf-8") |
| 104 | key = xxh64(value).hexdigest() |
| 105 | logger.debug(f"LOCK-CREATE: creating lock in store. key: {key}, lock: {lock}.") |
| 106 | self.store.store(f"locks/{key}", value) |
| 107 | if update_last_refresh: |
| 108 | # we parse the timestamp string to get *precisely* the datetime in the lock: |
| 109 | self.last_refresh_dt = datetime.datetime.fromisoformat(timestamp) |
| 110 | return key |
| 111 | |
| 112 | def _delete_lock(self, key, *, ignore_not_found=False, update_last_refresh=False): |
| 113 | logger.debug(f"LOCK-DELETE: deleting lock from store. key: {key}.") |