MCPcopy Create free account
hub / github.com/RocketMap/RocketMap / search_worker_thread

Function search_worker_thread

pogom/search.py:383–580  ·  view source on GitHub ↗
(args, account_queue, account_failures, search_items_queue, pause_bit, encryption_lib_path, status, dbq, whq)

Source from the content-addressed store, hash-verified

381
382
383def search_worker_thread(args, account_queue, account_failures, search_items_queue, pause_bit, encryption_lib_path, status, dbq, whq):
384
385 log.debug('Search worker thread starting')
386
387 # The outer forever loop restarts only when the inner one is intentionally exited - which should only be done when the worker is failing too often, and probably banned.
388 # This reinitializes the API and grabs a new account from the queue.
389 while True:
390 try:
391 status['starttime'] = now()
392
393 # Get account
394 status['message'] = 'Waiting to get new account from the queue'
395 log.info(status['message'])
396 account = account_queue.get()
397 status['message'] = 'Switching to account {}'.format(account['username'])
398 status['user'] = account['username']
399 log.info(status['message'])
400
401 stagger_thread(args, account)
402
403 # New lease of life right here
404 status['fail'] = 0
405 status['success'] = 0
406 status['noitems'] = 0
407 status['skip'] = 0
408 status['location'] = False
409 status['last_scan_time'] = 0
410
411 # only sleep when consecutive_fails reaches max_failures, overall fails for stat purposes
412 consecutive_fails = 0
413
414 # Create the API instance this will use
415 if args.mock != '':
416 api = FakePogoApi(args.mock)
417 else:
418 api = PGoApi()
419
420 if status['proxy_url']:
421 log.debug("Using proxy %s", status['proxy_url'])
422 api.set_proxy({'http': status['proxy_url'], 'https': status['proxy_url']})
423
424 api.activate_signature(encryption_lib_path)
425
426 # The forever loop for the searches
427 while True:
428
429 # If this account has been messing up too hard, let it rest
430 if consecutive_fails >= args.max_failures:
431 status['message'] = 'Account {} failed more than {} scans; possibly bad account. Switching accounts...'.format(account['username'], args.max_failures)
432 log.warning(status['message'])
433 account_failures.append({'account': account, 'last_fail_time': now(), 'reason': 'failures'})
434 break # exit this loop to get a new account and have the API recreated
435
436 # If this account has been running too long, let it rest
437 if (args.account_search_interval is not None):
438 if (status['starttime'] <= (now() - args.account_search_interval)):
439 status['message'] = 'Account {} is being rotated out to rest.'.format(account['username'])
440 log.info(status['message'])

Callers

nothing calls this directly

Calls 13

nowFunction · 0.85
stagger_threadFunction · 0.85
FakePogoApiClass · 0.85
check_loginFunction · 0.85
map_requestFunction · 0.85
parse_mapFunction · 0.85
calc_distanceFunction · 0.85
gym_requestFunction · 0.85
parse_gymsFunction · 0.85
set_proxyMethod · 0.80
activate_signatureMethod · 0.80
appendMethod · 0.80

Tested by

no test coverage detected