Class: RcrewAI::Rails::Span

Inherits:
ApplicationRecord show all
Defined in:
app/models/rcrewai/rails/span.rb

Constant Summary collapse

KINDS =
%w[crew agent task llm_call tool_call].freeze
STATUSES =
%w[running ok error].freeze

Instance Method Summary collapse

Instance Method Details

#attributes_hashObject



27
28
29
30
31
32
33
34
# File 'app/models/rcrewai/rails/span.rb', line 27

def attributes_hash
  raw = self[:attributes_json]
  return {} if raw.blank?

  JSON.parse(raw)
rescue JSON::ParserError
  {}
end

#attributes_hash=(hash) ⇒ Object



36
37
38
# File 'app/models/rcrewai/rails/span.rb', line 36

def attributes_hash=(hash)
  self[:attributes_json] = hash.nil? ? nil : JSON.generate(hash)
end

#errored?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'app/models/rcrewai/rails/span.rb', line 52

def errored?
  status == "error"
end

#finish!(status: "ok", ended_at: Time.current) ⇒ Object



40
41
42
43
44
45
46
# File 'app/models/rcrewai/rails/span.rb', line 40

def finish!(status: "ok", ended_at: Time.current)
  update!(
    status: status,
    ended_at: ended_at,
    duration_ms: ((ended_at - started_at) * 1000).round
  )
end

#running?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'app/models/rcrewai/rails/span.rb', line 48

def running?
  status == "running"
end