本文整理汇总了Python中celery.task.Task.get_publisher方法的典型用法代码示例。如果您正苦于以下问题:Python Task.get_publisher方法的具体用法?Python Task.get_publisher怎么用?Python Task.get_publisher使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类celery.task.Task
的用法示例。
在下文中一共展示了Task.get_publisher方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from celery.task import Task [as 别名]
# 或者: from celery.task.Task import get_publisher [as 别名]
def handle(self, *args, **options):
settings.LOG_TO_STREAM = True
now = datetime.datetime.utcnow()
feeds = Feed.objects.filter(
next_scheduled_update__lte=now,
active=True
).exclude(
active_subscribers=0
).order_by('?')
if options['force']:
feeds = Feed.objects.all().order_by('pk')
print " ---> Tasking %s feeds..." % feeds.count()
publisher = Task.get_publisher()
feed_queue = []
size = 12
for f in feeds:
f.queued_date = datetime.datetime.utcnow()
f.set_next_scheduled_update()
for feed_queue in (feeds[pos:pos + size] for pos in xrange(0, len(feeds), size)):
print feed_queue
feed_ids = [feed.pk for feed in feed_queue]
print feed_ids
UpdateFeeds.apply_async(args=(feed_ids,), queue='update_feeds', publisher=publisher)
publisher.connection.close()
示例2: queue_new_feeds
# 需要导入模块: from celery.task import Task [as 别名]
# 或者: from celery.task.Task import get_publisher [as 别名]
def queue_new_feeds(self):
new_feeds = UserSubscription.objects.filter(user=self.user, feed__fetched_once=False).values("feed_id")
new_feeds = list(set([f["feed_id"] for f in new_feeds]))
logging.info(" ---> [%s] Queueing NewFeeds: (%s) %s" % (self.user, len(new_feeds), new_feeds))
size = 4
publisher = Task.get_publisher(exchange="new_feeds")
for t in (new_feeds[pos : pos + size] for pos in xrange(0, len(new_feeds), size)):
NewFeeds.apply_async(args=(t,), queue="new_feeds", publisher=publisher)
publisher.connection.close()
示例3: queue_new_feeds
# 需要导入模块: from celery.task import Task [as 别名]
# 或者: from celery.task.Task import get_publisher [as 别名]
def queue_new_feeds(self, new_feeds=None):
if not new_feeds:
new_feeds = UserSubscription.objects.filter(user=self.user,
feed__fetched_once=False,
active=True).values('feed_id')
new_feeds = list(set([f['feed_id'] for f in new_feeds]))
logging.user(self.user, "~BB~FW~SBQueueing NewFeeds: ~FC(%s) %s" % (len(new_feeds), new_feeds))
size = 4
publisher = Task.get_publisher(exchange="new_feeds")
for t in (new_feeds[pos:pos + size] for pos in xrange(0, len(new_feeds), size)):
NewFeeds.apply_async(args=(t,), queue="new_feeds", publisher=publisher)
publisher.connection.close()
示例4: task_feeds
# 需要导入模块: from celery.task import Task [as 别名]
# 或者: from celery.task.Task import get_publisher [as 别名]
def task_feeds(cls, feeds, queue_size=12):
print " ---> Tasking %s feeds..." % feeds.count()
publisher = Task.get_publisher()
feed_queue = []
for f in feeds:
f.queued_date = datetime.datetime.utcnow()
f.set_next_scheduled_update()
for feed_queue in (feeds[pos : pos + queue_size] for pos in xrange(0, len(feeds), queue_size)):
feed_ids = [feed.pk for feed in feed_queue]
UpdateFeeds.apply_async(args=(feed_ids,), queue="update_feeds", publisher=publisher)
publisher.connection.close()