Class: ActionAgent::SandboxCleanupJob
- Inherits:
-
ApplicationJob
- Object
- ActiveJob::Base
- ApplicationJob
- ActionAgent::SandboxCleanupJob
- Defined in:
- app/jobs/action_agent/sandbox_cleanup_job.rb
Class Method Summary collapse
-
.cleanup_expired! ⇒ Object
Periodic cleanup of all expired sandboxes.
Instance Method Summary collapse
-
#perform(sandbox_session_id) ⇒ Object
Clean up Cloud Run resources for an expired sandbox.
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 |