Class: Regent::Span

Inherits:
Object
  • Object
show all
Includes:
Concerns::Durationable, Concerns::Identifiable
Defined in:
lib/regent/span.rb

Defined Under Namespace

Modules: Type

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Concerns::Durationable

#duration

Methods included from Concerns::Identifiable

included

Constructor Details

#initialize(type:, arguments:, logger: Logger.new) ⇒ Span

Returns a new instance of Span.

Parameters:

  • type (String)

    The type of span (must be one of Type.all)

  • arguments (Hash)

    Arguments for the span

  • logger (Logger) (defaults to: Logger.new)

    Logger instance



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/regent/span.rb', line 27

def initialize(type:, arguments:, logger: Logger.new)
  super()

  validate_type!(type)

  @logger = logger
  @type = type
  @arguments = arguments
  @meta = nil
  @output = nil
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



39
40
41
# File 'lib/regent/span.rb', line 39

def arguments
  @arguments
end

#end_timeObject (readonly)

Returns the value of attribute end_time.



39
40
41
# File 'lib/regent/span.rb', line 39

def end_time
  @end_time
end

#nameObject (readonly)

Returns the value of attribute name.



39
40
41
# File 'lib/regent/span.rb', line 39

def name
  @name
end

#outputObject (readonly)

Returns the value of attribute output.



39
40
41
# File 'lib/regent/span.rb', line 39

def output
  @output
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



39
40
41
# File 'lib/regent/span.rb', line 39

def start_time
  @start_time
end

#typeObject (readonly)

Returns the value of attribute type.



39
40
41
# File 'lib/regent/span.rb', line 39

def type
  @type
end

Instance Method Details

#completed?Boolean

Returns Whether the span is completed.

Returns:

  • (Boolean)

    Whether the span is completed



64
65
66
# File 'lib/regent/span.rb', line 64

def completed?
  @start_time && @end_time
end

#replayString

Returns The output of the span.

Returns:

  • (String)

    The output of the span



54
55
56
# File 'lib/regent/span.rb', line 54

def replay
  log_operation(live: false) { @output }
end

#runString

Returns The output of the span.

Returns:

  • (String)

    The output of the span

Raises:

  • (ArgumentError)

    if block is not given



43
44
45
46
47
48
49
50
51
# File 'lib/regent/span.rb', line 43

def run
  @output = log_operation do
    yield

  rescue StandardError, ToolError => e
    logger.error(label: type, message: e.message, **arguments)
    raise
  end
end

#running?Boolean

Returns Whether the span is currently running.

Returns:

  • (Boolean)

    Whether the span is currently running



59
60
61
# File 'lib/regent/span.rb', line 59

def running?
  @start_time && @end_time.nil?
end

#set_meta(value) ⇒ Object

Parameters:

  • value (String)

    The meta value to set



69
70
71
# File 'lib/regent/span.rb', line 69

def set_meta(value)
  @meta = value.freeze
end