tjchambers

tjchambers

Oban testing with elixir and python

I am trying to bridge Elixir and Python, and am getting a failure in testing.

   ** (RuntimeError) unknown worker: agr.__main__.AgrWorker
     code: Oban.Testing.with_testing_mode(:inline, fn ->
     stacktrace:
       (oban 2.21.1) lib/oban/queue/executor.ex:109: Oban.Queue.Executor.resolve_worker/1
       (oban 2.21.1) lib/oban/queue/executor.ex:74: Oban.Queue.Executor.call/1
       (oban 2.21.1) lib/oban/engines/inline.ex:104: Oban.Engines.Inline.execute_job/2
       (oban 2.21.1) lib/oban/engines/inline.ex:37: Oban.Engines.Inline.insert_job/3
       (oban 2.21.1) lib/oban/engine.ex:216: anonymous fn/4 in Oban.Engine.insert_job/3
       (oban 2.21.1) lib/oban/engine.ex:404: anonymous fn/3 in Oban.Engine.with_span/4

As far as I can tell using code I have deduced my Python worker is “_main_.AgrWorker" however no matter what I put in as a worker name, I get an error in finding the worker on the elixir side when I run my tests. I am running my test inline for a worker (an Elixir module). This elixir module enqueues a job which is for a Python class “AgrWorker”. It “seems” like what is happening is that because the test is “inline” on th Elixir side, the subsequent enqueue expects any subsequent Oban Job to also be in Elixir - i.e. it is looking for the Elixir worker to run.

I am not sure how or why it would be able to know about all of the Python Workers available.

Can anyone help me with why this makes any sense?

Most Liked

kokolegorille

kokolegorille

If You don’t mind I have switched the OP section from Question to Oban.

Last Post!

sorentwo

sorentwo

Oban Core Team

That’s correct. The inline engine runs jobs immediately, as they are inserted, and it never touches the database. In that case the job is referencing a Python class that’s not available as an Elixir module, and there’s no worker module to load and run.

It wouldn’t. In fact, Oban in Elixir isn’t aware that Oban in Python exists at all. They speak the same “language” via the database schema and pubsub (Bridging Elixir and Python with Oban · Oban Pro), but they can’t interchangeably execute code.

You’ll need to use manual mode to test enqueuing Python jobs, and ensure they’re inserted into a queue that isn’t ran by your Elixir app. Something like this:

# config/test.exs
config :my_app, Oban,
  queues: [
    default: 10, # runs in elixir
  ],
  testing: :manual,
  ...

# some_test.exs

args
|> Oban.Job.new(queue: :bridge, worker: "_main_.AgrWorker")
|> Oban.insert!()

# Assert that it's enqueued, don't run it
assert_enqueued queue: :bridge, worker: "_main_.AgrWorker"

The jobs won’t execute during tests, but you can be sure they’re in the bridge queue.

Note that Ecto tests run in a sandbox, essentially a transaction, and whatever is inserted during a test is invisible to all other processes or connections. The only way to test end-to-end is without the sandbox enabled an with manual cleanup steps, which may be worth it eventually, but it’s not where I’d start.

Where Next?

Popular in Questions Top

hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

Other popular topics Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
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
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New

We're in Beta

About us Mission Statement