Fork me on GitHub
#duct
<
2020-06-17
>
g7s08:06:43

In my app I want to execute some code after the system has been initiated successfully. What is the proper way of doing this?

kwrooijen09:06:52

Generally speaking, after initialization, code will be executed by HTTP requests / cron tasks

kwrooijen09:06:18

Not sure what you're trying to do?

g7s09:06:02

I want to run a setup script for my web app (create stuff that have to be there etc). The script will be idempotent so I would not care if it runs after every system initialization

rickmoynihan06:06:21

@kevin.van.rooijen in the main thread is right; there’s no such mechanism. Instead you need to use dependencies between components to force an ordering…

{ :my/database { ,,, }
  :my/initialised-database { :db #ig/ref :my/database } 
   :my/app {:db #ig/ref :my/initialised-database}}

kwrooijen09:06:01

As in database rows?

g7s09:06:29

Including database rows

kwrooijen09:06:24

Ok, I don't think there's really a reason everything needs to be started, right? As long as the database connection is established. You could create an init-key that references :duct.database/sql, and does what it needs to do

kwrooijen09:06:14

Basically just reference whichever keys need to be started before this one

g7s09:06:13

Ok so this is what my initial thought was, I asked to see if there is something like a callback to a successful initialization or smth

kwrooijen09:06:30

AFAIK, there isn't

g7s09:06:22

:thumbsup:

kwrooijen09:06:07

https://github.com/duct-framework/core/blob/master/src/duct/core.clj#L213-L233 looks like exec-config just starts the system and checks of there are any :duct/daemon keys. If there are, it adds a shutdown hook and blocks infinitely

kwrooijen09:06:29

Doesn't look like there is any extra logic for hooks and stuff

g7s09:06:15

Yeah looks like it