Sha256: 5f8892cbe55d5f161b64b096fb5501bb0cdfd2e295552ace51e4b36d8331b53e

Contents?: true

Size: 1.48 KB

Versions: 1

Compression:

Stored size: 1.48 KB

Contents

require 'barbeque_client/configuration'
require 'barbeque_client/client'
require 'barbeque_client/version'
require 'barbeque_client/executor'

begin
  require 'rails'
rescue LoadError
else
  require 'barbeque_client/railtie'
end

module BarbequeClient
  class << self
    def configure
      yield config
    end

    def config
      @config ||= Configuration.new
    end

    # @param  [String] job     - Job name to enqueue.
    # @param  [Object] message - An object which is serializable as JSON.
    # @param  optional [String] queue - A queue name to enqueue a job.
    # @param  optional [Integer] delay_seconds - Message timer of SQS.
    # @return [Hashie::Mash] resonse - { message_id: String, status: String }
    def enqueue(job:, message:, queue: nil, delay_seconds: nil)
      response = client.create_execution(
        job:     job,
        message: message,
        queue:   queue,
        delay_seconds: delay_seconds,
      )
      response.body
    end

    # @param  [String] message_id - Job execution's message_id to check status
    # @return [String] status     - Job execution's status like "success", "pending", "failure", ...
    def status(message_id:)
      response = client.execution(message_id: message_id)
      response.body.status
    end

    def client
      @client ||= Client.new(
        application:   config.application,
        default_queue: config.default_queue,
        endpoint:      config.endpoint,
        tracing:       config.tracing,
      )
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
barbeque_client-0.10.0 lib/barbeque_client.rb