Skip to content
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

Update sync task to consider never synced orgs #4901

Merged
merged 1 commit into from
Aug 22, 2024
Merged
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
4 changes: 3 additions & 1 deletion engine/apps/grafana_plugin/tasks/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
def start_sync_organizations():
sync_threshold = timezone.now() - SYNC_PERIOD

organization_qs = Organization.objects.filter(last_time_synced__lte=sync_threshold)
organization_qs = Organization.objects.filter(last_time_synced__lte=sync_threshold) | Organization.objects.filter(
last_time_synced__isnull=True
)

active_instance_ids, is_cloud_configured = get_active_instance_ids()
if is_cloud_configured:
Expand Down
19 changes: 18 additions & 1 deletion engine/apps/grafana_plugin/tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
from django.utils import timezone

from apps.alerts.models import AlertReceiveChannel
from apps.grafana_plugin.tasks.sync import cleanup_empty_deleted_integrations, run_organization_sync
from apps.grafana_plugin.tasks.sync import (
cleanup_empty_deleted_integrations,
run_organization_sync,
start_sync_organizations,
)


class SyncOrganization(object):
Expand Down Expand Up @@ -45,6 +49,19 @@ def get_instance_info(self, stack_id: str):
return self.info


@pytest.mark.django_db
def test_start_sync_organization_filter(make_organization):
make_organization(last_time_synced=timezone.now())
org2 = make_organization(last_time_synced=None)
org3 = make_organization(last_time_synced=timezone.now() - timezone.timedelta(days=30))

with patch("apps.grafana_plugin.tasks.sync.sync_organization_async.apply_async") as mock_sync:
start_sync_organizations()
assert mock_sync.call_count == 2
mock_sync.assert_any_call((org2.pk,), countdown=0)
mock_sync.assert_any_call((org3.pk,), countdown=1)


@pytest.mark.django_db
def test_sync_organization_skip(
make_organization,
Expand Down
Loading