worker: check tor before claiming work
This commit is contained in:
52
ppf.py
52
ppf.py
@@ -498,8 +498,6 @@ def worker_main(config):
|
|||||||
jobs_completed = 0
|
jobs_completed = 0
|
||||||
proxies_tested = 0
|
proxies_tested = 0
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
last_tor_check = time.time()
|
|
||||||
tor_check_interval = 300 # Check Tor every 5 minutes
|
|
||||||
current_tor_ip = None
|
current_tor_ip = None
|
||||||
consecutive_tor_failures = 0
|
consecutive_tor_failures = 0
|
||||||
worker_profiling = config.args.profile or config.common.profiling
|
worker_profiling = config.args.profile or config.common.profiling
|
||||||
@@ -546,33 +544,33 @@ def worker_main(config):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
# Periodic Tor health check
|
# Tor check before claiming work - don't claim if Tor is down
|
||||||
now = time.time()
|
working, tor_ip = check_tor_connectivity(config.torhosts)
|
||||||
if now - last_tor_check > tor_check_interval:
|
if not working:
|
||||||
working, tor_ip = check_tor_connectivity(config.torhosts)
|
consecutive_tor_failures += 1
|
||||||
last_tor_check = now
|
_log('tor down before claiming work (consecutive: %d)' % consecutive_tor_failures, 'warn')
|
||||||
if working:
|
try:
|
||||||
|
worker_send_heartbeat(server_url, wstate['worker_key'], False, None, worker_profiling)
|
||||||
|
except NeedReregister:
|
||||||
|
do_register()
|
||||||
|
if consecutive_tor_failures >= 2:
|
||||||
|
_log('tor appears down, waiting before claiming work', 'error')
|
||||||
|
working, current_tor_ip = wait_for_tor()
|
||||||
consecutive_tor_failures = 0
|
consecutive_tor_failures = 0
|
||||||
if tor_ip != current_tor_ip:
|
|
||||||
_log('tor circuit rotated: %s' % tor_ip, 'info')
|
|
||||||
current_tor_ip = tor_ip
|
|
||||||
# Send periodic heartbeat
|
|
||||||
try:
|
|
||||||
worker_send_heartbeat(server_url, wstate['worker_key'], True, tor_ip, worker_profiling)
|
|
||||||
except NeedReregister:
|
|
||||||
do_register()
|
|
||||||
else:
|
else:
|
||||||
consecutive_tor_failures += 1
|
time.sleep(10)
|
||||||
_log('tor connectivity failed (consecutive: %d)' % consecutive_tor_failures, 'warn')
|
continue
|
||||||
if consecutive_tor_failures >= 2:
|
else:
|
||||||
_log('tor appears down, pausing work', 'error')
|
consecutive_tor_failures = 0
|
||||||
try:
|
if tor_ip != current_tor_ip:
|
||||||
worker_send_heartbeat(server_url, wstate['worker_key'], False, None, worker_profiling)
|
if current_tor_ip:
|
||||||
except NeedReregister:
|
_log('tor circuit rotated: %s' % tor_ip, 'info')
|
||||||
do_register()
|
current_tor_ip = tor_ip
|
||||||
working, current_tor_ip = wait_for_tor()
|
# Send heartbeat to manager
|
||||||
consecutive_tor_failures = 0
|
try:
|
||||||
last_tor_check = time.time()
|
worker_send_heartbeat(server_url, wstate['worker_key'], True, tor_ip, worker_profiling)
|
||||||
|
except NeedReregister:
|
||||||
|
do_register()
|
||||||
|
|
||||||
# Get work from master
|
# Get work from master
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user