Tagged with “Elixir” (11)

While uploading the picture of the bread I noticed that somewhere in the upload process the page would just turn blank and the upload would fail without any error message.

When I checked the server process in journalctl, I realized that the elixir process gets killed because it’s exhausting the memory of my (admittedly undersized) VPS. Since I do some processing (mostly dithering and resizing) of all uploaded images, it takes up to 400MB at one point.

Sometimes that’s less than is available so the OOM Killer (badass name) steps in and kills the process.

@preloads [
  tags: [
      |> where_published()
      |> order_by(desc: :updated_at),
      |> where_unpublished()
      |> order_by(desc: :updated_at)

Is this a normal preload? Looks a bit.. funny.

Preloading in Elixir/Ecto

This is a pattern for preloading in Elixir that I have adopted for a few projects. I’m sharing it here for reference. The idea is to have one place to define your preloads instead of in every query.

@preloads [:listens]
defp with_preloads(query), do: preload(query, ^@preloads)
def preload_artist(artist), do: Repo.preload(artist, @preloads)

with_preloads can be used to enhance an query with preloads:

def list_artists do
 |> with_preloads()
 |> Repo.all()

Whereas preload_artist() is used to preload a single object, for example, after getting a single artist:

def get_artist!(id), do: Repo.get!(Artist, id) |> preload_artist()

Hm. The instructions for installing Elixir on Ubuntu from https://elixir-lang.org/install.html do not seem to work anymore. Trying to install esl-erlang wants to download a gigabyte of dependencies like icons, java and graphics-drivers lol.

For now, the solution is to do apt install elixir erlang-dev erlang-parsetools erlang-xmerl build-essential to get mirage to compile.

Managing Elixir project versions with git_ops

When developing ELixir applications, I’d like to have an easy way to manage versions. A tool that makes this very easy is git_ops. It is an elixir/hex package which sets up a workflow of versioning your project and git commits using conventional commits.

Conventional commits uses a few easy.. well, conventions to make your commits parseable and actionable.

Here’s how I set up git_ops in my projects.