-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executor observer now publishes rich events
- Loading branch information
Showing
11 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ module TestHelpers | |
backend.flush | ||
|
||
TestingLogBackend.instance.clear | ||
PubSub.instance.clear | ||
yield | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
class PubSub | ||
def self.instance | ||
@@instance ||= new | ||
end | ||
|
||
def self.eavesdrop : Array(Mosquito::Backend::BroadcastMessage) | ||
instance.receive_messages | ||
yield | ||
instance.stop_listening | ||
instance.messages | ||
end | ||
|
||
getter messages = [] of Mosquito::Backend::BroadcastMessage | ||
@channel = Channel(Mosquito::Backend::BroadcastMessage).new | ||
@stopping_channel = Channel(Bool).new | ||
|
||
def initialize | ||
end | ||
|
||
def receive_messages | ||
@continue_receiving = true | ||
spawn receive_loop | ||
@channel = Mosquito.backend.subscribe "mosquito:*" | ||
end | ||
|
||
def stop_listening | ||
@continue_receiving = false | ||
end | ||
|
||
def receive_loop | ||
loop do | ||
break unless @continue_receiving | ||
select | ||
when message = @channel.receive | ||
@messages << message | ||
when timeout(500.milliseconds) | ||
end | ||
end | ||
@channel.close | ||
end | ||
|
||
delegate clear, to: @messages | ||
|
||
module Helpers | ||
delegate eavesdrop, to: PubSub | ||
def assert_message_received(matcher : Regex) : Nil | ||
PubSub.instance.messages.find do |message| | ||
matcher === message.message | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Mosquito::Observability::Publisher | ||
getter publish_context : PublishContext | ||
|
||
def publish(data : NamedTuple) | ||
Log.debug { "Publishing #{data} to #{@publish_context.originator}" } | ||
Mosquito.backend.publish( | ||
publish_context.originator, | ||
data.to_json | ||
) | ||
end | ||
|
||
class PublishContext | ||
alias Context = Array(String | Symbol | UInt64) | ||
property originator : String | ||
property context : String | ||
|
||
def initialize(context : Context) | ||
@context = KeyBuilder.build context | ||
@originator = KeyBuilder.build "mosquito", @context | ||
end | ||
|
||
def initialize(parent : self, context : Context) | ||
@context = KeyBuilder.build context | ||
@originator = KeyBuilder.build "mosquito", parent.context, context | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
require "json" | ||
|
||
module Mosquito | ||
alias Id = Int64 | Int32 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters