Module: Chronos

Defined in:
lib/chronos.rb,
lib/chronos/version.rb

Overview

The top-level module for this gem. It’s purpose is to hold global configuration variables that are used as defaults in other classes.

Defined Under Namespace

Modules: Error Classes: Connection

Constant Summary collapse

DEFAULT_URL =
'http://localhost:4400'
VERSION =
'0.0.1'

Class Method Summary collapse

Class Method Details

.add(job) ⇒ Object

add job



72
73
74
# File 'lib/chronos.rb', line 72

def add(job)
  connection.post('/scheduler/iso8601', nil, body: job)
end

.connectionObject

Set a new connection



57
58
59
# File 'lib/chronos.rb', line 57

def connection
  @connection ||= Connection.new(url, options)
end

.delete(name) ⇒ Object

delete job



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

def delete(name)
  connection.delete("/scheduler/job/#{URI.encode name}")
end

.delete_allObject

delete all jobs



82
83
84
# File 'lib/chronos.rb', line 82

def delete_all
  connection.delete('/scheduler/jobs')
end

.env_optionsObject

Get marathon options from environment



26
27
28
29
30
31
# File 'lib/chronos.rb', line 26

def env_options
  opts = {}
  opts[:username] = ENV['CHRONOS_USER'] if ENV['CHRONOS_USER']
  opts[:password] = ENV['CHRONOS_PASSWORD'] if ENV['CHRONOS_PASSWORD']
  opts
end

.env_urlObject

Get the chronos url from environment



21
22
23
# File 'lib/chronos.rb', line 21

def env_url
  ENV['CHRONOS_URL']
end

.listObject

list jobs



67
68
69
# File 'lib/chronos.rb', line 67

def list
  connection.get('/scheduler/jobs')
end

.loggerObject

Returns the value of attribute logger.



12
13
14
# File 'lib/chronos.rb', line 12

def logger
  @logger
end

.logger=(value) ⇒ Object

Sets the attribute logger

Parameters:

  • value

    the value to set the attribute logger to.



12
13
14
# File 'lib/chronos.rb', line 12

def logger=(value)
  @logger = value
end

.optionsObject

Get options for connecting to marathon API



40
41
42
# File 'lib/chronos.rb', line 40

def options
  @options ||= env_options
end

.options=(new_options) ⇒ Object

Set new options



51
52
53
54
# File 'lib/chronos.rb', line 51

def options=(new_options)
  @options = env_options.merge(new_options || {})
  reset_connection!
end

.reset_connection!Object

Reset the connection



62
63
64
# File 'lib/chronos.rb', line 62

def reset_connection!
  @connection = nil
end

.start(name) ⇒ Object

start a job



87
88
89
# File 'lib/chronos.rb', line 87

def start(name)
  connection.put("/scheduler/job/#{URI.encode name}")
end

.urlObject

Get the marathon API URL



34
35
36
37
# File 'lib/chronos.rb', line 34

def url
  @url ||= env_url || DEFAULT_URL
  @url
end

.url=(new_url) ⇒ Object

Set a new url



45
46
47
48
# File 'lib/chronos.rb', line 45

def url=(new_url)
  @url = new_url
  reset_connection!
end