Skip to content

Commit

Permalink
Run sync every 8 hours
Browse files Browse the repository at this point in the history
  • Loading branch information
rixx committed Nov 11, 2024
1 parent 8873d22 commit b706d7d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pretalx_salesforce/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ class SalesforceSettings(models.Model):
),
)

@property
def sync_ready(self):
return all(
[
self.client_id,
self.client_secret,
self.username,
self.password,
self.salesforce_instance,
]
)


class SpeakerProfileSalesforceSync(models.Model):
profile = models.OneToOneField(
Expand Down
14 changes: 14 additions & 0 deletions pretalx_salesforce/signals.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.dispatch import receiver
from django.urls import reverse
from pretalx.common.signals import minimum_interval, periodic_task
from pretalx.orga.signals import nav_event_settings


Expand All @@ -18,3 +19,16 @@ def pretalx_salesforce_settings(sender, request, **kwargs):
== "plugins:pretalx_salesforce:settings",
}
]


@receiver(periodic_task)
@minimum_interval(minutes_after_success=60 * 8)
def periodic_salesforce_sync(sender, **kwargs):
from .models import SalesforceSettings
from .tasks import salesforce_event_sync

for settings in SalesforceSettings.objects.all().filter(
event__plugins__contains="pretalx_salesforce"
):
if settings.sync_ready:
salesforce_event_sync.apply_async(kwargs={"event_id": settings.event_id})

0 comments on commit b706d7d

Please sign in to comment.