Class: RosettAi::Thor::Tasks::BuildContext

Inherits:
Struct
  • Object
show all
Defined in:
lib/rosett_ai/thor/tasks/build.rb

Overview

Mutable build state: ID, log path, timings, and failure info.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#build_idObject

Returns the value of attribute build_id

Returns:

  • (Object)

    the current value of build_id



20
21
22
# File 'lib/rosett_ai/thor/tasks/build.rb', line 20

def build_id
  @build_id
end

#build_logObject

Returns the value of attribute build_log

Returns:

  • (Object)

    the current value of build_log



20
21
22
# File 'lib/rosett_ai/thor/tasks/build.rb', line 20

def build_log
  @build_log
end

#build_startObject

Returns the value of attribute build_start

Returns:

  • (Object)

    the current value of build_start



20
21
22
# File 'lib/rosett_ai/thor/tasks/build.rb', line 20

def build_start
  @build_start
end

#completed_stagesObject

Returns the value of attribute completed_stages

Returns:

  • (Object)

    the current value of completed_stages



20
21
22
# File 'lib/rosett_ai/thor/tasks/build.rb', line 20

def completed_stages
  @completed_stages
end

#failed_stageObject

Returns the value of attribute failed_stage

Returns:

  • (Object)

    the current value of failed_stage



20
21
22
# File 'lib/rosett_ai/thor/tasks/build.rb', line 20

def failed_stage
  @failed_stage
end

#failure_reasonObject

Returns the value of attribute failure_reason

Returns:

  • (Object)

    the current value of failure_reason



20
21
22
# File 'lib/rosett_ai/thor/tasks/build.rb', line 20

def failure_reason
  @failure_reason
end

#stage_timingsObject

Returns the value of attribute stage_timings

Returns:

  • (Object)

    the current value of stage_timings



20
21
22
# File 'lib/rosett_ai/thor/tasks/build.rb', line 20

def stage_timings
  @stage_timings
end

#summary_printedObject

Returns the value of attribute summary_printed

Returns:

  • (Object)

    the current value of summary_printed



20
21
22
# File 'lib/rosett_ai/thor/tasks/build.rb', line 20

def summary_printed
  @summary_printed
end

Class Method Details

.create(log_dir) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rosett_ai/thor/tasks/build.rb', line 25

def self.create(log_dir)
  id = SecureRandom.uuid
  log_path = log_dir.join("build-#{id}.log")
  FileUtils.mkdir_p(log_path.dirname)
  ctx = new(
    build_id: id,
    build_start: Time.now,
    build_log: log_path,
    stage_timings: {},
    completed_stages: [],
    failed_stage: nil,
    failure_reason: nil,
    summary_printed: false
  )
  File.open(log_path, 'w', 0o644) do |f|
    f.write("# rosett-ai build log\n# Build ID: #{id}\n" \
            "# Started:  #{ctx.build_start.iso8601}\n\n")
  end
  ctx
end