Potions

Potions

Forum Sponsor

Sooner or later you’ll need to run a one-off or recurring task on a deployed app, and if you deploy with releases the usual answer, a Mix task, isn’t available. In this screencast we’ll walk through what releases give you instead: remote, rpc, and eval, and when to use each one.

The first three parts are plain Elixir releases and apply to any deployment. The last part uses Potions’ scheduled tasks to run the job daily.

Showing Posts 1 to 2

krasenyp

krasenyp

Everything was fine and dandy until I encountered this N+1:

def reprice_stale do
  repriced =
    stale_query()
    |> Repo.all()
    |> Enum.map(fn widget ->
      widget
      |> Ecto.Changeset.change(
        price: widget.price |> Decimal.mult(@discount) |> Decimal.round(2),
        price_reduced: true
      )
      |> Repo.update!()
    end)

  IO.puts("Reduced #{length(repriced)} stale widgets")
end

I really, really hope the author doesn’t put such code in production because it’s essentially a single UPDATE in the database. No mapping, no individual updates.

def reprice_stale do
  {repriced_count, _} =
    stale_query()
    |> update([w], 
      set: [
        price: fragment("round(? * ?, 2)", w.price, @discount), 
        price_reduced: true
      ]
    )  
    |> Repo.update_all([])

  IO.puts("Reduced #{length(repriced_count)} stale widgets")
end

P.S. Of course, the above implies the author has a NUMERIC column for the price.

Potions

Potions OP

Forum Sponsor

You’re right, and thanks for calling it out. I’ve updated the post and re-recorded that section of the video.

— All posts loaded —

Where Next? Top

Trending in Screencasts Top

Potions
A new screencast on moving a blocking HTTP fetch into an Oban job. Part 1 of 2. Screencast + full walkthrough:
New
Potions
A new screencast on live LiveView updates with PubSub, the Oban Web dashboard, and smarter retries. Part 2 of 2. Screencast + full walkth...
New

Other Trending Topics Top

GenericJam
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
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews