Skip to content

Commit

Permalink
Merge pull request #4902 from grafana/dev
Browse files Browse the repository at this point in the history
v1.9.11
  • Loading branch information
matiasb authored Aug 22, 2024
2 parents 6ff4898 + 87dd5c6 commit a7f6f1f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
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

0 comments on commit a7f6f1f

Please sign in to comment.