Skip to content

Commit

Permalink
Merge branch 'trunk' into add_rails_generators_182017716
Browse files Browse the repository at this point in the history
  • Loading branch information
saikumar9 authored Jun 11, 2024
2 parents 6bd1b83 + ed23a94 commit 33d7e14
Show file tree
Hide file tree
Showing 47 changed files with 1,261 additions and 257 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
name: Rubocop and Rspec
name: Rspec
on: push

jobs:
rspec:
strategy:
fail-fast: false
matrix:
ruby_version: ['2.6.3', '2.7.5', '3.0.5', '3.1.4', '3.2.2']
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -14,14 +18,14 @@ jobs:
sudo rabbitmqctl set_permissions -p event_source guest ".*" ".*" ".*"
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
ruby-version: ${{ matrix.ruby_version }}
- name: Cache Gems
uses: actions/cache@v1
with:
path: vendor/bundle
key: ${{ runner.os }}-event_source-gems-${{ hashFiles('**/Gemfile.lock') }}-${{ hashFiles('**/Gemfile' ) }}
key: ${{ runner.os }}-${{matrix.ruby_version}}-event_source-gems-${{ hashFiles('**/Gemfile.lock') }}-${{ hashFiles('**/Gemfile' ) }}
restore-keys: |
${{ runner.os }}-event_source-gems-${{ hashFiles('**/Gemfile.lock') }}-${{ hashFiles('**/Gemfile' ) }}
${{ runner.os }}-${{matrix.ruby_version}}-event_source-gems-${{ hashFiles('**/Gemfile.lock') }}-${{ hashFiles('**/Gemfile' ) }}
- name: bundle install
run: |
bundle config path vendor/bundle
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.6.6
3.2.1
54 changes: 7 additions & 47 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
PATH
remote: .
specs:
event_source (0.5.7)
event_source (0.5.8)
addressable (>= 2.8.0)
bunny (>= 2.14)
deep_merge (~> 1.2.0)
dry-configurable (= 0.12.1)
dry-configurable (~> 0.12)
dry-events (~> 0.3)
dry-inflector (~> 0.2)
dry-initializer (~> 3.0)
dry-monads (~> 1.3)
dry-schema (= 1.6.2)
dry-schema (~> 1.6)
dry-struct (~> 1.4)
dry-types (~> 1.5)
dry-validation (~> 1.6)
faraday (~> 1.4.1)
faraday_middleware (~> 1.0)
logging (~> 2.3.0)
mime-types
nokogiri (>= 1.12.5)
nokogiri (>= 1.13.0)
oj (~> 3.11)
ox (~> 2.14)
resque-bus (~> 0.7.0)
typhoeus (~> 1.4.0)

GEM
Expand Down Expand Up @@ -154,8 +153,6 @@ GEM
dry-initializer (~> 3.0)
dry-schema (~> 1.5, >= 1.5.2)
erubi (1.10.0)
et-orbi (1.2.6)
tzinfo
ethon (0.15.0)
ffi (>= 1.15.0)
faker (2.18.0)
Expand All @@ -176,9 +173,6 @@ GEM
faraday_middleware (1.2.0)
faraday (~> 1.0)
ffi (1.15.4)
fugit (1.5.2)
et-orbi (~> 1.1, >= 1.1.8)
raabro (~> 1.4)
globalid (0.5.2)
activesupport (>= 5.0)
hashdiff (1.0.1)
Expand All @@ -200,22 +194,18 @@ GEM
mime-types-data (~> 3.2015)
mime-types-data (3.2021.0901)
mini_mime (1.1.2)
mini_portile2 (2.6.1)
mini_portile2 (2.8.1)
minitest (5.14.4)
mongo (2.14.0)
bson (>= 4.8.2, < 5.0.0)
mongoid (7.3.0)
activemodel (>= 5.1, < 6.2)
mongo (>= 2.10.5, < 3.0.0)
mono_logger (1.1.1)
multi_json (1.15.0)
multipart-post (2.1.1)
mustermann (1.1.1)
ruby2_keywords (~> 0.0.1)
nio4r (2.5.8)
nokogiri (1.12.5)
mini_portile2 (~> 2.6.1)
racc (~> 1.4)
oj (3.13.9)
ox (2.14.5)
parallel (1.20.1)
Expand All @@ -228,11 +218,7 @@ GEM
byebug (~> 11.0)
pry (~> 0.10)
public_suffix (4.0.6)
queue-bus (0.12.0)
multi_json
redis
raabro (1.4.0)
racc (1.6.0)
racc (1.6.2)
rack (2.2.3)
rack-protection (2.1.0)
rack
Expand Down Expand Up @@ -266,30 +252,8 @@ GEM
thor (~> 1.0)
rainbow (3.0.0)
rake (13.0.6)
rbtree (0.4.4)
redis (4.5.1)
redis-namespace (1.8.1)
redis (>= 3.0.4)
rbtree (0.4.6)
regexp_parser (2.1.1)
resque (1.27.4)
mono_logger (~> 1.0)
multi_json (~> 1.0)
redis-namespace (~> 1.3)
sinatra (>= 0.9.2)
vegas (~> 0.1.2)
resque-bus (0.7.0)
queue-bus (>= 0.7, < 1)
resque (>= 1.10.0, < 2.0)
resque-retry
resque-scheduler (>= 2.0.1)
resque-retry (1.7.6)
resque (>= 1.25, < 3.0)
resque-scheduler (~> 4.0)
resque-scheduler (4.5.0)
mono_logger (~> 1.0)
redis (>= 3.3)
resque (>= 1.27)
rufus-scheduler (~> 3.2, < 3.7)
rexml (3.2.5)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
Expand Down Expand Up @@ -321,8 +285,6 @@ GEM
parser (>= 3.0.1.1)
ruby-progressbar (1.11.0)
ruby2_keywords (0.0.4)
rufus-scheduler (3.6.0)
fugit (~> 1.1, >= 1.1.6)
set (1.0.2)
sinatra (2.1.0)
mustermann (~> 1.0)
Expand All @@ -346,8 +308,6 @@ GEM
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
unicode-display_width (2.0.0)
vegas (0.1.11)
rack (>= 1.0.0)
webmock (3.13.0)
addressable (>= 2.3.6)
crack (>= 0.3.2)
Expand Down
7 changes: 3 additions & 4 deletions event_source.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,22 @@ Gem::Specification.new do |spec|
spec.add_dependency 'addressable', '>= 2.8.0'
spec.add_dependency 'bunny', '>= 2.14'
spec.add_dependency 'deep_merge', '~> 1.2.0'
spec.add_dependency 'dry-configurable', '0.12.1'
spec.add_dependency 'dry-configurable', '~> 0.12'
spec.add_dependency 'dry-events', '~> 0.3'
spec.add_dependency 'dry-inflector', '~> 0.2'
spec.add_dependency 'dry-initializer', '~> 3.0'
spec.add_dependency 'dry-monads', '~> 1.3'
spec.add_dependency 'dry-struct', '~> 1.4'
spec.add_dependency 'dry-types', '~> 1.5'
spec.add_dependency 'dry-validation', '~> 1.6'
spec.add_dependency 'dry-schema', '1.6.2'
spec.add_dependency 'dry-schema', '~> 1.6'
spec.add_dependency 'faraday', '~> 1.4.1'
spec.add_dependency 'faraday_middleware', '~> 1.0'
spec.add_dependency 'logging', '~> 2.3.0'
spec.add_dependency 'nokogiri', '>= 1.12.5'
spec.add_dependency 'nokogiri', '>= 1.13.0'
spec.add_dependency 'mime-types'
spec.add_dependency 'oj', '~> 3.11'
spec.add_dependency 'ox', '~> 2.14'
spec.add_dependency 'resque-bus', '~> 0.7.0'
spec.add_dependency 'typhoeus', '~> 1.4.0'

# TODO: Change to development dependency
Expand Down
6 changes: 6 additions & 0 deletions lib/event_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
require 'active_support/all' # TODO: Remove ActiveSupport dependency

require 'event_source/version'
require 'event_source/ruby_versions'
require 'event_source/error'
require 'event_source/inflector'
require 'event_source/logging'
Expand All @@ -30,11 +31,16 @@
require 'event_source/worker'
require 'event_source/publish_operation'
require 'event_source/subscribe_operation'
require 'event_source/message'
require 'event_source/command'
require 'event_source/publisher'
require 'event_source/event'
require 'event_source/subscriber'
require 'event_source/operations/codec64'
require 'event_source/operations/create_message'
require 'event_source/operations/fetch_session'
require 'event_source/operations/build_message_options'
require 'event_source/operations/build_message'

# Event source provides ability to compose, publish and subscribe to events
module EventSource
Expand Down
20 changes: 2 additions & 18 deletions lib/event_source/async_api/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,14 @@ class Message < Dry::Struct
# @!attribute [r] headers
# Schema definition of the application headers. Schema must be of type "object".
# It must not define the protocol headers.
# @return [Schema]
attribute :headers, Schema.meta(omittable: true)
# @return [Types::Any]
attribute :headers, Types::Any.meta(omittable: true)

# @!attribute [r] payload
# Definition of the message payload. It can be of any type but defaults to Schema object
# @return [Types::Any]
attribute :payload, Types::Any.meta(omittable: true)

# @!attribute [r] correlation_id
# Definition of the correlation ID used for message tracing or matching
# @return [String]
attribute :correlation_id do
# @!attribute [r] description
# An optional description of the identifier.
# CommonMark syntax can be used for rich text representation
# @return [String]
attribute :description, Types::String.meta(omittable: true)

# @!attribute [r] location
# Required. A runtime expression that specifies the location of the correlation ID
# @return [String]
attribute :location, Types::String.meta(omittable: true)
end.meta(omittable: true)

# @!attribute [r] schema_format
# A string containing the name of the schema format used to define the message payload.
# If omitted, implementations should parse the payload as a Schema object. Check out the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Operations
module AsyncApiConf
# load channel params from given file path
class LoadPath
send(:include, Dry::Monads[:result, :do, :try])
include Dry::Monads[:result, :do, :try]

def call(path:)
file_io = yield read(path)
Expand All @@ -27,7 +27,7 @@ def read(path)

def deserialize(file_io)
Try do
YAML.safe_load(file_io, [Symbol])
YAML.load(file_io)
end.to_result
end

Expand Down
1 change: 1 addition & 0 deletions lib/event_source/async_api/publish_bindings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class PublishBindings < Dry::Struct
transform_keys(&:to_sym)
attribute :http, ::EventSource::Protocols::Http::PublishBindings.meta(omittable: true)
attribute :amqp, Types::Hash.meta(omittable: true)
attribute :x_amqp_exchange_to_exchanges, Types::Hash.meta(omittable: true)
end
end
end
2 changes: 2 additions & 0 deletions lib/event_source/channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def add_publish_operation(async_api_channel_item)
@channel_proxy.add_publish_operation(async_api_channel_item)
return false unless publish_proxy

@channel_proxy.create_exchange_to_exchange_bindings(publish_proxy) if @connection.protocol == :amqp
operation_id = async_api_channel_item.publish.operationId

logger.info "Adding Publish Operation: #{operation_id}"
Expand All @@ -95,6 +96,7 @@ def add_publish_operation(async_api_channel_item)
# @return [EventSource::SubscribeOperation]
def add_subscribe_operation(async_api_channel_item)
return false unless async_api_channel_item.subscribe

subscribe_proxy =
@channel_proxy.add_subscribe_operation(async_api_channel_item)

Expand Down
7 changes: 5 additions & 2 deletions lib/event_source/configure/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ module Configure
class Config
include EventSource::Logging

def initialize
@log_level = :warn
end

# TODO: add default for pub_sub_root
attr_writer :pub_sub_root, :protocols, :server_configurations
attr_accessor :app_name, :log_level

def load_protocols
@protocols.each do |protocol|
Expand Down Expand Up @@ -164,8 +169,6 @@ def delimiter(protocol)
'.'
end
end

attr_accessor :app_name
end
end
end
1 change: 1 addition & 0 deletions lib/event_source/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ class Error < StandardError
ConnectionNotFound = Class.new(Error)
ServerConfigurationNotFound = Class.new(Error)
ServerConfigurationInvalid = Class.new(Error)
MessageBuildError = Class.new(Error)
end
end
13 changes: 12 additions & 1 deletion lib/event_source/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Event
# @attr_reader [Array<String>] attribute_keys optional list of attributes that must be included in { Payload }
# @attr_reader [String] publisher_path namespaced key indicating the class that registers event for publishing
# @attr_reader [String] payload attribute/value pairs for the message that accompanies the event
attr_reader :attribute_keys, :publisher_path, :payload, :headers, :metadata
attr_reader :attribute_keys, :publisher_path, :payload, :headers, :metadata, :message

HeaderDefaults = {
version: '3.0',
Expand All @@ -26,12 +26,22 @@ def initialize(options = {})
send(:headers=, options[:headers] || {})

@publisher_path = klass_var_for(:publisher_path) || nil
build_message(options) if headers.delete(:build_message)

if @publisher_path.eql?(nil)
raise EventSource::Error::PublisherKeyMissing,
"add 'publisher_path' to #{self.class.name}"
end
end

def build_message(options)
@message = EventSource::Message.new(
headers: options[:headers],
payload: options[:attributes],
event_name: name
)
end

# Set payload
# @overload payload=(payload)
# @param [Hash] payload New payload
Expand Down Expand Up @@ -127,6 +137,7 @@ def set_instance_variable_for(element, value)

def validate_attribute_presence
return unless attribute_keys.present?

gapped_keys = attribute_keys - payload.keys
@event_errors = []
event_errors.push("missing required keys: #{gapped_keys}") unless gapped_keys.empty?
Expand Down
2 changes: 1 addition & 1 deletion lib/event_source/logging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def logger
::Logging.appenders.rolling_file(
'log/event_source.log',
age: 'daily',
level: :debug,
level: EventSource.config.log_level,
keep: 7,
layout: ::Logging.layouts.json
)
Expand Down
Loading

0 comments on commit 33d7e14

Please sign in to comment.