osmirbresciani

osmirbresciani

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?

Showing Posts 1 to 10

sorentwo

sorentwo

Oban Core Team

It seems like you’re experiencing a combination of multiple versions of a module in memory, and lingering data in the database. Is it possible you have another app instance running somewhere?

osmirbresciani

osmirbresciani OP

There are no instances running in the background. Running via docker or locally without the docker, is the same problem. The only thing that works is updating the crontab. Do you have any test suggestions I can do to check if it’s something in the app’s startup config?

Ty!

sorentwo

sorentwo

Oban Core Team

There isn’t anything in the config or worker definitions that would prevent code reloading. As far as Oban knows, the worker is a string that represents a module name. When the job executes it looks up the module name and executes the job—the module definition isn’t stored in the database.

lud

lud

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

osmirbresciani

osmirbresciani OP

Yes, it works. The “bug” appears when running mix phx.server with MIX_ENV=dev

gabriel137

gabriel137

Lately I’ve had an error with it a bit similar, after many executions of jobs it stops showing any debug messages for me, but the work runs normally, this in my dev environment, in production it doesn’t happen.

sorentwo

sorentwo

Oban Core Team

This sounds like the telemetry handler for logging gets detached in development. There will be a warning in your logs stating that the handler encountered an error if that’s the case.

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.

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.

osmirbresciani

osmirbresciani OP

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.

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
peck
Hi everyone. My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
bradley
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
Alvinkariuki
How Can I Optimise Compile Time Dependencies I have been building an elixir application for about 2 years now. Many modules and files ha...
New

Other Trending Topics Top

budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews