Method: Proby::ProbyTask.create

Defined in:
lib/proby/proby_task.rb

.create(attributes = {}) ⇒ ProbyTask

Create a new Proby task.

Examples:

proby_task = ProbyTask.create(:name => "My new task", :crontab => "* * * * *")

Parameters:

  • attributes (Hash) (defaults to: {})

    The attributes for your task.

Options Hash (attributes):

  • :name (String)

    A name for your task.

  • :crontab (String)

    The schedule of the task, specified in cron format.

  • :time_zone (String)

    (Optional) The time zone of the machine executing the task.

  • :machine (String)

    (Optional) The name of the machine that is responsible for running this task. Will default to the default time zone configured in Proby if not specified.

  • :finish_alarms_enabled (Boolean)

    (Optional) true if you would like to receive finish alarms for this task, false otherwise (default: true).

  • :maximum_run_time (Fixnum)

    (Optional) The maximum amount of time the task is allowed to run before Proby sends a finish alarm. If not specified, Proby will determine when an alarm should be sent based on past run times.

  • :start_notification_grace_period (Fixnum)

    (Optional) The number of minutes to wait for a task to send its start notification after it should have started before sending an alarm.

  • :consecutive_alarmed_tasks_required_to_trigger_alarm (Fixnum)

    (Optional) The number of consecutive tasks that must fail before an alarm is sent.

Returns:

Raises:



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/proby/proby_task.rb', line 119

def self.create(attributes={})
  ensure_api_key_set
  raise InvalidParameterException.new("attributes are required") if attributes.nil? || attributes.empty?
  raise InvalidParameterException.new("name is required") unless !blank?(attributes[:name]) || !blank?(attributes['name'])
  raise InvalidParameterException.new("crontab is required") unless !blank?(attributes[:crontab]) || !blank?(attributes['crontab'])

  Proby.logger.info "Creating task with attributes: #{attributes.inspect}"
  response = post("/api/v1/tasks.json",
                  :format => :json,
                  :body => MultiJson.encode(:task => attributes),
                  :headers => default_headers)

  if response.code == 201 
    new(response.parsed_response['task'])
  else
    handle_api_failure(response)
  end 
end