I am new to Phoenix and Elixir. I want to add to Chat app a background job that should run once a minute, get data from another server and broadcast it to rooms. How can I do something like this in Phoenix?
Asked
Active
Viewed 848 times
2
-
2A simple way to run background job periodically - https://stackoverflow.com/questions/32085258/how-to-run-some-code-every-few-hours-in-phoenix-framework Broadcasting - https://hexdocs.pm/phoenix/Phoenix.Channel.html#broadcast/3 – NoDisplayName Apr 26 '16 at 05:10
-
Thanks a lot. Just another question, where in code i have to start a job, and how can i pass socket to it ? – s0ld13r Apr 26 '16 at 06:15
-
2You can use `MyApp.Endpoint.broadcast` (documented about half way down on https://hexdocs.pm/phoenix/Phoenix.Endpoint.html) to broadcast to a channel. – Gazler Apr 26 '16 at 07:38
-
@JustMichael you should post that as an answer. – Onorio Catenacci Apr 26 '16 at 13:44
1 Answers
0
A simple way to implement background jobs was offered by Jose Valim here.
And for broadcasting, you can use MyApp.Endpoint.broadcast()
as Gazler pointed out in the comments.

NoDisplayName
- 15,246
- 12
- 62
- 98