module Contentful::Scheduler

Constants

DEFAULT_ENDPOINT
DEFAULT_LOGGER
DEFAULT_PORT
VERSION

Public Class Methods

config() click to toggle source
# File lib/contentful/scheduler.rb, line 32
def self.config
  @@config
end
config=(config) click to toggle source
# File lib/contentful/scheduler.rb, line 17
def self.config=(config)
  fail ':redis configuration missing' unless config.key?(:redis)
  fail ':spaces configuration missing' unless config.key?(:spaces)
  config[:spaces].each do |space, data|
    fail ":management_token missing for space: #{space}" unless data.key?(:management_token)
  end

  config[:port] = (ENV.key?('PORT') ? ENV['PORT'].to_i : DEFAULT_PORT) unless config.key?(:port)
  config[:logger] = DEFAULT_LOGGER unless config.key?(:logger)
  config[:endpoint] = DEFAULT_ENDPOINT unless config.key?(:endpoint)

  ::Resque.redis = config[:redis].dup
  @@config ||= config
end
start(config = {}) { |config| ... } click to toggle source
# File lib/contentful/scheduler.rb, line 36
def self.start(config = {})
  fail "Scheduler not configured" if self.config.nil? && !block_given?

  if block_given?
    yield(config) if block_given?
    self.config = config
  end

  ::Contentful::Webhook::Listener::Server.start do |config|
    config[:port] = self.config[:port]
    config[:logger] = self.config[:logger]
    config[:endpoints] = [
      {
        endpoint: self.config[:endpoint],
        controller: ::Contentful::Scheduler::Controller,
        timeout: 0
      }
    ]
  end.join
end