### Precheck
- Do a quick search and make sure the bug has not yet been reporte…d
- For support, favor using the Elixir Forum, Slack, IRC, etc.
- Be friendly and polite!
### Environment
- Oban Version 2.10
- PostgreSQL 11
- Elixir 1.17 OTP 26.3
### Current Behavior
I have crossed a issue before using Oban and **case pattern matching**, this doesnt important now (I dont even remember what it was properly), my functions wasnt being called and I couldnt find why, after debugging a bit I found the problem (it was in another module return), so I changed to strict using with pattern matching to avoid the same issue, explicity treating piece by piece of the job code so if fails a gain, I will know where. Today I crossed something familiar even with **WITH** CLAUSES
My Oban Job
```
defmodule Testespay.Oban.PubkeyCheckWorker do
use Oban.Worker, queue: :pending_keys
alias Testespay.Genservers.ApiLoadBalancerBlockchain
alias Testespay.Resources.CompareRealm
alias Testespay.Oban.RequestBalanceFileSolana
alias Testespay.DataLayer.MnesiaPendingContractsDomain
require Logger
@snooze_time 3
@target_max_retrys 15
@allowed_retrys 30 ## retrys que incluem quando a request não foi feita corretamente
@impl Oban.Worker
def perform(%Oban.Job{attempt: _attempt, meta: _meta} = job) do
Logger.debug("initing job....")
contract_data = job.args["contract"]
addres = contract_data["pubkey"]
target_value = contract_data["amount"]
job_should_continue(address)
end
def main_function(address, target_value) do
case perform_request(address) do
{:ok, response_value}->
MnesiaPendingContractsDomain.att_ok_trys(address)
case handle_check_balance(response_value, target_value) do
:paid -> :ok
{:snooze, @snooze_time} -> {:snooze, @snooze_time}
end
{:error, :rate_limit} ->
MnesiaPendingContractsDomain.att_failed_retrys(address)
{:error, _reason} -> {:snooze, @snooze_time}
end
end
def handle_check_balance(response_value, target_value) when response_value > 0 do
Logger.debug("-----into handle check balance")
result = CompareRealm.compare_2_numbers(response_value, target_value)
case result do
{:ok, :eq} ->
:paid
{:ok, :lt} ->
{:snooze, @snooze_time}
{:ok, :gt} ->
{:snooze, @snooze_time}
end
end
def handle_check_balance(_response_value, _target_value, _) do
Logger.debug("-----into handle check balance")
{:snooze, 10}
end
defp perform_request(address) do
Logger.debug("-----into perform_request")
with {:ok, api_url} <- ApiLoadBalancerBlockchain.pick_api(),
{:ok, response} <- RequestBalanceFileSolana.get_balance(address, api_url) do
MnesiaPendingContractsDomain.att_ok_trys(address)
{:ok, response}
else
{:error, :rate_limit} ->
Logger.warning("Rate limit atingido")
{:error, :rate_limit}
{:error, reason} ->
Logger.error("Erro na requisição: #{inspect(reason)}")
{:error, reason}
end
end
def job_should_continue(pubkey) do
Logger.debug("hiii [job_should_continue]")
Logger.debug(pubkey)
with {:ok, _mnesia_data} <- MnesiaPendingContractsDomain.get_record_by_pk(pubkey) do
Logger.debug("job still ongoing")
:ok
else
{:error, reason} ->
Logger.debug("coudlt fetch job record #{reason}")
:ok
end
end
end
```
the piece in question of code in question:
```
def job_should_continue(pubkey) do
Logger.debug("hiii [job_should_continue]")
Logger.debug(pubkey)
with {:ok, _mnesia_data} <- MnesiaPendingContractsDomain.get_record_by_pk(pubkey) do
Logger.debug("job still ongoing")
:ok
else
{:error, reason} ->
Logger.debug("coudlt fetch job record #{reason}")
:ok
end
end
```
and the mnesia module function
```
def get_record_by_pk(pk) do
result = Memento.transaction(fn ->
Memento.Query.read(MnesiaPendingContracts, pk)
end)
Logger.debug("resultado dessa porra de banco #{result}")
case result do
{:ok, _} -> {:ok, :up}
{:error, _} -> {:error, :down}
_ -> System.stop(1)
end
end
```
this is my code after all the work, but on the very beginning it was exatcly like that
```
def job_sho2uld_continue(pubkey) do
with {:ok, _mnesia_data} <- MnesiaPendingContractsDomain.get_record_by_pk(pubkey) do
#CALL some function
#return this funtion
else
{:error, reason} ->
:ok
end
end
```
that was calling this
```
def get_record_by_pk(pk) do
result = Memento.transaction(fn ->
Memento.Query.read(MnesiaPendingContracts, pk)
end) do
{:ok, nil} ->
Logger.debug("record mnesia not found")
{:error, :not_found}
{:ok, record} ->
Logger.debug("Extracted record: #{inspect(record)}")
{:ok, record}
{:error, reason} ->
Logger.debug("unknow reason #{reason}" )
{:error,:not_found}
end
end
```
it was weird because this mnesia module it was tested and fully working in another section of the code, and had little capacity to cause problems (minimal output possibilites) so I reached iEx and found out the problem was: I was trying to debug a struct without calling inspect() to it
```
iex(13)> Testespay.DataLayer.MnesiaPendingContractsDomain.get_record_by_pk(pubkey1)
** (Protocol.UndefinedError) protocol String.Chars not implemented for {:ok, %MnesiaPendingContracts{__meta__: Memento.Table, pubkey: "abc123", last_attempt: 0, attempts: 0, time_limit: 100, job_id: 1, ok_trys: 0, failed_retrys: 0}} of type Tuple. This protocol is implemented for the following type(s): Atom, BitString, Date, DateTime, Decimal, Float, Integer, List, NaiveDateTime, Phoenix.LiveComponent.CID, Postgrex.Copy, Postgrex.Query, Time, URI, Version, Version.Requirement
(elixir 1.17.0) lib/string/chars.ex:3: String.Chars.impl_for!/1
(elixir 1.17.0) lib/string/chars.ex:22: String.Chars.to_string/1
(testespay 0.1.0) lib/testespay/data_layer/mnesia_pending_contracts.ex:18: Testespay.DataLayer.MnesiaPendingContractsDomain.get_record_by_pk/1
iex:13: (file)
```
when I added the inspect(), the job worked properly
```result = Memento.transaction(fn ->
Memento.Query.read(MnesiaPendingContracts, pk)
end)
Logger.debug("resultado dessa porra de banco #{inspect(result)}")
```
Is the desired behavior that something crashes or doesnt work properly even with this strict pattern matching with with clauses? I have come to apoint where I added
_ -> System.stop(1) to really check if the return of the domain was something different
if is, it is possible to change some internal configurations to avoid it? its painfull not being able to rely on nothing beside my eyes to see what isnt going on
### Expected Behavior
more safety with **with** clauses