Musings On Matters Elixir, OTP, BEAM, and Phoenix that I couldn't think of a name for that doesn't involve a disgraced president or UDP. Explanation coming soon.
- Designing a large Elixir/Phoenix application
- Deploying it
- The business case for Elixir
- The developer case for Elixir
- A look at when its the best tool
- Extremely technical at an OTP/micro level
- A complete solution to all your woes
- A beckoning for us all to use these new tools with no real reason
Veridian Dynamics has a problem. They are paying far too much to grab customer data for quoting insurance policies in their new property & casualty division through an API. They have reached an agreement with a data provider to get all the raw data they want, but they need to be able to query it via an API.
iex(1)> h String.split
def split(binary)
Divides a string into substrings at each Unicode whitespace occurrence with
leading and trailing whitespace ignored. Groups of whitespace are treated as a
single occurrence. Divisions do not occur on non-breaking whitespace.
defmodule App.CronJob do
use GenServer
def start_link() do
GenServer.start_link(__MODULE__, [])
end
def init([]) do
schedule_work()
{:ok, []}
end
def handle_info(:work, state) do
state = do_work(state)
schedule_work()
{:noreply, state}
end
defp do_work(state) do
2 * 2 # or call some other module/function etc
IO.puts "running"
end
defp schedule_work do
Process.send_after(self(), :work, (60 * 1_000)) # one/minute
end
end
GenServer.call(App.CronJob, [])
From the docs:
Paul Graham, Beating the Averages
An Idea for a Community Initiative