Skip to content

Commit

Permalink
fix(backend/newsletter/process_event_filter.py): Fix bug in processin…
Browse files Browse the repository at this point in the history
…g logic
  • Loading branch information
rcboufleur committed Nov 30, 2024
1 parent 0e8c5fe commit 7fe46b5
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions backend/newsletter/process_event_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,17 +261,18 @@ def process_subscription_filter(self, filter_set, output_path, force_run=False):
date_start = (now + relativedelta(months=1)).replace(
day=1, hour=0, minute=0, second=0, microsecond=0
)
allow_process = True if (date_start - now).days <= 7 else False
already_processed = (
latest_processing_date is not None
and (date_start - latest_processing_date).days < 7
processing_window = True if (date_start - now).days <= 7 else False

allow_process = (latest_processing_date is None) or not (
(date_start - relativedelta(days=7) <= latest_processing_date)
and (latest_processing_date <= date_start)
)

if force_run:
date_end = (
date_start + relativedelta(months=1) - relativedelta(microseconds=1)
)
elif allow_process and not already_processed:
elif processing_window and allow_process:
date_end = (
date_start + relativedelta(months=1) - relativedelta(microseconds=1)
)
Expand All @@ -285,20 +286,22 @@ def process_subscription_filter(self, filter_set, output_path, force_run=False):
date_start = (now + relativedelta(weekday=SU(+1))).replace(
hour=0, minute=0, second=0, microsecond=0
)
allow_process = (

processing_window = (
True if (date_start - now).days <= 3 else False
) # verifica se deve ser processado
already_processed = (
latest_processing_date is not None
and (date_start - latest_processing_date).days < 3

allow_process = (latest_processing_date is None) or not (
(date_start - relativedelta(days=3) <= latest_processing_date)
and (latest_processing_date <= date_start)
)
if force_run:
date_end = (
date_start
+ relativedelta(weekday=SU(+2))
- relativedelta(microseconds=1)
)
elif allow_process and not already_processed:
elif processing_window and allow_process:
date_end = (
date_start
+ relativedelta(weekday=SU(+2))
Expand All @@ -313,18 +316,19 @@ def process_subscription_filter(self, filter_set, output_path, force_run=False):
date_start = (now + relativedelta(days=1)).replace(
hour=0, minute=0, second=0, microsecond=0
)
self.log.info("Processing daily filter.")
processing_window = True if (date_start - now).seconds < 86400 else False

allow_process = True if (date_start - now).seconds < 86400 else False

already_processed = (
latest_processing_date is not None
and (date_start - latest_processing_date).seconds < 86400
allow_process = (latest_processing_date is None) or not (
(date_start - relativedelta(days=1) <= latest_processing_date)
and (latest_processing_date <= date_start)
)

if force_run:
date_end = (
date_start + relativedelta(days=1) - relativedelta(microseconds=1)
)
elif allow_process and not already_processed:
elif processing_window and allow_process:
date_end = (
date_start + relativedelta(days=1) - relativedelta(microseconds=1)
)
Expand Down

0 comments on commit 7fe46b5

Please sign in to comment.