mirror of
https://github.com/scrapy/scrapy.git
synced 2025-02-27 01:43:43 +00:00
46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
from twisted.application.service import Application
|
|
from twisted.application.internet import TimerService, TCPServer
|
|
from twisted.web import server
|
|
from twisted.python import log
|
|
|
|
from scrapy.utils.misc import load_object
|
|
|
|
from .interfaces import IEggStorage, IPoller, ISpiderScheduler, IEnvironment
|
|
from .launcher import Launcher
|
|
from .eggstorage import FilesystemEggStorage
|
|
from .scheduler import SpiderScheduler
|
|
from .poller import QueuePoller
|
|
from .environ import Environment
|
|
from .website import Root
|
|
from .config import Config
|
|
|
|
def application(config):
|
|
app = Application("Scrapyd")
|
|
http_port = config.getint('http_port', 6800)
|
|
bind_address = config.get('bind_address', '0.0.0.0')
|
|
|
|
poller = QueuePoller(config)
|
|
eggstorage = FilesystemEggStorage(config)
|
|
scheduler = SpiderScheduler(config)
|
|
environment = Environment(config)
|
|
|
|
app.setComponent(IPoller, poller)
|
|
app.setComponent(IEggStorage, eggstorage)
|
|
app.setComponent(ISpiderScheduler, scheduler)
|
|
app.setComponent(IEnvironment, environment)
|
|
|
|
laupath = config.get('launcher', 'scrapyd.launcher.Launcher')
|
|
laucls = load_object(laupath)
|
|
launcher = laucls(config, app)
|
|
|
|
timer = TimerService(5, poller.poll)
|
|
webservice = TCPServer(http_port, server.Site(Root(config, app)), interface=bind_address)
|
|
log.msg(format="Scrapyd web console available at http://%(bind_address)s:%(http_port)s/",
|
|
bind_address=bind_address, http_port=http_port)
|
|
|
|
launcher.setServiceParent(app)
|
|
timer.setServiceParent(app)
|
|
webservice.setServiceParent(app)
|
|
|
|
return app
|