Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUESTION] Run quartz-persistance independently #115

Closed
midhunadarvin opened this issue Feb 4, 2024 · 5 comments
Closed

[QUESTION] Run quartz-persistance independently #115

midhunadarvin opened this issue Feb 4, 2024 · 5 comments
Labels

Comments

@midhunadarvin
Copy link
Contributor

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
Copy link
Owner

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
Copy link
Contributor Author

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
Copy link
Owner

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
Copy link
Owner

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
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants