Skip to content

Commit

Permalink
fix: small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
talboren committed Aug 5, 2024
1 parent 5b0c084 commit 92ebb1e
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions keep/api/routes/preset.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import os
import uuid
from datetime import datetime, timezone
from datetime import datetime

from fastapi import (
APIRouter,
Expand Down Expand Up @@ -64,11 +64,16 @@ def pull_data_from_providers(
}

if provider.last_pull_time is not None:
now = datetime.now(tz=timezone.utc)
if (now - provider.last_pull_time).days <= PROVIDER_PULL_INTERVAL_DAYS:
now = datetime.now()
days_passed = (now - provider.last_pull_time).days
if days_passed <= PROVIDER_PULL_INTERVAL_DAYS:
logger.info(
"Skipping provider data pull",
extra=extra,
"Skipping provider data pulling since not enough time has passed",
extra={
**extra,
"days_passed": days_passed,
"provider_last_pull_time": str(provider.last_pull_time),
},
)
continue

Expand Down Expand Up @@ -105,6 +110,9 @@ def pull_data_from_providers(
extra=extra,
)

# Even if we failed at processing some event, lets save the last pull time to not iterate this process over and over again.
update_provider_last_pull_time(tenant_id=tenant_id, provider_id=provider.id)

for fingerprint, alert in sorted_provider_alerts_by_fingerprint.items():
process_event(
{},
Expand All @@ -117,7 +125,6 @@ def pull_data_from_providers(
alert,
notify_client=False,
)
update_provider_last_pull_time(tenant_id=tenant_id, provider_id=provider.id)


@router.get(
Expand Down

0 comments on commit 92ebb1e

Please sign in to comment.