Class: Chef::Resource::ExecutableSchedule

Inherits:
Chef::Resource show all
Defined in:
lib/chef/providers/executable_schedule_resource.rb

Overview

ExecutableSchedule chef resource. Allows defining the schedule(cron) for a right script or a recipe

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, run_context = nil) ⇒ ExecutableSchedule

Initialize ExecutableSchedule resource with default values

Parameters

name(String)

Name of the schedule



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/chef/providers/executable_schedule_resource.rb', line 41

def initialize(name, run_context=nil)
  super(name, run_context)
  @cron_resource = Chef::Resource::Cron.new(name)
  @cron_resource.user('rightscale')
  @resource_name = :executable_schedule
  recipe nil
  recipe_id nil
  right_script nil
  right_script_id nil
  @action = :create
  @allowed_actions.push(:create, :delete)
end

Instance Attribute Details

#cron_resourceObject

(Chef::Resource::Cron) Underlying cron resource



55
56
57
# File 'lib/chef/providers/executable_schedule_resource.rb', line 55

def cron_resource
  @cron_resource
end

Instance Method Details

#day(arg = nil) ⇒ Object

(String) Schedule day



73
74
75
# File 'lib/chef/providers/executable_schedule_resource.rb', line 73

def day(arg=nil)
  @cron_resource.day(arg)
end

#hour(arg = nil) ⇒ Object

(String) Schedule hour



68
69
70
# File 'lib/chef/providers/executable_schedule_resource.rb', line 68

def hour(arg=nil)
  @cron_resource.hour(arg)
end

#minute(arg = nil) ⇒ Object

(String) Schedule minute



63
64
65
# File 'lib/chef/providers/executable_schedule_resource.rb', line 63

def minute(arg=nil)
  @cron_resource.minute(arg)
end

#month(arg = nil) ⇒ Object

(String) Schedule month



78
79
80
# File 'lib/chef/providers/executable_schedule_resource.rb', line 78

def month(arg=nil)
  @cron_resource.month(arg)
end

#name(arg = nil) ⇒ Object

(String) Schedule name



58
59
60
# File 'lib/chef/providers/executable_schedule_resource.rb', line 58

def name(arg=nil)
  @cron_resource.name(arg)
end

#recipe(arg = nil) ⇒ Object

(String) recipe name for the schedule



88
89
90
91
92
93
94
95
96
# File 'lib/chef/providers/executable_schedule_resource.rb', line 88

def recipe(arg=nil)
  set_or_return(
    :recipe,
    arg,
    :kind_of => [ String ]
  )

  @cron_resource.command "rs_run_recipe -n #{arg}" if arg
end

#recipe_id(arg = nil) ⇒ Object

(String) recipe id for the schedule



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/chef/providers/executable_schedule_resource.rb', line 99

def recipe_id(arg=nil)
  if Integer(arg) < 0 then raise RangeError end
  if arg.is_a?(Integer)
    converted_arg = arg.to_s
  else
    converted_arg = arg
  end
  set_or_return(
    :recipe_id,
    converted_arg,
    :kind_of => [ String ]
  )

  @cron_resource.command "rs_run_recipe -i #{converted_arg}" if arg
end

#right_script(arg = nil) ⇒ Object

(String) RightScript’s name for the schedule



116
117
118
119
120
121
122
123
124
# File 'lib/chef/providers/executable_schedule_resource.rb', line 116

def right_script(arg=nil)
  set_or_return(
    :right_script,
    arg,
    :kind_of => [ String ]
  )

  @cron_resource.command "rs_run_right_script -n #{arg}" if arg
end

#right_script_id(arg = nil) ⇒ Object

(String) RightScript’s id for the schedule



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/chef/providers/executable_schedule_resource.rb', line 127

def right_script_id(arg=nil)
  if Integer(arg) < 0 then raise RangeError end
  if arg.is_a?(Integer)
    converted_arg = arg.to_s
  else
    converted_arg = arg
  end
  set_or_return(
    :right_script_id,
    converted_arg,
    :kind_of => [ String ]
  )

  @cron_resource.command "rs_run_right_script -i #{converted_arg}" if arg
end

#weekday(arg = nil) ⇒ Object

(String) Schedule weekday



83
84
85
# File 'lib/chef/providers/executable_schedule_resource.rb', line 83

def weekday(arg=nil)
  @cron_resource.weekday(arg)
end