-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed processors to use appropriate config
- Loading branch information
Showing
16 changed files
with
211 additions
and
188 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
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,34 @@ | ||
module Circuitry | ||
module Pool | ||
class << self | ||
def <<(processor) | ||
raise ArgumentError, 'processor must be a Circuitry::Processor' unless processor.is_a?(Circuitry::Processor) | ||
pool << processor | ||
end | ||
|
||
def flush | ||
while (processor = pool.shift) | ||
processor.wait | ||
end | ||
end | ||
|
||
def size | ||
pool.size | ||
end | ||
|
||
def empty? | ||
pool.empty? | ||
end | ||
|
||
def any? | ||
pool.any? | ||
end | ||
|
||
private | ||
|
||
def pool | ||
@pool ||= [] | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,47 @@ | ||
module Circuitry | ||
module Processor | ||
def process(&_block) | ||
raise NotImplementedError, "#{self} must implement class method `process`" | ||
class Processor | ||
attr_reader :config, :block | ||
|
||
def initialize(config, &block) | ||
raise ArgumentError, 'no block given' unless block_given? | ||
|
||
self.config = config | ||
self.block = block | ||
end | ||
|
||
def flush | ||
raise NotImplementedError, "#{self} must implement class method `flush`" | ||
def process | ||
raise NotImplementedError, "#{self} must implement instance method `process`" | ||
end | ||
|
||
def on_exit | ||
Circuitry.subscriber_config.on_async_exit | ||
def wait | ||
raise NotImplementedError, "#{self} must implement instance method `wait`" | ||
end | ||
|
||
protected | ||
|
||
def safely_process | ||
yield | ||
def safely_process(&block) | ||
block.call | ||
rescue => e | ||
logger.error("Error handling message: #{e}") | ||
error_handler.call(e) if error_handler | ||
end | ||
|
||
def pool | ||
@pool ||= [] | ||
ensure | ||
on_exit.call if on_exit | ||
end | ||
|
||
private | ||
|
||
attr_writer :config, :block | ||
|
||
def logger | ||
Circuitry.subscriber_config.logger | ||
config.logger | ||
end | ||
|
||
def error_handler | ||
Circuitry.subscriber_config.error_handler | ||
config.error_handler | ||
end | ||
|
||
def on_exit | ||
config.on_async_exit | ||
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
Oops, something went wrong.