Class: ActionAgent::SandboxCleanupJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/action_agent/sandbox_cleanup_job.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.cleanup_expired!Object

Periodic cleanup of all expired sandboxes



25
26
27
28
29
# File 'app/jobs/action_agent/sandbox_cleanup_job.rb', line 25

def self.cleanup_expired!
  SandboxSession.expired_sessions.active.find_each do |sandbox|
    sandbox.expire!
  end
end

Instance Method Details

#perform(sandbox_session_id) ⇒ Object

Clean up Cloud Run resources for an expired sandbox



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/jobs/action_agent/sandbox_cleanup_job.rb', line 8

def perform(sandbox_session_id)
  sandbox = SandboxSession.find_by(id: sandbox_session_id)
  return unless sandbox

  Rails.logger.info("Cleaning up sandbox: #{sandbox.session_id}")

  # Delete Cloud Run Job if exists
  if sandbox.cloud_run_job_id.present? && !Rails.env.development?
    delete_cloud_run_job(sandbox.cloud_run_job_id)
  end

  # Optionally delete old sandbox records
  # For now, keep for analytics
  sandbox.update!(cloud_run_url: nil, cloud_run_job_id: nil)
end