class DrainEngineJob
Drains and destroys the engine. Deliberately idempotent: it re-evaluates demand before acting, so work arriving during the grace period makes any scheduled job cancellation unnecessary.
Constants
- POLL_INTERVAL
Public Instance Methods
Source
# File app/jobs/drain_engine_job.rb, line 12 def perform state = TrinoEngineSupervisor.state return unless state.status == "draining" deadline = (state.drain_started_at || Time.current) + TrinoEngineSupervisor::DRAIN_GRACE loop do # Work arrived: begin_stopping! returns false and already restores to up. return unless still_draining? break if Time.current > deadline break if TrinoProvisioner.idle? sleep POLL_INTERVAL end # Last check and the transition to stopping happen under the SAME lock: # after this, new demand waits for down instead of being dispatched. return unless TrinoEngineSupervisor.begin_stopping! Rails.logger.warn("Drain grace period exhausted with queries still active; destroying anyway") unless TrinoProvisioner.idle? destroy_engine end
Polls the engine while it is draining, waiting for the grace period to elapse or all work to finish, then transitions to stopping and destroys the engine. No-op unless the engine is currently draining.