Class: FaHarnessTools::CheckSchedule
- Inherits:
-
Object
- Object
- FaHarnessTools::CheckSchedule
- Defined in:
- lib/fa-harness-tools/check_schedule.rb
Overview
Check against the time of day so you can restrict deploying to sensible hours.
Instance Method Summary collapse
-
#initialize(timezone:, schedules:) ⇒ CheckSchedule
constructor
A new instance of CheckSchedule.
- #verify? ⇒ Boolean
Constructor Details
#initialize(timezone:, schedules:) ⇒ CheckSchedule
Returns a new instance of CheckSchedule.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/fa-harness-tools/check_schedule.rb', line 8 def initialize(timezone:, schedules:) tz = TZInfo::Timezone.get(timezone) @timezone = timezone @now = tz.to_local(Time.now.utc) @schedules = schedules @logger = CheckLogger.new( name: "Check deployment schedule", description: "Only allow deployments within certain times of the day", ) end |
Instance Method Details
#verify? ⇒ Boolean
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/fa-harness-tools/check_schedule.rb', line 19 def verify? @logger.start @logger.info("operating in the #{@timezone} timezone") @logger.info("local time is #{@now}") permitted = @schedules.any? do |schedule| can_run = schedule.can_run?(time: @now) @logger.info("deployments are allowed due to the following schedule: #{schedule.to_s}") if can_run can_run end if permitted @logger.pass "inside the deployment schedule" else @logger.info "failed to match any schedule #{@schedules.map(&:to_s).join(", ")}" @logger.fail "outside the deployment schedule" end end |