Skip to content
This repository has been archived by the owner on Apr 5, 2023. It is now read-only.

Commit

Permalink
feat: add config to broker
Browse files Browse the repository at this point in the history
  • Loading branch information
eHattori committed Apr 13, 2022
1 parent 44efd09 commit 80a06e2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
23 changes: 23 additions & 0 deletions lib/pipefy_message/providers/aws_broker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,34 @@
module PipefyMessage
module Providers
class AwsBroker < Broker

@@default_options = {
access_key_id: (ENV["AWS_ACCESS_KEY_ID"] || "foo"),
secret_access_key: (ENV["AWS_SECRET_ACCESS_KEY"] || "bar"),
endpoint: (ENV["AWS_ENDPOINT"] || "http://localhost:4566"),
region: (ENV["AWS_REGION"] || "us-east-1"),
stub_responses: (ENV["AWS_CLI_STUB_RESPONSE"] || "true")
}

def initialize(queue_url)

@config = AwsBroker.config_options

Aws.config.update(@config)


@sqs = Aws::SQS::Client.new(region: @config[:region])
require "pry"; binding.pry

@poller = Aws::SQS::QueuePoller.new(queue_url)
@poller.before_request { stop! if user_interrupt == true }
@wait_time_seconds = 10
end

def self.config_options
@@default_options
end

def poller()
## Aws poller
@poller.poll(wait_time_seconds: @wait_time_seconds) do |received_message|
Expand Down
7 changes: 4 additions & 3 deletions spec/worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,25 @@ def poller

class TestWorker
include PipefyMessage::Worker
pipefymessage_options broker: "aws"
pipefymessage_options broker: "aws", queue: "http://localhost:4566/000000000000/pipefy-local-queue"

def perform(message)
puts message
$result = message
end
end

describe "#perform" do
it "should call #perform from child instance when call #perform_async with success" do
allow(TestWorker).to receive(:build_instance_broker).and_return(MockBroker.new)
# allow(TestWorker).to receive(:build_instance_broker).and_return(MockBroker.new)

TestWorker.perform_async
expect($result).to eq "test"
end

it "should call #perform from child instance when call #perform_async with fail(raise a exception)" do
allow(TestWorker).to receive(:build_instance_broker).and_return(MockBrokerFail.new)
expect{ TestWorker.perform_async }.to raise_error
expect{ TestWorker.perform_async }.to raise_error(Exception, /This is an exception/)
end
end

Expand Down

0 comments on commit 80a06e2

Please sign in to comment.