Monitor threats independently of active jobs
This commit is contained in:
1 parent
f799a9ea47
commit
038fc503f0
4 files changed
+320
-8
No files matched your search
+25
-1
@@ -289,7 +289,8 @@ def tick(global_state):
|
||||
g.connection.write_packet(packet, force=True)
|
||||
g.connection.write_packet(ClientTickEnd(), force=True)
|
||||
|
||||
if g.job:
|
||||
monitor = g.get('threat_monitor')
|
||||
if g.job and not (monitor and monitor.suppress_job):
|
||||
g.job.tick()
|
||||
if g.game:
|
||||
g.game.tick() # order important for correction_count
|
||||
@@ -472,6 +473,10 @@ def start_automation(global_state, initialize=True):
|
||||
g.game = Game(g)
|
||||
g.job = JobStates(g)
|
||||
|
||||
if g.get('threat_monitor') is None:
|
||||
from mosfet.jobs.check_threats import ThreatMonitor
|
||||
g.threat_monitor = ThreatMonitor(g)
|
||||
|
||||
# Preserve active work during hot reloads, but give the worker all fields
|
||||
# introduced by the currently migrated inventory controls.
|
||||
g.setdefault('draining', False)
|
||||
@@ -527,6 +532,25 @@ def start_automation(global_state, initialize=True):
|
||||
initial_world_ready = True
|
||||
else:
|
||||
loaded_since = None
|
||||
# The monitor runs even with no active job; its own 0.5-second
|
||||
# timer keeps idle threat surveillance cheap and non-blocking.
|
||||
monitor = g.get('threat_monitor')
|
||||
if monitor is not None:
|
||||
try:
|
||||
reload_lock = g.get('reload_lock')
|
||||
if reload_lock is None:
|
||||
monitor.tick()
|
||||
else:
|
||||
with reload_lock:
|
||||
monitor.tick()
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
g.movement_error = traceback.format_exc()
|
||||
g.movement_status = 'error'
|
||||
print('[movement] stopped after threat-monitor error',
|
||||
flush=True)
|
||||
return
|
||||
|
||||
# Wait once for the initial position/chunk batch. After that,
|
||||
# bot.tick() keeps requesting chunks at cache boundaries instead
|
||||
# of gating itself forever on a momentary missing column.
|
||||
|
||||
Reference in new issue
Block a user