コード例 #1
0
ファイル: models.py プロジェクト: credis/subhub
    def process(self, log=None):
        """
        Processes all subscriptions for expiration and automatic refreshing.
        """
        utils.lock("subscription")
        try:
            if log is None:
                log = logging.getLogger("subhub.subscription.process")

            for subscription in self.all():
                if subscription.expires < datetime.now():
                    subscription.delete()
                    log.info("Subscription expired %s" % subscription)
                elif subscription.expires - datetime.now() < timedelta(seconds=MIN_LEASE):
                    task, created = SubscriptionTask.objects.get_or_create(
                        callback=subscription.callback,
                        topic=subscription.topic,
                        verify_token=subscription.verify_token,
                        mode="subscribe",
                        defaults={"secret": subscription.secret},
                    )
                    if created:
                        log.info("Refresh request for %s" % subscription)
        finally:
            utils.unlock("subscription")
コード例 #2
0
ファイル: models.py プロジェクト: credis/subhub
    def process(self, log=None):
        """
        Verifies all tasks in queue.
        """
        utils.lock("subscriptiontask")
        try:
            if log is None:
                log = logging.getLogger("subhub.subscriptiontask.process")

            for task in self.all():
                result, description = task.verify()
                if result:
                    log.info("%s: %s" % (task, description))
                else:
                    log.error("%s (ttl=%s): %s" % (task, task.ttl, description))
        finally:
            utils.unlock("subscriptiontask")
コード例 #3
0
ファイル: models.py プロジェクト: credis/subhub
                    if 200 <= response.status < 300:
                        sent_ids = [id.text for id in feed.root.findall("entry/id")]
                        log.info("%s (%s)" % (subscription, ", ".join(sent_ids)))
                        return True
                    else:
                        log.error("%s: HTTP Error %s" % (subscription, response.status))
                except utils.HTTP_ERRORS, e:
                    log.error("%s: %s" % (subscription, e))
                return False

            results = utils.pool(process_update, updates)
            for result, (subscription, feed) in results:
                if result:
                    self.filter(subscription=subscription).delete()
        finally:
            utils.unlock("distribution")


class DistributionTask(models.Model):
    """
    Task for pushing a particular entry to a subscriber.
    """

    subscription = models.ForeignKey(Subscription)
    entry_id = models.CharField(max_length=1024)

    objects = DistributionTaskManager()

    class Meta:
        unique_together = [("subscription", "entry_id")]