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
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
Kia ora,
We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
Hi all, I wanted to ask how the community is dealing with post-release steps.
Today we have Ecto migrations, which make sure that the db...
New
Hello,
I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New
Other Trending Topics
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
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










Showing Posts 1 to 4- Show Best Posts
- Show All Posts (oldest first)
- Show All Posts (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.