Skip to content

Commit

Permalink
Merge branch 'trunk' into finish_what_you_started
Browse files Browse the repository at this point in the history
  • Loading branch information
saikumar9 authored Aug 6, 2024
2 parents 0016215 + 7fa9b28 commit 27d63f7
Show file tree
Hide file tree
Showing 31 changed files with 956 additions and 240 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/downstream.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Downstream

on:
workflow_dispatch:
branches:
- trunk
push:
branches:
- trunk

jobs:
check-dependencies:
runs-on: ubuntu-latest
steps:
- name: Bundle Dependency Checks
uses: convictional/trigger-workflow-and-wait@v1.6.1
with:
owner: ideacrew
repo: ic_dependency_jamboree
github_token: ${{ secrets.GH_PAT }}
workflow_file_name: test_bundle.yml
ref: trunk
propagate_failure: false

2 changes: 1 addition & 1 deletion .github/workflows/rspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby_version: ["2.7.5", "3.0.5", "3.1.4", "3.2.2"]
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 Down
46 changes: 3 additions & 43 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
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)
Expand All @@ -21,7 +21,6 @@ PATH
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 Down Expand Up @@ -207,15 +201,11 @@ GEM
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.14.2)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
oj (3.13.9)
ox (2.14.5)
parallel (1.20.1)
Expand All @@ -228,10 +218,6 @@ 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.2)
rack (2.2.3)
rack-protection (2.1.0)
Expand Down Expand Up @@ -267,29 +253,7 @@ GEM
rainbow (3.0.0)
rake (13.0.6)
rbtree (0.4.6)
redis (4.5.1)
redis-namespace (1.8.1)
redis (>= 3.0.4)
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
5 changes: 2 additions & 3 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.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
5 changes: 5 additions & 0 deletions lib/event_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,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
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
37 changes: 37 additions & 0 deletions lib/event_source/message.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# frozen_string_literal: true

require "forwardable"

module EventSource
# Construct async api message object
class Message
extend Forwardable

def initialize(options = {})
message_options = build_message(options)
@message = create_message(message_options)
end

def_delegators :@message, :payload, :headers

private

def build_message(options)
result = EventSource::Operations::BuildMessageOptions.new.call(options)
unless result.success?
raise EventSource::Error::MessageBuildError,
"unable to build message options due to #{result.failure}"
end
result.success
end

def create_message(options)
result = EventSource::Operations::CreateMessage.new.call(options)
unless result.success?
raise EventSource::Error::MessageBuildError,
"unable to create message due to #{result.failure}"
end
result.success
end
end
end
31 changes: 31 additions & 0 deletions lib/event_source/operations/build_message.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

require "dry/monads"
require "dry/monads/do"

module EventSource
module Operations
# create message
class BuildMessage
include Dry::Monads[:result, :do]

def call(params)
values = yield build_options(params)
message = yield create_message(values)

Success(message)
end

private

def build_options(params)
result = BuildMessageOptions.new.call(params)
result.success? ? result : Failure(result.errors.to_h)
end

def create_message(values)
CreateMessage.new.call(values)
end
end
end
end
Loading

0 comments on commit 27d63f7

Please sign in to comment.