mirror of
https://github.com/scrapy/scrapy.git
synced 2025-02-25 03:43:58 +00:00
--HG-- rename : scrapy/spiderqueue.py => scrapyd/spiderqueue.py rename : scrapy/tests/test_spiderqueue.py => scrapyd/tests/test_spiderqueue.py
36 lines
853 B
Python
36 lines
853 B
Python
from zope.interface import implements
|
|
|
|
from scrapyd.interfaces import ISpiderQueue
|
|
from scrapy.utils.sqlite import JsonSqlitePriorityQueue
|
|
from scrapy.utils.project import sqlite_db
|
|
|
|
|
|
class SqliteSpiderQueue(object):
|
|
|
|
implements(ISpiderQueue)
|
|
|
|
def __init__(self, database=None, table='spider_queue'):
|
|
self.q = JsonSqlitePriorityQueue(database, table)
|
|
|
|
@classmethod
|
|
def from_settings(cls, settings):
|
|
return cls(sqlite_db(settings['SQLITE_DB']))
|
|
|
|
def add(self, name, **spider_args):
|
|
d = spider_args.copy()
|
|
d['name'] = name
|
|
priority = float(d.pop('priority', 0))
|
|
self.q.put(d, priority)
|
|
|
|
def pop(self):
|
|
return self.q.pop()
|
|
|
|
def count(self):
|
|
return len(self.q)
|
|
|
|
def list(self):
|
|
return [x[0] for x in self.q]
|
|
|
|
def clear(self):
|
|
self.q.clear()
|