Class: ChatNotificationWorker

Inherits:
Object
  • Object
show all
Includes:
ApplicationWorker
Defined in:
app/workers/chat_notification_worker.rb

Overview

rubocop:disable Scalability/IdempotentWorker

Constant Summary collapse

TimeoutExceeded =
Class.new(StandardError)
RESCHEDULE_INTERVAL =
2.seconds
RESCHEDULE_TIMEOUT =
5.minutes

Constants included from ApplicationWorker

ApplicationWorker::LOGGING_EXTRA_KEY

Constants included from WorkerAttributes

WorkerAttributes::NAMESPACE_WEIGHTS, WorkerAttributes::VALID_RESOURCE_BOUNDARIES, WorkerAttributes::VALID_URGENCIES

Instance Method Summary collapse

Methods included from Gitlab::SidekiqVersioning::Worker

#job_version

Methods included from WorkerContext

#with_context

Instance Method Details

#perform(build_id, reschedule_count = 0) ⇒ Object

rubocop: disable CodeReuse/ActiveRecord


18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/workers/chat_notification_worker.rb', line 18

def perform(build_id, reschedule_count = 0)
  Ci::Build.find_by(id: build_id).try do |build|
    send_response(build)
  end
rescue Gitlab::Chat::Output::MissingBuildSectionError
  raise TimeoutExceeded if timeout_exceeded?(reschedule_count)

  # The creation of traces and sections appears to be eventually consistent.
  # As a result it's possible for us to run the above code before the trace
  # sections are present. To better handle such cases we'll just reschedule
  # the job instead of producing an error.
  self.class.perform_in(RESCHEDULE_INTERVAL, build_id, reschedule_count + 1)
end

#send_response(build) ⇒ Object

rubocop: enable CodeReuse/ActiveRecord


33
34
35
36
37
38
39
40
41
42
43
# File 'app/workers/chat_notification_worker.rb', line 33

def send_response(build)
  Gitlab::Chat::Responder.responder_for(build).try do |responder|
    if build.success?
      output = Gitlab::Chat::Output.new(build)

      responder.success(output.to_s)
    else
      responder.failure
    end
  end
end