maz
I’d like to queue the mailing of an email via Bamboo but this code results in a Protocol.UndefinedError because it seems that Oban doesn’t know how to encode the %Bamboo.Email{} struct that contains the email body etc. Am I doing this correctly? If I am, I don’t understand why if Oban needs to encode the data which it’s about to queue. Wouldn’t every struct be unique and therefore there should be a way to handle this in the general case?
caller code:
defmodule Elijah.Emails do
import Bamboo.Email
use Bamboo.Phoenix, view: ElijahWeb.EmailView
alias Elijah.Accounts.Jobs.WelcomeEmail
@sender_no_reply {"Elijah", "no-reply@elijah.app"}
@supported_locales ~w(en)
def welcome_email(%{user: user, url: url}) do
base_email()
|> subject("Elijah - Welcome!")
|> to(user.email)
|> assign(:user, user)
|> assign(:url, url)
|> render_i18n(:welcome_email)
|> premail()
|> WelcomeEmail.new()
|> Oban.insert()
end
...
Oban job:
defmodule Elijah.Accounts.Jobs.WelcomeEmail do
use Oban.Worker, queue: :mailer, max_attempts: 4
@impl Oban.Worker
def perform(email, _job) do
# IO.inspect(email)
email
|> Elijah.Mailer.deliver_now()
:ok
end
end
stack:
(jason 1.2.1) lib/jason.ex:199: Jason.encode_to_iodata!/2
(postgrex 0.15.5) lib/postgrex/type_module.ex:897: Postgrex.DefaultTypes.encode_params/3
(postgrex 0.15.5) lib/postgrex/query.ex:75: DBConnection.Query.Postgrex.Query.encode/3
(db_connection 2.2.2) lib/db_connection.ex:1148: DBConnection.encode/5
(db_connection 2.2.2) lib/db_connection.ex:1246: DBConnection.run_prepare_execute/5
(db_connection 2.2.2) lib/db_connection.ex:539: DBConnection.parsed_prepare_execute/5
(db_connection 2.2.2) lib/db_connection.ex:532: DBConnection.prepare_execute/4
(postgrex 0.15.5) lib/postgrex.ex:214: Postgrex.query/4
(ecto_sql 3.4.5) lib/ecto/adapters/sql.ex:630: Ecto.Adapters.SQL.struct/10
(ecto 3.4.6) lib/ecto/repo/schema.ex:661: Ecto.Repo.Schema.apply/4
(ecto 3.4.6) lib/ecto/repo/schema.ex:263: anonymous fn/15 in Ecto.Repo.Schema.do_insert/4
(ecto_sql 3.4.5) lib/ecto/adapters/sql.ex:875: anonymous fn/3 in Ecto.Adapters.SQL.checkout_or_transaction/4
(db_connection 2.2.2) lib/db_connection.ex:1427: DBConnection.run_transaction/4
(oban 2.1.0) lib/oban/query.ex:47: Oban.Query.fetch_or_insert_job/2
(elijah 0.1.0) lib/elijah/accounts/user_notifier.ex:17: Elijah.Accounts.UserNotifier.deliver_confirmation_instructions/2
(elijah 0.1.0) lib/elijah_web/controllers/user_registration_controller.ex:17: ElijahWeb.UserRegistrationController.create/2
(elijah 0.1.0) lib/elijah_web/controllers/user_registration_controller.ex:1: ElijahWeb.Us (truncated)
thanks for any help,
Michael
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex










Showing Posts 1 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
chulkilee
Note that
So just need to convert the struct to the map. Please note that if your struct is from ecto schema, the struct has more internal state and metadata for ecto…
There are two approaches
In most cases I prefer the former for following reasons
Here is a pattern I’m using:
You can see:
Whether to pass only reference or the full args - it really depends. For example, if you need the exact information when job is placed - then you should pass that information as job args, instead of delaying fetching them by job worker.
maz
Yeah thanks for the detailed explanation. I get it now, Oban should be treated like a “pass-through”. I wasn’t quite understanding it’s design/usage but your reply helped a lot. The email worked.
For others with similar problems, here is my code.
chulkilee
Storing Elixir term has its own pros and cons. For the illusion of “transparently passing elixir term”… here are downsides:
For your information:
byteanotjsonb)chasers
FWIW you can encode Erlang types into JSON by doing:
When decoding just do:
I have a
Propertystruct with some nested structures with some tuples in them. It is, I think, cleaner to do this than to do a custom JSON encoder / decoder.Note, that am pulling out the
property.idandproperty.addressfor the Oban args so I can unique the job on property ID and inspect the address if something goes wrong.I could store what I have of the
propertyin the db first and reference it with the id, but I was unable to do that because of some other requirements. With this I’m able to just pass it around in Oban, and finally store it when I’m ready.Not sure where this breaks down but it’s working for me for now.