Created
July 28, 2018 13:26
-
-
Save manoelneto/0dd47dd31d912ddfae363e03d8fa988c to your computer and use it in GitHub Desktop.
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
# perceba que agora o metodo está no plural | |
def process_messages messages | |
# vou ter um hash de: client_id: mensagens | |
messages_by_client = messages.group_by do |message| | |
message["client_id"] | |
end | |
messages_by_client.each do |client_id, messages| | |
# como as mensagens estão agrupadas por cliente, preciso pegar apenas os triggers | |
# do cliente de qualquer mensagem | |
triggers = find_triggers_for_client messages.first | |
messages.each do |message| | |
process_message message, triggers | |
end | |
end | |
end | |
def process_message message, triggers | |
# Aqui eu não preciso mais filtrar os triggers pelo cliente | |
triggers = filter_triggers_in_batch message, triggers | |
triggers = triggers.select do |trigger| | |
# verifica se passa nos ultimos filtros | |
trigger.pass_filters? message | |
end.each do |trigger| | |
# executa as ações | |
publish_to_actions_queue trigger, message | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment