Class: RailsInformant::Api::DeploysController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/rails_informant/api/deploys_controller.rb

Constant Summary collapse

STALE_ERROR_CUTOFF =
1.hour

Instance Method Summary collapse

Instance Method Details

#createObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/rails_informant/api/deploys_controller.rb', line 6

def create
  sha = params[:sha]
  raise RailsInformant::InvalidParameterError, "sha is required" unless sha.present?
  raise RailsInformant::InvalidParameterError, "Invalid SHA format" unless sha.match?(RailsInformant::SHA_FORMAT)

  cutoff = STALE_ERROR_CUTOFF.ago
  resolved_count = ErrorGroup
    .where(status: "unresolved")
    .where(last_seen_at: ...cutoff)
    .update_all(
      status: "resolved", resolved_at: Time.current,
      fix_sha: sha, updated_at: Time.current
    )

  render json: { resolved_count:, sha: }
end