Sha256: d1615e98bc99149be1990aa7c168bd220174183cb60a6ed47ad63e8937279437

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

require 'contentful/webhook/listener'

module ContentfulMiddleman
  class WebhookHandler < Contentful::Webhook::Listener::Controllers::Wait
    def perform(*)
      logger.info 'Webhook Received - Waiting for rebuild'
      super
      logger.info 'Rebuilding'
      system('bundle exec middleman contentful --rebuild')
    end

    def self.start(options)
      Contentful::Webhook::Listener::Server.start do |config|
        config[:endpoints] = [{
          endpoint: '/receive',
          timeout: options.webhook_timeout,
          controller: ::ContentfulMiddleman::WebhookHandler
        }]
        logger = Logger.new(STDOUT)
        logger.level = Logger::INFO
        logger.formatter = proc do |severity, datetime, progname, msg|
          date_format = datetime.strftime("%Y-%m-%d %H:%M:%S")
          if severity == "INFO"
            "Webhook Server: #{msg}\n"
          else
            "[#{date_format}] #{severity} (#{progname}): #{msg}\n"
          end
        end
        config[:logger] = logger
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
contentful_middleman-1.2.0 lib/contentful_middleman/webhook_handler.rb