From: Michael Tremer Date: Tue, 26 Nov 2024 17:33:31 +0000 (+0000) Subject: campaigns: Remove old stuff X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f6499d1a6f444589f03945c4bc1d7ebd0e7e2784;p=ipfire.org.git campaigns: Remove old stuff Signed-off-by: Michael Tremer --- diff --git a/src/backend/base.py b/src/backend/base.py index 09eb6f93..29b707cb 100644 --- a/src/backend/base.py +++ b/src/backend/base.py @@ -164,9 +164,7 @@ class Backend(object): "check-mirrors" : self.mirrors.check_all, "cleanup" : self.cleanup, "get-all-emails" : self.accounts.get_all_emails, - "launch-campaigns" : self.campaigns.launch_manually, "load-certificate" : self.load_certificate, - "run-campaigns" : self.campaigns.run, "scan-files" : self.releases.scan_files, "send-message" : self.messages.send_cli, "send-all-messages" : self.messages.queue.send_all, diff --git a/src/backend/campaigns.py b/src/backend/campaigns.py index d11cd8a1..9e91222c 100644 --- a/src/backend/campaigns.py +++ b/src/backend/campaigns.py @@ -1,47 +1,8 @@ #!/usr/bin/python3 -import logging - -from .decorators import * from .misc import Object class Campaigns(Object): - async def launch_manually(self, name, uid): - account = self.backend.accounts.get_by_uid(uid) - if account: - self.launch(name, account) - - def launch(self, name, account): - logging.debug("Launching all campaigns for %s" % account) - - # Update old timestamps first - self.db.execute("UPDATE campaign_templates \ - SET launch_at = launch_at + repeat_after \ - WHERE (launch_at IS NOT NULL AND launch_at <= CURRENT_TIMESTAMP) \ - AND repeat_after IS NOT NULL") - - # Launch all campaigns - self.db.execute("INSERT INTO campaign_emails(account_uid, template, \ - launch_at, repeat_after, promotional) \ - SELECT %s, template, COALESCE(launch_at, CURRENT_TIMESTAMP + launch_after), \ - repeat_after, promotional FROM campaign_templates WHERE name = %s", - account.uid, name) - - def _get_campaign_emails(self, query, *args): - res = self.db.query(query, *args) - - for row in res: - yield CampaignEmail(self.backend, row.id, data=row) - - async def run(self): - with self.db.transaction(): - emails = self._get_campaign_emails("SELECT * FROM campaign_emails \ - WHERE launch_at <= CURRENT_TIMESTAMP ORDER BY launch_at") - - # Send them all - for email in emails: - email.send() - async def send(self, template, promotional=True, **kwargs): """ Sends a message to all users that have consented to promotional messages @@ -53,65 +14,3 @@ class Campaigns(Object): # Remember that we sent a promotional message if promotional: account.promotional_message_sent() - - -class CampaignEmail(Object): - def init(self, id, data=None): - self.id = id - self.data = data - - @lazy_property - def account(self): - return self.backend.accounts.get_by_uid(self.data.account_uid) - - @property - def template(self): - return self.data.template - - @property - def repeat_after(self): - return self.data.repeat_after - - @property - def promotional(self): - return self.data.promotional - - @property - def should_be_sent(self): - # Send all non-promotional emails - if not self.promotional: - return True - - # For promotional emails, send them if we have consent - return self.account.consents_to_promotional_emails - - def send(self): - # Delete if the account does not exist any more - if not self.account: - return self._delete() - - logging.debug("Sending %s to %s" % (self.template, self.account)) - - # Generate the email - if self.should_be_sent: - account.send_message(self.template) - - # Update this email for the next launch - self._update() - - def _update(self): - # If this email repeats, we will update the timestamp - if self.repeat_after: - self.db.execute("UPDATE campaign_emails \ - SET launch_at = launch_at + repeat_after \ - WHERE id = %s", self.id) - - # Otherwise we will delete it - else: - self._delete() - - def _delete(self): - """ - Deletes this email - """ - self.db.execute("DELETE FROM campaign_emails WHERE id = %s", self.id) diff --git a/src/crontab/ipfire b/src/crontab/ipfire index e1366ccf..b1f3584f 100644 --- a/src/crontab/ipfire +++ b/src/crontab/ipfire @@ -9,9 +9,6 @@ SHELL=/bin/bash # Send messages * * * * * nobody flock /tmp/.ipfire.org.send-all-messages.lock ipfire.org --logging=error send-all-messages -# Run campaigns -*/5 * * * * nobody ipfire.org --logging=error run-campaigns - # Announce blog posts */5 * * * * nobody flock /tmp/.ipfire.org.announce-blog-posts ipfire.org --logging=error announce-blog-posts