Integrating with Phoenix App?
damien-roche opened this issue · comments
It's fairly straightforward to add the supervisor to the array of supervisors to start with a Phoenix app, but I don't want to start a Phoenix server along with my workers. I want them both separated, and yet still make use of my app logic from within the workers -- exactly as Sidekiq works when loading in a Rails app.
So I tried this with Phoenix. I have a simple condition in my application.ex
config that uses supervisor(Verk.Supervisor, [])
if an ENV variable is set (APP_WORKER
), else it loads default web supervisors. This works great for separating the processes.
However, I still need to kick off jobs from within my app. I tried to enqueue a job though the Verk.Supervisor
was not loaded and it complained that it couldn't find the gen server Verk.Redis
:
exited in: :gen_server.call(Verk.Redis, {:commands, [["LPUSH", "queue:default"......
So I added that to my default web workers, and now when attempting to enqueue a job within my web app it says:
function Verk.Redis.start_link/0 is undefined (module Verk.Redis is not available)
Now, I do apologise - I am new to the Elixir ecosystem, and I don't mean to dump simple module loading questions here, but I would appreciate any pointers on how I might load in the required code to simply enqueue jobs through redis without the rest of it (which will be handled in a separate worker process).
Next time I'll read the code first :/ .. seems like I'll just need to mimic a little setup from the init
in Verk.Supervisor
! Works now.
https://github.com/edgurgel/verk/blob/master/lib/verk/supervisor.ex#L20
Though I would be interested to hear whether I might be creating any sketchy points of failure here.