mirror of
https://github.com/janLo/punkow
synced 2026-06-19 15:38:00 +00:00
Add some logging to the worker
This commit is contained in:
@@ -39,6 +39,14 @@ class RequestQueue(object):
|
|||||||
def is_empty(self):
|
def is_empty(self):
|
||||||
return len(self._targets) == 0
|
return len(self._targets) == 0
|
||||||
|
|
||||||
|
@property
|
||||||
|
def target_cnt(self):
|
||||||
|
return len(self._targets)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def request_cnt(self):
|
||||||
|
return sum(len(x) for x in self._requests.values())
|
||||||
|
|
||||||
|
|
||||||
def _book(target: str, reqs: typing.List[_WorkerRequest], debug = False) -> typing.List[int]:
|
def _book(target: str, reqs: typing.List[_WorkerRequest], debug = False) -> typing.List[int]:
|
||||||
data = [scraper.BookingData(name=req.name, email=req.email, id=req.id)
|
data = [scraper.BookingData(name=req.name, email=req.email, id=req.id)
|
||||||
@@ -46,15 +54,18 @@ def _book(target: str, reqs: typing.List[_WorkerRequest], debug = False) -> typi
|
|||||||
if target.startswith(scraper.BASE_URL):
|
if target.startswith(scraper.BASE_URL):
|
||||||
target = target[len(scraper.BASE_URL):]
|
target = target[len(scraper.BASE_URL):]
|
||||||
|
|
||||||
|
logger.info("Try to book %d appointments for %s", len(reqs), target)
|
||||||
|
|
||||||
booked_ids = []
|
booked_ids = []
|
||||||
try:
|
try:
|
||||||
svc = scraper.BookingService(target, debug=debug)
|
svc = scraper.BookingService(target, debug=debug)
|
||||||
for booked in svc.book(data):
|
for booked in svc.book(data):
|
||||||
booked_ids.append(booked.id)
|
booked_ids.append(booked.id)
|
||||||
except:
|
except:
|
||||||
print(target, reqs)
|
|
||||||
logger.exception("Exception while booking")
|
logger.exception("Exception while booking")
|
||||||
|
|
||||||
|
logger.info("Booked %d appointments for %s", len(booked_ids), target)
|
||||||
|
|
||||||
return booked_ids
|
return booked_ids
|
||||||
|
|
||||||
|
|
||||||
@@ -88,6 +99,7 @@ class Worker(object):
|
|||||||
for req in qry:
|
for req in qry:
|
||||||
requests.enqueue(req)
|
requests.enqueue(req)
|
||||||
|
|
||||||
|
logger.info("Loaded %d requests for %d targets", requests.request_cnt, requests.target_cnt)
|
||||||
return requests
|
return requests
|
||||||
|
|
||||||
def cleanup_booked(self, booked):
|
def cleanup_booked(self, booked):
|
||||||
|
|||||||
Reference in New Issue
Block a user