Spawn an asynchronous worker

Almost that, except you should start the task under a supervision tree:

children = [
  {Task.Supervisor, name: MyApp.TaskSupervisor}
]

Task.Supervisor.start_child(MyApp.TaskSupervisor, fn ->
  IO.puts "I am running in a task"
end)

From the docs:

Note that the spawned process is not linked to the caller, but only to the supervisor. This command is useful in case the task needs to perform side-effects (like I/O) and you have no interest on its results nor if it completes successfully.

But if you’re on PostreSQL, then consider Oban. It’s awesome.