caleb-bb

caleb-bb

So, I have a set of child processes under my start/2 callback, as you do:

  @impl true
  def start(_type, _args) do
    children = [
      MyAppWeb.Telemetry,
      MyApp.Repo,
      {DNSCluster, query: Application.get_env(:caque, :dns_cluster_query) || :ignore},
      {Phoenix.PubSub, name: MyApp.PubSub},
      # Start the Finch HTTP client for sending emails
      {Finch, name: MyApp.Finch},
      {MyApp.Documents.Cluster, name: :document_cluster},
      # Start a worker by calling: MyApp.Worker.start_link(arg)
      # {MyApp.Worker, arg},
      # Start to serve requests, typically the last entry
      MyAppWeb.Endpoint
    ]

    # See https://hexdocs.pm/elixir/Supervisor.html
    # for other strategies and supported options
    opts = [strategy: :one_for_one, max_restarts: 5, name: MyApp.Supervisor]
    Supervisor.start_link(children, opts)
  end

I’m using the Snap library to integrate OpenSearch. The Snap docs have it,

Each cluster defines start_link/1 which must be invoked before using the cluster and optionally accepts an explicit config. It creates the supervision tree, including the connection pool.

Include it in your application:

def start(_type, _args) do
  children = [
    {MyApp.Cluster, []}
  ]

  opts = [strategy: :one_for_one, name: MyApp.Supervisor]
  Supervisor.start_link(children, opts)
end

Okay, okay, so I did all that. But… I’ve got a problem.

I want to set up my app to create a certain index on startup. That is, when my application starts, I want it to check if there’s an index named "docs" under the Documents cluster (defined by MyApp.Documents.Cluster). If no such index exists, the app should create one.

MyApp.Documents.Cluster already uses the Snap.Cluster module, which implements GenServer. So I can’t define start_link in Documents.Cluster in order to spin up an index on startup.

What would be the best/most idiomatic way to spin up an index on startup? In a separate module? As some kind of appendage to Documents.Cluster? What’s the best way?

I notice in the Snap docs that init/1 is listed under defoverridable. Does that mean it’s safe to override, and use that to start the index?

Showing Posts 1 to 1

cmo

cmo

Snap.Cluster does not implement GenServer. If it did, you could use a continue.

Yep. Note that doing things in init blocks the supervisor from starting subsequent children until it returns.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
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
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
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

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews