Class: CoPlan::CommitExpiredSessionJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/coplan/commit_expired_session_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(session_id:) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/jobs/coplan/commit_expired_session_job.rb', line 5

def perform(session_id:)
  session = EditSession.find_by(id: session_id)
  return unless session  # Session was deleted

  # Only auto-commit if still open
  return unless session.open?

  if session.has_operations?
    Plans::CommitSession.call(
      session: session,
      change_summary: session.change_summary || "Auto-committed expired session"
    )
  else
    session.update!(status: "expired", committed_at: Time.current)
  end
rescue Plans::CommitSession::SessionNotOpenError
  # Session was closed concurrently (manual commit/cancel) — nothing to do
  Rails.logger.info("CommitExpiredSessionJob: session #{session_id} already closed, skipping")
rescue Plans::CommitSession::SessionConflictError, Plans::CommitSession::StaleSessionError, Plans::OperationError => e
  # Conflict during auto-commit — mark session as failed
  session.update!(status: "failed", change_summary: "Auto-commit failed: #{e.message}")
  Rails.logger.warn("CommitExpiredSessionJob failed for session #{session_id}: #{e.message}")
end