commit
a7f6f1f8a8
2 changed files with 21 additions and 2 deletions
|
|
@ -27,7 +27,9 @@ CLEANUP_PERIOD = timezone.timedelta(hours=13)
|
|||
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:
|
||||
|
|
|
|||
|
|
@ -6,7 +6,11 @@ from django.test.utils import override_settings
|
|||
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):
|
||||
|
|
@ -45,6 +49,19 @@ class TestGcomAPIClient:
|
|||
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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue