Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- defmodule KinesisServer.Worker do
- use GenServer
- alias KinesisServer.Writer
- def start_link(opts \\ []) do
- GenServer.start_link(__MODULE__, Writer.new(opts))
- end
- @impl true
- def init(init_arg) do
- Process.flag(:trap_exit, true)
- {:ok, init_arg}
- end
- def write(record) do
- :poolboy.transaction(:kinesis_writer_pool, fn pid ->
- GenServer.cast(pid, {:write, record})
- end)
- end
- @impl true
- def handle_cast({:write, record}, state) do
- {:noreply, Writer.write(state, record)}
- end
- @impl true
- def terminate(reason, state) do
- Writer.flush(state)
- :shutdown
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement