Skip to content

stop converting time to utc for FileLock. fixes #71 #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions sherlock/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ def _expiry_time(self, lease: kubernetes.client.V1Lease) -> datetime.datetime:
seconds=lease.spec.lease_duration_seconds
)
elif lease.spec.lease_duration_seconds is None:
expiry_time = datetime.datetime.max
expiry_time = datetime.datetime.max.replace(tzinfo=datetime.timezone.utc)
return expiry_time.astimezone(tz=datetime.timezone.utc)

def _has_expired(
Expand Down Expand Up @@ -1157,17 +1157,17 @@ def _key_name(self):
return key

def _now(self) -> datetime.datetime:
return datetime.datetime.now(tz=datetime.timezone.utc)
return datetime.datetime.now()

def _expiry_time(self) -> str:
expiry_time = datetime.datetime.max.astimezone(datetime.timezone.utc)
expiry_time = datetime.datetime.max
if self.expire is not None:
expiry_time = self._now() + datetime.timedelta(seconds=self.expire)
return expiry_time.isoformat()

def _has_expired(self, data: dict, now: datetime.datetime) -> bool:
expiry_time = datetime.datetime.fromisoformat(data["expiry_time"])
return now > expiry_time.astimezone(tz=datetime.timezone.utc)
return now > expiry_time

def _acquire(self) -> bool:
owner = str(uuid.uuid4())
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ def test_acquire_check_expire_is_not_set(self):
file = self._load_file(self.lock_name)
self.assertEqual(
file["expiry_time"],
datetime.datetime.max.astimezone(datetime.timezone.utc).isoformat(),
datetime.datetime.max.isoformat(),
)
self.assertTrue(lock.locked())

Expand Down