Class: Xronor::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/xronor/job.rb

Constant Summary collapse

DOM_INDEX =
2
DOW_INDEX =
4

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, description, schedule, command) ⇒ Job



6
7
8
9
10
11
# File 'lib/xronor/job.rb', line 6

def initialize(name, description, schedule, command)
  @name = name
  @description = description
  @schedule = schedule
  @command = command
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



13
14
15
# File 'lib/xronor/job.rb', line 13

def command
  @command
end

#descriptionObject (readonly)

Returns the value of attribute description.



13
14
15
# File 'lib/xronor/job.rb', line 13

def description
  @description
end

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/xronor/job.rb', line 13

def name
  @name
end

#scheduleObject (readonly)

Returns the value of attribute schedule.



13
14
15
# File 'lib/xronor/job.rb', line 13

def schedule
  @schedule
end

Instance Method Details

#cloud_watch_rule_name(prefix) ⇒ Object



34
35
36
# File 'lib/xronor/job.rb', line 34

def cloud_watch_rule_name(prefix)
  "#{prefix}#{@name}-#{hashcode}".gsub(/[^\.\-_A-Za-z0-9]/, "-").downcase
end

#cloud_watch_scheduleObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/xronor/job.rb', line 15

def cloud_watch_schedule
  cron_fields = @schedule.split(" ")

  if cron_fields[DOM_INDEX] == "*" && cron_fields[DOW_INDEX] == "*"
    cron_fields[DOW_INDEX] = "?"
  else
    cron_fields[DOM_INDEX] = "?" if cron_fields[DOM_INDEX] == "*"

    if cron_fields[DOW_INDEX] == "*"
      cron_fields[DOW_INDEX] = "?"
    else
      cron_fields[DOW_INDEX] = cron_fields[DOW_INDEX].to_i + 1
    end
  end

  cron_fields << "*" # Year
  "cron(#{cron_fields.join(" ")})"
end