예제 #1
0
    def inner_handle(self):
        with connection.cursor() as curs:
            curs.execute("LISTEN pgeu_notification")
            curs.execute("LISTEN pgeu_broadcast")
            curs.execute("SET application_name = 'pgeu messages/media poster'")

        while True:
            providers = ProviderCache()

            send_pending_messages(providers)
            send_pending_posts(providers)

            self.eat_notifications()

            # Wake up to check if there is something to do every 5 minutes, just in case
            select.select([connection.connection], [], [], 5 * 60)
    def handle(self, *args, **options):
        curs = connection.cursor()
        curs.execute("SELECT pg_try_advisory_lock(981279)")
        if not curs.fetchall()[0][0]:
            raise CommandError("Failed to get advisory lock, existing post_media_broadcasts process stuck?")

        providers = ProviderCache()

        ok, numposts, numreposts = send_pending_posts(providers)

        if numposts:
            print("Sent {} broadcast posts".format(numposts))
        if numreposts:
            print("Made {} broadcast reposts".format(numreposts))

        if not ok:
            sys.exit(1)