Skip to content

Commit

Permalink
Fixed last digest getting logic
Browse files Browse the repository at this point in the history
  • Loading branch information
G L committed Jul 28, 2024
1 parent fcf53c2 commit 46ca121
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
28 changes: 21 additions & 7 deletions echopages/infrastructure/delivery/samplers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,31 @@ def sample(
if len(contents) == 0:
raise ValueError("No content units available")

# TODO: Indices are not a direct match to IDs, neither for digests nor for contents.

# Start sampling from the last content sent
if len(digests) == 0:
content_sampler_index = -1
else:
last_sent_content_id = max(digests[-1].content_ids)
content_sampler_index = [content.id for content in contents].index(
last_sent_content_id
)
print()
# Get digest with the last content sent
previously_sent_digests = [
digest for digest in digests if digest.sent_at is not None
]
if len(previously_sent_digests) == 0:
last_digest = digests[-1]
else:
digest_timestamps = [
digest.sent_at
for digest in previously_sent_digests
if digest.sent_at is not None
]
last_digest_index = digest_timestamps.index(max(digest_timestamps))
last_digest = previously_sent_digests[last_digest_index]

last_sent_content_id = max(last_digest.content_ids)
content_ids = [content.id for content in contents]
if last_sent_content_id not in content_ids:
content_sampler_index = -1
else:
content_sampler_index = content_ids.index(last_sent_content_id)

contents_length = len(contents)
sampled_contents = []
Expand Down
2 changes: 1 addition & 1 deletion production.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DELIVERY_SYSTEM="PostmarkDigestDeliverySystem"
APP_EMAIL_ADDRESS=echopages@pachovit.com
NUMBER_OF_UNITS_PER_DIGEST=1
DAILY_TIME_OF_DIGEST="15:50"
DAILY_TIME_OF_DIGEST="20:05"

0 comments on commit 46ca121

Please sign in to comment.