Skip to content

Commit

Permalink
F: 实现用于后台触发爬取打包投递的周期计划任务的action
Browse files Browse the repository at this point in the history
  • Loading branch information
littlemo committed Apr 14, 2018
1 parent 5a182ff commit d5d0e01
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion server/spiders/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from .models import *
from . import tasks
from celery import group
from core.tasks import periodic_chain_crawl_package_deliver


class SpiderAdmin(admin.ModelAdmin):
Expand All @@ -15,7 +16,9 @@ class SpiderAdmin(admin.ModelAdmin):
'email', 'description']
list_filter = ('author',)
actions = [
'action_spider_post']
'action_spider_post',
'action_periodic_chain_crawl_package_deliver',
]

def action_spider_post(self, request, queryset):
"""异步爬取Post信息"""
Expand All @@ -28,7 +31,18 @@ def action_spider_post(self, request, queryset):
_('共触发 {num} 个爬虫源').format(
num=len(queryset)))

def action_periodic_chain_crawl_package_deliver(self, request, queryset):
'''异步周期链式爬取、打包并投递书籍'''
c = (group(
periodic_chain_crawl_package_deliver.s(
spider.name) for spider in queryset
))
c.delay()
self.message_user(request, _('成功创建调用任务'))

action_spider_post.short_description = _('异步爬取Post信息')
action_periodic_chain_crawl_package_deliver.short_description = \
_('异步周期链式爬取、打包并投递书籍')


class SpiderMetaAdmin(admin.ModelAdmin):
Expand Down

0 comments on commit d5d0e01

Please sign in to comment.