Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated webservice.py #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions scrapyd/webservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
import uuid
from cStringIO import StringIO

from twisted.web import resource, static
from twisted.application.service import IServiceCollection

from twisted.python import log

from .utils import get_spider_list, JsonResource, UtilsCache

from .interfaces import IPoller, IEggStorage, ISpiderScheduler

class WsResource(JsonResource):

def __init__(self, root):
Expand Down Expand Up @@ -124,3 +129,39 @@ def render_POST(self, txrequest):
version = txrequest.args['version'][0]
self._delete_version(project, version)
return {"node_name": self.root.nodename, "status": "ok"}

class ListAllJobs(WsResource):

@property
def launcher(self):
app = IServiceCollection(self.app, self.app)
return app.getServiceNamed('launcher')

@property
def scheduler(self):
return self.app.getComponent(ISpiderScheduler)

@property
def eggstorage(self):
return self.app.getComponent(IEggStorage)

@property
def poller(self):
return self.app.getComponent(IPoller)

def render_GET(self, txrequest):

for projectname, queue in self.root.poller.queues.items():
pending = [{"project":projectname,"id": x["_job"], "spider": x["name"]} for x in queue.list()]

spiders = self.root.launcher.processes.values()
running = [{"id": s.job, "spider": s.spider,"project": s.project, "pid": s.pid,"start_time" : s.start_time.isoformat(' ')} for s in spiders]

finished = [{"id": s.job, "spider": s.spider,
"start_time": s.start_time.isoformat(' '),
"end_time": s.end_time.isoformat(' '),
"project" : s.project} for s in self.root.launcher.finished
]

return {"status":"ok", "pending": pending, "running" : running, "finished" : finished}