Class: Kdeploy::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/kdeploy/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pipeline) ⇒ Runner

Returns a new instance of Runner.



7
8
9
# File 'lib/kdeploy/runner.rb', line 7

def initialize(pipeline)
  @pipeline = pipeline
end

Instance Attribute Details

#pipelineObject (readonly)

Returns the value of attribute pipeline.



5
6
7
# File 'lib/kdeploy/runner.rb', line 5

def pipeline
  @pipeline
end

Instance Method Details

#dry_runHash

Dry run - validate and show what would be executed

Returns:

  • (Hash)

    Validation results and execution plan



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/kdeploy/runner.rb', line 64

def dry_run
  KdeployLogger.info("Performing dry run for pipeline: #{@pipeline.name}")

  validation_errors = @pipeline.validate

  if validation_errors.any?
    KdeployLogger.error('Pipeline validation failed:')
    validation_errors.each { |error| KdeployLogger.error("  - #{error}") }

    return {
      success: false,
      validation_errors: validation_errors,
      execution_plan: nil
    }
  end

  execution_plan = generate_execution_plan

  KdeployLogger.info('Dry run completed successfully')
  log_execution_plan(execution_plan)

  {
    success: true,
    validation_errors: [],
    execution_plan: execution_plan
  }
end

#executeHash

Execute the deployment pipeline

Returns:

  • (Hash)

    Execution results



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/kdeploy/runner.rb', line 13

def execute
  validate_pipeline!
  setup_logging

  KdeployLogger.info("Starting deployment: #{@pipeline.name}")
  KdeployLogger.info("Pipeline summary: #{@pipeline.summary}")

  start_time = Time.now

  begin
    result = @pipeline.execute

    duration = Time.now - start_time

    # Enhanced result with pipeline info for statistics
    enhanced_result = result.merge(
      pipeline_name: @pipeline.name,
      hosts_count: @pipeline.hosts.size
    )

    # Record deployment statistics
    Kdeploy.statistics.record_deployment(enhanced_result)

    log_final_results(enhanced_result, duration)

    enhanced_result
  rescue StandardError => e
    duration = Time.now - start_time
    KdeployLogger.fatal("Deployment failed after #{duration.round(2)}s: #{e.message}")
    KdeployLogger.debug("Error backtrace: #{e.backtrace.join("\n")}")

    failed_result = {
      success: false,
      error: e.message,
      duration: duration,
      results: [],
      pipeline_name: @pipeline.name,
      hosts_count: @pipeline.hosts.size,
      tasks_count: @pipeline.tasks.size,
      success_count: 0
    }

    # Record failed deployment statistics
    Kdeploy.statistics.record_deployment(failed_result)

    failed_result
  end
end