Class: SFRest::Cron

Inherits:
Object
  • Object
show all
Defined in:
lib/sfrest/cron.rb

Overview

Manipulates SF cron jobs.

Instance Method Summary collapse

Constructor Details

#initialize(conn) ⇒ Cron

Returns a new instance of Cron.

Parameters:



7
8
9
# File 'lib/sfrest/cron.rb', line 7

def initialize(conn)
  @conn = conn
end

Instance Method Details

#create_cron_job(name, command, interval, scope, enabled, thread_percentage, stacks) ⇒ Object

Creates a new cron job rubocop: disable Metrics/ParameterLists

Parameters:

  • cron (string)

    job name

  • cron (string)

    job command

  • A (string)

    unix cron expression

  • Sites (string)

    affected by cron

  • if (int)

    the cron should be enabled

  • The (int)

    percentage of cron threads that should be used for this cron

  • An (array)

    array of stack ids for which the cron should be enabled



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/sfrest/cron.rb', line 37

def create_cron_job(name, command, interval, scope, enabled, thread_percentage, stacks)
  # rubocop: enable Metrics/ParameterLists
  payload = {
    'name' => name,
    'command' => command,
    'interval' => interval,
    'sites_affected' => scope,
    'enabled' => enabled,
    'thread_percentage' => thread_percentage,
    'stacks' => stacks
  }.to_json
  @conn.post('/api/v1/cronjobs', payload)
end

#delete_cron_job(nid) ⇒ Object

Deletes a cron job by its node id

Parameters:

  • cron (int)

    job nid



77
78
79
# File 'lib/sfrest/cron.rb', line 77

def delete_cron_job(nid)
  @conn.delete("/api/v1/cronjobs/#{nid}")
end

#edit_cron_job(nid, name, command, interval, scope, enabled, thread_percentage, stacks) ⇒ Object

Edits a cron job by its node id rubocop: disable Metrics/ParameterLists

Parameters:

  • cron (int)

    job nid

  • cron (string)

    job name

  • cron (string)

    job command

  • A (string)

    unix cron expression

  • Sites (string)

    affected by cron

  • if (int)

    the cron should be enabled

  • The (int)

    percentage of cron threads that should be used for this cron

  • An (array)

    array of stack ids for which the cron should be enabled



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/sfrest/cron.rb', line 61

def edit_cron_job(nid, name, command, interval, scope, enabled, thread_percentage, stacks)
  # rubocop: enable Metrics/ParameterLists
  payload = {
    'name' => name,
    'command' => command,
    'interval' => interval,
    'sites_affected' => scope,
    'enabled' => enabled,
    'thread_percentage' => thread_percentage,
    'stacks' => stacks
  }.to_json
  @conn.put("/api/v1/cronjobs/#{nid}", payload)
end

#get_cron_job(nid) ⇒ Object

Gets a cron job by its node id

Parameters:

  • cron (Integer)

    job nid



24
25
26
# File 'lib/sfrest/cron.rb', line 24

def get_cron_job(nid)
  @conn.get("/api/v1/cronjobs/#{nid}")
end

#get_cron_jobs(page = nil, limit = nil) ⇒ Object

Gets a list of cron jobs

Parameters:

  • page (Integer) (defaults to: nil)
  • items (Integer)

    per page



14
15
16
17
18
19
20
# File 'lib/sfrest/cron.rb', line 14

def get_cron_jobs(page = nil, limit = nil)
  args = {}
  args['page'] = page unless page.nil?
  args['limit'] = limit unless limit.nil?
  url = "/api/v1/cronjobs?#{args.map { |k, v| "#{k}=#{v}" }.join('&')}"
  @conn.get(url)
end