Skip to content

Commit

Permalink
Rename
Browse files Browse the repository at this point in the history
  • Loading branch information
acasajus committed Oct 16, 2024
1 parent f03a205 commit 497ed0c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3771,12 +3771,12 @@ class SyncEvent(Base, ModelMixin):
sa.Index("ix_sync_event_taken_time", "taken_time"),
)

def mark_as_taken(self, taken_older_than: Optional[Arrow] = None) -> bool:
def mark_as_taken(self, allow_taken_older_than: Optional[Arrow] = None) -> bool:
taken_condition = ["taken_time IS NULL"]
args = {"taken_time": arrow.now().datetime, "sync_event_id": self.id}
if taken_older_than:
if allow_taken_older_than:
taken_condition.append("taken_time < :taken_older_than")
args["taken_older_than"] = taken_older_than.datetime
args["taken_older_than"] = allow_taken_older_than.datetime
sql_taken_condition = "({})".format(" OR ".join(taken_condition))
sql = f"UPDATE sync_event SET taken_time = :taken_time WHERE id = :sync_event_id AND {sql_taken_condition}"
res = Session.execute(sql, args)
Expand Down
2 changes: 1 addition & 1 deletion events/event_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def execute_loop(
"Custom/dead_letter_events_to_process", len(events)
)
for event in events:
if event.mark_as_taken(taken_older_than=threshold):
if event.mark_as_taken(allow_taken_older_than=threshold):
on_event(event)
return events

Expand Down
4 changes: 2 additions & 2 deletions tests/events/test_sent_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ def test_event_mark_as_taken_does_nothing_for_not_before_events():
now = arrow.utcnow()
event = SyncEvent.create(content="test".encode("utf-8"), taken_time=now, flush=True)
older_than = now.shift(minutes=-1)
assert not event.mark_as_taken(taken_older_than=older_than)
assert not event.mark_as_taken(allow_taken_older_than=older_than)


def test_event_mark_as_taken_works_for_before_events():
now = arrow.utcnow()
event = SyncEvent.create(content="test".encode("utf-8"), taken_time=now, flush=True)
older_than = now.shift(minutes=+1)
assert event.mark_as_taken(taken_older_than=older_than)
assert event.mark_as_taken(allow_taken_older_than=older_than)


def test_fire_event_on_alias_creation():
Expand Down

0 comments on commit 497ed0c

Please sign in to comment.