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 2 to 1

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.

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.

— All posts loaded —

Where Next? Top

Trending in Screencasts Top

Potions
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...
New
ElixirCasts
Plotto is a 100% Elixir charting library with no NIFs or external dependencies. In this episode, we’ll use it to add interactive SVG char...
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
JesseHerrick
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
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
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
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews