Class: PuppetX::PuppetLabs::ScheduledTask::Trigger::V2::Days Private

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet_x/puppetlabs/scheduled_task/trigger.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defines the day of the month the task will run.

Constant Summary collapse

MAX_VALUE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

32 bit mask, but only 31 days can be set. This is contrary to the V2 IMonthlyTrigger::DaysOfMonth documentation referenced below, but in testing, setting the last bit of the bit mask does not set ‘last’ day of month as that documentation suggests. Instead it results in an error. That feature will be handled instead by the RunOnLastDayOfMonth property of the trigger object. V2 IMonthlyTrigger::RunOnLastDayOfMonth docs.microsoft.com/en-us/windows/win32/api/taskschd/nf-taskschd-imonthlytrigger-put_runonlastdayofmonth

0b01111111111111111111111111111111

Class Method Summary collapse

Class Method Details

.bit_index(bitmask) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns bit index



442
443
444
445
446
447
448
# File 'lib/puppet_x/puppetlabs/scheduled_task/trigger.rb', line 442

def self.bit_index(bitmask)
  (0..31).select do |bit_index|
    bit_to_check = 1 << bit_index
    # given position is set in the bitmask
    (bitmask & bit_to_check) == bit_to_check
  end
end

.bitmask_to_indexes(bitmask, run_on_last_day_of_month = nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converts bitmask to index



428
429
430
431
432
433
434
435
436
437
438
439
# File 'lib/puppet_x/puppetlabs/scheduled_task/trigger.rb', line 428

def self.bitmask_to_indexes(bitmask, run_on_last_day_of_month = nil)
  bitmask = Integer(bitmask)
  if bitmask.negative? || bitmask > MAX_VALUE
    raise ArgumentError, "bitmask must be specified as an integer from 0 to #{MAX_VALUE.to_s(10)}"
  end

  indexes = bit_index(bitmask).map { |bit_index| bit_index + 1 }

  indexes << 'last' if run_on_last_day_of_month

  indexes
end

.indexes_to_bitmask(day_indexes) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

V1 MONTHLYDATE structure msdn.microsoft.com/en-us/library/windows/desktop/aa381918(v=vs.85).aspx V2 IMonthlyTrigger::DaysOfMonth msdn.microsoft.com/en-us/library/windows/desktop/aa380735(v=vs.85).aspx



413
414
415
416
417
418
419
420
421
422
423
424
425
# File 'lib/puppet_x/puppetlabs/scheduled_task/trigger.rb', line 413

def self.indexes_to_bitmask(day_indexes)
  if day_indexes.nil? || (day_indexes.is_a?(Hash) && day_indexes.empty?)
    raise TypeError, 'Day indexes value must not be nil or an empty hash.'
  end

  integer_days = Array(day_indexes).select { |i| i.is_a?(Integer) }
  invalid_days = integer_days.reject { |i| i.between?(1, 31) }

  unless invalid_days.empty?
    raise ArgumentError, "Day indexes value #{invalid_days.join(', ')} is invalid. Integers must be in the range 1-31"
  end
  integer_days.reduce(0) { |bitmask, day_index| bitmask | 1 << day_index - 1 }
end

.last_day_of_month?(day_indexes) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


450
451
452
453
454
455
456
# File 'lib/puppet_x/puppetlabs/scheduled_task/trigger.rb', line 450

def self.last_day_of_month?(day_indexes)
  invalid_day_names = Array(day_indexes).select { |i| i.is_a?(String) && (i != 'last') }
  unless invalid_day_names.empty?
    raise ArgumentError, "Only 'last' is allowed as a day name. All other values must be integers between 1 and 31."
  end
  Array(day_indexes).include? 'last'
end