mihai-ciupina

mihai-ciupina

hi,

how can I prevent genserver to start when running the seeds.ex file?

I have this cronjob that is running when I start the server, but I noticed that it starts too when I run the seeds.ex file. It wouldn’t be so bad but when the script is finished then the cronjob stops and that is bad for my data.

I want somehow the genserver to start only when I start the server.

Thanks

Showing Posts 1 to 8

idi527

idi527

:waving_hand:

How is this genserver started normally? Does something make it start in seeds.exs?

NobbZ

NobbZ

seeds.exs does need your application to be started. So it will start of course everything in your application. The hole supervision tree.

But also the seeds.exs isn’t meant to be run periodically. Usually its meant to be run once at an initial deploy of the application. Thats why it is called seeds. One usually doesn’t throw more seeds on the acre when the wheat is already growing…

NobbZ

NobbZ

I have digged a bit.

mix run --no-start seeds.exs might work, but then you have do a lot of bootstrapping on your own, like starting your repo, the connection pool, other needed stuff.

But I still think it is a bad idea.

mihai-ciupina

mihai-ciupina OP

yes but the cronjob puts some data in the database and suddenly is closed, leaving things in air.

I can postpone the cronjob for a minute just to be sure, but is kind of smelly :slight_smile:

NobbZ

NobbZ

I do assume your app is running as a release? Have you considered a “custom command” as described in the running migrations section?

That will actually run in th context of your already started application and not spawn a new one in parallel.

If you are not running a release created by distillery you can use other means to connect to the already running node and make it run your database updates.

Or last but not least, you can of course create those in plain SQL and just run them through your database…

mihai-ciupina

mihai-ciupina OP

No, it’s in dev mode.

NobbZ

NobbZ

Even when run via mix only, you can still remote shell into your application and run arbitrary functions. This is even possible via Cron.

But if it’s in dev, why bother at all? Just stop your application, run maintenance task and start the application again.

Dev is for development, not for production use.

mihai-ciupina

mihai-ciupina OP

My app/server is always stopped when I run my seeds.ex file.
This is how I register my cronjob:

defmodule MyApp.Application do
..
def start(_type, _args) do
..
children = [
..
supervisor(MyApp.MyCronjob, )
]
..

You might not see my situation.

I have the seeds file, the app, and some genserver.

When I do some task first thing I reset the app:
mix echo.reset
This will execute seeds and start genserver(for 1 sec or so)

Then I start the app:
mix pix.server
This will start the app and the genserver.

seeds puts some test data in the database.
Genserver will run once at 10 minutes so that it can detect some changes and copy data to my database.

What I want is:

When I do some task first thing I reset the app:
mix echo.reset
This will execute seeds

Then I start the app:
mix phx.server
This will start the app and the genserver.

— 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
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
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
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
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

Other Trending Topics Top

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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews