Oban marks tasks immediately as completed if inserted within Enum.map

I am trying to insert jobs like this:

records = RecordApi.Records.Record |> where([c], is_nil(c.google_lookup_instagrams_processed_at)) |> limit(5) |> RecordApi.Repo.all()

Enum.map(records , fn record  -> %{id: record.id} |> RecordApi.Jobs.GoogleLookupInstagram.new() |> Oban.insert() end)

The problem is that Oban processes only one row, the 4 other rows get status completed immediately.

Probably caused by attempted_by, since the ones getting same value for this field are not processed.

What to do? thank you.

Jobs are inserted in the available or scheduled state and only change when processed. If the job’s state is set to completed and it has an attempted_by value, that means it was ran.

Whether jobs are inserted one at a time, in a “loop” like Enum.map, or via Oban.insert_all makes no difference to how jobs are executed.

Consider enabling the default logger to see a record of when jobs start and stop: Preparing for Production — Oban v2.18.0

3 Likes

@sorentwo

Thank you for the explanation. Indeed, I have just restarted the OS and all is working now as expected. Seems I had a process running in background that interfered.