fabioformosa / quartz-manager

REST API and UI Console Manager for Quartz Scheduler. This is a Java Library & UI embeddable single page app, to control and monitor jobs scheduled with Quartz Scheduler
Apache License 2.0
232 stars 84 forks source link

[QUESTION] Run `quartz-persistance` independently #115

Closed midhunadarvin closed 5 months ago

midhunadarvin commented 5 months ago

Hi,

I had a requirement of setting up quartz with persistence in a postgres database. With the quartz-manager project if I have to initialize the database, I could set the spring.quartz.initialize-schema from never to always

This will help initialize the database, but it will drop existing tables and initialize on every startup of the application. So in order to workaround that, the 1st deployment should be with the property spring.quartz.initialize-schema=always and the 2nd deployment should be with the property spring.quartz.initialize-schema=never

This will work but doesn't seem clean due to dependency on multiple deployment.

I tried to setup the quartz-manager-starter-persistence project with configuration to run it independently and initialize the database without the need for spring boot project to start.

In pom.xml of quartz-manager-starter-persistence

<build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.liquibase</groupId>
          <artifactId>liquibase-maven-plugin</artifactId>
          <version>4.25.0</version>
          <configuration>
            <propertyFile>liquibase.properties</propertyFile>
          </configuration>
          <executions>
            <execution>
              <phase>process-resources</phase>
              <goals>
                <goal>update</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>

liquibase.properties

changeLogFile=src/main/resources/db/quartz-scheduler/liquibase-changelog-master.xml
url=jdbc:postgresql://localhost:5432/quartzmanager
username=quartzmanager
password=quartzmanager

Finally I run the command to migrate / initialize the database independently of spring boot :

mvn liquibase:update

My question is whether there are any other better options to initialize the database only once ? Should this be incorporated into the quartz-manager-starter-persistence project as an alternate option ?

fabioformosa commented 5 months ago

I'm not sure to have got your point. Anyway, if you need to run Quartz with a DB to persist the scheduler config, you don't need to run liquibase and switch spring.quartz.initialize-schema to always and later to never again. Simply you have to import the quartz-manager-starter-persistence dependency in your project. That dependency will run liquibase at the bootstrap to initialize the tables, only once, at the first bootstrap. See this paragraph Is it what you were looking for?

midhunadarvin commented 5 months ago

I did try the same to bootstrap a newly created database with the scheduler configs. I used the docker-compose file in the quartz-manager-web-showcase project to create a new postgres container. I added the quartz-manager-starter-persistence as dependency. In application.yml, the database url, username, password are given. However when I started the quartz-manager-web-showcase project the qrtz_* tables were not created.

I think why it doesn't work is because spring.quartz.initialize-schema is set to never in the quartz-persistence.properties

When i set this property to always, the tables are initialized, but I could see stack overflow links where when we set spring.quartz.initialize-schema to always, the tables are dropped and created again on every restart of the application. https://stackoverflow.com/questions/64101847/spring-boot-quartz-jdbc-tables-are-always-initailized

Is there anything that i might have missed ?

fabioformosa commented 5 months ago

You've got a bug. spring.quartz.initialize-schema is set to never in the quartz-persistence.properties, because quartz-manager-starter-persistence has the quartz DB scripts within it and it should execute them through liquibase, at the bootstrap. Unfortunately, liquibase isn't finding the changelog, thus quartz DB scripts are not executed. Thank you to have notified it. I'm debugging...

fabioformosa commented 5 months ago

Hi @midhunadarvin, I've just fixed. I've released the ver 4.0.9 with this fix and your already merged contributions. I confirm that it's enough to import the dependency quartz-manager-starter-persistence to get initialized the tables. You can get an example here: https://github.com/fabioformosa/quartz-manager-use-cases/tree/main/with-persistence

midhunadarvin commented 5 months ago

Thanks @fabioformosa . I checked it and confirm that it is working. Closing this issue.