Class: BackgroundQueue::ServerLib::Config

Inherits:
Config
  • Object
show all
Defined in:
lib/background_queue/server_lib/config.rb

Overview

The server configuration which is stored as a YAML file containing a root key for each environments configuration, much like database.yml.

Example

development:
  address: 
    host: 127.0.0.1
    port: 3000
  workers: 
    - http://127.0.0.1:801/background_queue
  secret: this_is_used_to_make_sure_it_is_secure
  task_file: /path/to/file/to/save/running/tasks
production:
  address: 
    host: 0.0.0.0
    port: 3000
  connections_per_worker: 10
  workers: 
    - http://192.168.3.1:801/background_queue
    - http://192.168.3.2:801/background_queue
  secret: this_is_used_to_make_sure_it_is_secure
  system_task_options:
    domain: the_default_domain
  jobs
    - cron: "0 22 * * 1-5"
      worker: some_worker
      args: 
        arg1: 22
        arg2: "hello"

Defined Under Namespace

Classes: Address, Job, Worker

Constant Summary

Constants inherited from Config

Config::DEFAULT_PORT

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Config

load_file, load_string, load_yaml

Constructor Details

#initialize(workers, secret, address, connections_per_worker, jobs, system_task_options, task_file) ⇒ Config

do not call this directly, use a load_* method



192
193
194
195
196
197
198
199
200
# File 'lib/background_queue/server_lib/config.rb', line 192

def initialize(workers, secret, address, connections_per_worker, jobs, system_task_options, task_file)
  @workers = workers
  @secret = secret
  @address = address
  @connections_per_worker = connections_per_worker
  @jobs = jobs
  @system_task_options = system_task_options
  @task_file = task_file
end

Instance Attribute Details

#addressObject (readonly)

the address to listen on



52
53
54
# File 'lib/background_queue/server_lib/config.rb', line 52

def address
  @address
end

#connections_per_workerObject (readonly)

the number of connections allowed for each active worker



55
56
57
# File 'lib/background_queue/server_lib/config.rb', line 55

def connections_per_worker
  @connections_per_worker
end

#jobsObject (readonly)

an array of scheduled jobs



49
50
51
# File 'lib/background_queue/server_lib/config.rb', line 49

def jobs
  @jobs
end

#secretObject (readonly)

the shared secret to make sure the worker is not called directly from the internet



43
44
45
# File 'lib/background_queue/server_lib/config.rb', line 43

def secret
  @secret
end

#system_task_optionsObject (readonly)

used for polling task and jobs. Should include a domain entry if your worker uses domain lookups



58
59
60
# File 'lib/background_queue/server_lib/config.rb', line 58

def system_task_options
  @system_task_options
end

#task_fileObject (readonly)

a path where tasks are saved when the server shuts down, and loaded when it starts back up. This will store tasks being lost when restarting the server.



46
47
48
# File 'lib/background_queue/server_lib/config.rb', line 46

def task_file
  @task_file
end

#workersObject (readonly)

the list of workers that are called using http



39
40
41
# File 'lib/background_queue/server_lib/config.rb', line 39

def workers
  @workers
end

Class Method Details

.load_hash(env_config, path) ⇒ Object

load the configration using a hash just containing the environment



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/background_queue/server_lib/config.rb', line 61

def self.load_hash(env_config, path)
  BackgroundQueue::ServerLib::Config.new(
    build_worker_entries(env_config, path),
    get_secret_entry(env_config, path),
    get_address_entry(env_config, path),
    get_connections_per_worker_entry(env_config, path),
    get_jobs_entry(env_config, path),
    get_system_task_options_entry(env_config, path),
    get_task_file_entry(env_config, path)
  )
end