Packages
This is a GenServer-ish implementation of a Service watcher. A process that is designed to poll service state every given number of miliseconds and perform due actions in case it is not in designated state. The process is also capable of sending notifications to the configured recipient in Slack.
Current section
Files
Jump to
Current section
Files
lib/management_commands_processor.ex
defmodule ManagementCommandsProcessor do
def process_command(%ReceiverMessage{payload: payload}) do
decoded_message = payload |> Poison.decode!
function = decoded_message["function"] |> String.to_atom
args = decoded_message["args"]
result = apply Service.Watcher, function, args
result_string = result
IO.puts "result: #{result_string}"
reply_to = decoded_message["reply_to"]
if reply_to do
IO.puts "Going to reply to #{reply_to}"
prefix = (if mention = decoded_message["mention"], do: mention <> " ", else: "")
IO.puts "Prefix is #{prefix}"
payload = "#{prefix}#{result_string}"
IO.puts "Payload message is #{payload}"
Service.Watcher.send_message(payload, reply_to)
end
result
end
def execute_command(command) do
function = command["function"] |> String.to_atom
args = command["args"]
result = apply Service.Watcher, function, args
result_string = result
IO.puts "result: #{result_string}"
reply_to = command["reply_to"]
if reply_to do
IO.puts "Going to reply to #{reply_to}"
prefix = (if mention = command["mention"], do: mention <> " ", else: "")
IO.puts "Prefix is #{prefix}"
payload = "#{prefix}#{result_string}"
IO.puts "Payload message is #{payload}"
Service.Watcher.send_message(payload, reply_to)
end
end
end