Class: Environments::RecalculateAutoStopService

Inherits:
Object
  • Object
show all
Defined in:
app/services/environments/recalculate_auto_stop_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(deployable) ⇒ RecalculateAutoStopService

Returns a new instance of RecalculateAutoStopService.



7
8
9
10
# File 'app/services/environments/recalculate_auto_stop_service.rb', line 7

def initialize(deployable)
  @deployable = deployable
  @environment = deployable.persisted_environment
end

Instance Attribute Details

#deployableObject (readonly)

Returns the value of attribute deployable.



5
6
7
# File 'app/services/environments/recalculate_auto_stop_service.rb', line 5

def deployable
  @deployable
end

#environmentObject (readonly)

Returns the value of attribute environment.



5
6
7
# File 'app/services/environments/recalculate_auto_stop_service.rb', line 5

def environment
  @environment
end

Instance Method Details

#executeObject



12
13
14
15
16
17
18
19
# File 'app/services/environments/recalculate_auto_stop_service.rb', line 12

def execute
  return unless can_set_auto_stop? && environment.present?

  auto_stop_in = deployable.expanded_auto_stop_in
  auto_stop_in ||= last_successful_deployable&.expanded_auto_stop_in if can_reset_timer?

  environment.update!(auto_stop_in: auto_stop_in) if auto_stop_in.present?
end