osmirbresciani

osmirbresciani

Problem with Oban Workers

I’m developing process automation using oban, but lately I’m facing a problem with updating the code in worker modules.

Whenever I update the module for the worker and start the application, the worker keeps processing jobs as if the code hasn’t been updated. In the worker module, even if I comment out everything that is in the perform(_job) function, the oban continues processing the code that was there. It’s like there’s some kind of cache.

ie.:

this job successfully run:

  @impl Oban.Worker
  def perform(_job) do
    Users.list_users_from_last_day()
    |> Emails.digest_email()
    |> Mailer.deliver_now()

if I changes to:

  @impl Oban.Worker
  def perform(_job) do
    IO.inspect("Nothing to do")

the previous job before the change continues to run successfully. Or if I change the tags for testing, they don’t change in db.

Another common error I’m experiencing is the “unknown worker”- oban error, when I change the worker set in config.exs.

I’ve already tried:

  • clear cache files → sudo rm -rf ./_build ./.elixir_ls ./mix.lock ~/.hex/cache.ets
  • recompile the app from scratch

Running through IEX or running the automated tests, everything works. The problem only occurs in homolog environment

Could anyone give a help on how to debug this problem?

Marked As Solved

osmirbresciani

osmirbresciani

updating:

Running oban tests using iex in dev:

  iex> Oban.Worker.from_string("Oban.Integration.Worker")
  {:ok, Oban.Integration.Worker}

  iex> defmodule NotAWorker, do: []
  ...> Oban.Worker.from_string("NotAWorker")
  {:error, %RuntimeError{message: "module is not a worker: NotAWorker"}}

  iex> Oban.Worker.from_string("RandomWorker")
  {:error, %RuntimeError{message: "unknown worker: RandomWorker"}}

Everything worked as it should. The module is recognized. I also run the app in production with oban workers and it worked!! The error only continues running locally in dev environment: iex -S mix phx.server and mix phx.server where the code doesn’t update and I get the error: unknown worker from oban.

I believe it’s a problem in the compilation of my code because when I start the app, I sometimes get the error: ** (File.Error) could not write to file "/home/desktop/projects/api/_build/dev/lib/api/ebin/my-worker-file.beam": permission denied, but running with release in prod works. Thanks for the help, I’ll search for the cause of this compilation issue.

Also Liked

egze

egze

Curious to find out more what you’re building. We are also starting a process automation project soon. Would appreciate if you drop me a message.

lud

lud

Can you call the perform/1 function directly from a test to ensure that it works as intended?

lud

lud

That’s strange.

As a workaround you can always delete the _build directory (or just _build/dev/lib/myapp).

Also you can call :code.which(MyWorker) to retrieve the beam file for your module so you could check the modification time of this file, or load it in an iex session to check stuff.

Last Post!

Aktaeon

Aktaeon

Hahaha, never mind, there was an old cache but it was because I am using gitlab review environments which after a git push automatically run. So what was happening that the server for some reason always was the first to be able to get the job and send out the email and not my dev laptop. Leaving this as it might save someone else from wasting two hours trying to figure out what was causing this :-/

Where Next?

Popular in Questions Top

vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

Other popular topics Top

hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31525 112
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42576 114
New

We're in Beta

About us Mission Statement