Puppet Function: simplib::cron::to_systemd

Defined in:
functions/cron/to_systemd.pp
Function type:
Puppet Language

Overview

simplib::cron::to_systemd(Simplib::Cron::Minute $minute = '*', Simplib::Cron::Hour $hour = '*', Simplib::Cron::Month $month = '*', Simplib::Cron::Monthday $monthday = '*', Optional[Simplib::Cron::Weekday] $weekday = undef)String

Convert a set of ‘cron’ native type parameters to a ‘best effort’ systemd calendar String

Parameters:

  • minute (Simplib::Cron::Minute) (defaults to: '*')

    The ‘minute` parameter from the cron resource

  • hour (Simplib::Cron::Hour) (defaults to: '*')

    The ‘hour` parameter from the cron resource

  • month (Simplib::Cron::Month) (defaults to: '*')

    The ‘month` parameter from the cron resource

  • monthday (Simplib::Cron::Monthday) (defaults to: '*')

    The ‘monthday` parameter from the cron resource

  • weekday (Optional[Simplib::Cron::Weekday]) (defaults to: undef)

    The ‘weekday` parameter from the cron resource

Returns:

  • (String)


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
61
62
63
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
91
92
# File 'functions/cron/to_systemd.pp', line 21

function simplib::cron::to_systemd(
  Simplib::Cron::Minute            $minute   = '*',
  Simplib::Cron::Hour              $hour     = '*',
  Simplib::Cron::Month             $month    = '*',
  Simplib::Cron::Monthday          $monthday = '*',
  Optional[Simplib::Cron::Weekday] $weekday  = undef
) {
  $_minute = simplib::cron::expand_range(Array($minute, true).join(','))

  $_hour = simplib::cron::expand_range(Array($hour, true).join(','))

  $_month = Array($month, true).map |$m| {
    $m ? {
      /(?i:jan)/ => 1,
      /(?i:feb)/ => 2,
      /(?i:mar)/ => 3,
      /(?i:apr)/ => 4,
      /(?i:may)/ => 5,
      /(?i:jun)/ => 6,
      /(?i:jul)/ => 7,
      /(?i:aug)/ => 8,
      /(?i:sep)/ => 9,
      /(?i:oct)/ => 10,
      /(?i:nov)/ => 11,
      /(?i:dec)/ => 12,
      default    => $m
    }
  }.join(',')

  $_monthday = Array($monthday, true).join(',')

  if $weekday {
    $_munged_weekday = Array($weekday, true).map |$w| {
      if '-' in $w {
        simplib::cron::expand_range($w)
      }
      else {
        $w
      }
    }

    $_weekday = Array($_munged_weekday, true).map |$w| {
      "${w}".split(',').map |$mw| {
        "${mw}" ? {
          '*'     => undef,
          '0'     => 'Sun',
          '1'     => 'Mon',
          '2'     => 'Tue',
          '3'     => 'Wed',
          '4'     => 'Thu',
          '5'     => 'Fri',
          '6'     => 'Sat',
          default => $weekday
        }
      }.join(',')
    }.join(',')
  }
  else {
    $_weekday = ''
  }

  strip(
    join(
      [
        $_weekday,
        join([$_month, $_monthday], '-'),
        join([$_hour, $_minute], ':')
      ],
      ' '
    )
  )
}