Class: Gitlab::Ci::Config::External::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/ci/config/external/context.rb

Constant Summary collapse

TimeoutError =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project: nil, sha: nil, user: nil, parent_pipeline: nil) {|_self| ... } ⇒ Context

Returns a new instance of Context.

Yields:

  • (_self)

Yield Parameters:


13
14
15
16
17
18
19
20
21
22
# File 'lib/gitlab/ci/config/external/context.rb', line 13

def initialize(project: nil, sha: nil, user: nil, parent_pipeline: nil)
  @project = project
  @sha = sha
  @user = user
  @parent_pipeline = parent_pipeline
  @expandset = Set.new
  @execution_deadline = 0

  yield self if block_given?
end

Instance Attribute Details

#execution_deadlineObject

Returns the value of attribute execution_deadline


11
12
13
# File 'lib/gitlab/ci/config/external/context.rb', line 11

def execution_deadline
  @execution_deadline
end

#expandsetObject

Returns the value of attribute expandset


11
12
13
# File 'lib/gitlab/ci/config/external/context.rb', line 11

def expandset
  @expandset
end

#parent_pipelineObject (readonly)

Returns the value of attribute parent_pipeline


10
11
12
# File 'lib/gitlab/ci/config/external/context.rb', line 10

def parent_pipeline
  @parent_pipeline
end

#projectObject (readonly)

Returns the value of attribute project


10
11
12
# File 'lib/gitlab/ci/config/external/context.rb', line 10

def project
  @project
end

#shaObject (readonly)

Returns the value of attribute sha


10
11
12
# File 'lib/gitlab/ci/config/external/context.rb', line 10

def sha
  @sha
end

#userObject (readonly)

Returns the value of attribute user


10
11
12
# File 'lib/gitlab/ci/config/external/context.rb', line 10

def user
  @user
end

Instance Method Details

#check_execution_time!Object

Raises:


35
36
37
# File 'lib/gitlab/ci/config/external/context.rb', line 35

def check_execution_time!
  raise TimeoutError if execution_expired?
end

#mutate(attrs = {}) ⇒ Object


24
25
26
27
28
29
# File 'lib/gitlab/ci/config/external/context.rb', line 24

def mutate(attrs = {})
  self.class.new(**attrs) do |ctx|
    ctx.expandset = expandset
    ctx.execution_deadline = execution_deadline
  end
end

#sentry_payloadObject


39
40
41
42
43
44
# File 'lib/gitlab/ci/config/external/context.rb', line 39

def sentry_payload
  {
    user: user.inspect,
    project: project.inspect
  }
end

#set_deadline(timeout_seconds) ⇒ Object


31
32
33
# File 'lib/gitlab/ci/config/external/context.rb', line 31

def set_deadline(timeout_seconds)
  @execution_deadline = current_monotonic_time + timeout_seconds.to_f
end