]> git.ipfire.org Git - ipfire.org.git/commitdiff
campaigns: Remove old stuff
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 26 Nov 2024 17:33:31 +0000 (17:33 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 26 Nov 2024 17:33:31 +0000 (17:33 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/backend/base.py
src/backend/campaigns.py
src/crontab/ipfire

index 09eb6f93031a2d680b372a299744978931a23635..29b707cbd91fe8af7b6e12c0bc978010bea31493 100644 (file)
@@ -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,
index d11cd8a118488bd50fe54cf968ba175ce4385e60..9e91222c35d9d42945e6fda8f3ae67cfe6650556 100644 (file)
@@ -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)
index e1366ccf3e6dc1fb073201717f7849f51f509c3a..b1f3584f558387395de5cb663e56b6ac285fc9a1 100644 (file)
@@ -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