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

KOGITO-530/531 Jobs persistence and retries on error #2

Merged
merged 16 commits into from
Nov 19, 2019

Conversation

tiagodolphine
Copy link

Initial implementation of persistence with infinipsan and retries on errors.

To disable persistence you can set the property on application.properties persistence=false or use -Dpersistence=false on the startup, in this way it will use the in-memory repository.

Copy link
Owner

@mswiderski mswiderski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added few comments but lets have a chat tomorrow so I better understand what it does and how :)

@@ -39,34 +47,71 @@
private static final Logger LOGGER = LoggerFactory.getLogger(HttpJobExecutor.class);

@Inject
Vertx vertx;
private Vertx vertx;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use package protected as otherwise quarkus reports warnings

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great point, I was not aware of this behavior. I changed the all attributes with @Inject until all warnings were gone.


@RegisterForReflection
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don’t think this is needed, we won’t run it as naitive executable

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, my bad I forgot to remove it.
Done


@Inject
public JobRepositoryDelegate(@Any Instance<ReactiveJobRepository> instances,
@ConfigProperty(name = "persistence")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to prefix the config ptoperty so it is clear what it refers to ‚kogito.job-service.persistence’ or similar

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree.
Done


@Inject
public InfinispanConfiguration(Instance<RemoteCacheManager> cacheManagerInstance,
@ConfigProperty(name = "persistence")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, prefix the config property

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree.
Done

import static org.kie.kogito.jobs.service.repository.infinispan.InfinispanConfiguration.Caches.SCHEDULED_JOBS;

@ApplicationScoped
@Repository(persistence = true)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this qualifier? Is this to allow to have in memory and infinispan in the same app?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea here was to have multiple implementations of the interface, for instance one for in-memory and other for infinispan, in this way injecting the interface on beans cause exceptions, so the solution was to have only one @Default impl that delegates to the concrete class according to the config property for persistence. So I added the qualifier to solve this problem, do you have a better/simpler idea? I'll be happy to change, this was my last change to solve the problem to disable or enable persistence.
One observation, since the injection is Lazy, the infinispan client is not being initialized by quarkus that why I'm injecting the Instance<ReactiveJobRepository> when persistence is not enabled, it evicts to get Exception during the startup.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about using named injections and then let people configure in application property which one to use? It will be more explicit and we could easily add more implementations. While the default would be in memory and we only look up beans when the config property is given. That way we could move all the code related to bootstrapping into the given bean that will be initialised only when that property is set.

so implementation wise it would be similar ... still using qualifier (though we could use @Named but it is considered less CDI) but instead of linking it with persistence we could just have one that is @Repository("inmemory") and another one @Repository("infinispan")

and then in application.properties we could then have kogito.job-service.repository=infinispan and by default it will be kogito.job-service.repository=inmemory

wdyt?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and in case we would to this we don't have to specify if the persistence is enabled or nor as it will be taken based on the repository implementation anyway

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

// @Produces
// public EnumMarshaller statusMarshaller() {
// return new StatusMarshaller();
// }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe remove if this is not needed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great catch.
Done

@Path("/job")
public class JobResource {

private static final Logger LOGGER = LoggerFactory.getLogger(JobResource.class);

@Inject
VertxJobScheduler scheduler;
private VertxJobScheduler scheduler;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here use package protected

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

private Logger logger = LoggerFactory.getLogger(BaseTimerJobScheduler.class);
private static final Logger LOGGER = LoggerFactory.getLogger(BaseTimerJobScheduler.class);
public static final long BACKOFF_RETRY_MILLIS = TimeUnit.SECONDS.toMillis(1);
public static final long MAX_INTERVAL_LIMIT_TO_RETRY_MILLIS = TimeUnit.SECONDS.toMillis(60);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn’t this be configurable via application.properties

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree, better to have it configurable.

quarkus.swagger-ui.path=/swagger-ui

#Infinispan - more specific configs on hotrod-client.properties file.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can actually use this file for hotrod auth setup which I would prefer as its easier to override

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I'll move the config to application.properties.

@Override
public JobsService getJobsService() {
return delegate.getJobsService();
>>>>>>> further work on timer service
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ouch ... looks like conflict not resolved?

@tiagodolphine
Copy link
Author

@mswiderski I rebased with last changes on your fork, the conflicts should be solved.

@tiagodolphine
Copy link
Author

@mswiderski just pushed some changes, now the repository config is based on a string (the impl type), jobs are removed when achieving a final state, and some other improvements on onde.

@mswiderski mswiderski merged commit e0e174f into mswiderski:job-service Nov 19, 2019
mswiderski pushed a commit that referenced this pull request Nov 19, 2019
* KOGITO-18 - Pluggable timer/jobs service that can be used as service

* Initial Job Service implementation

Initial Job Service implementation

inserting swagger

* Apply PR comments and some code refactoring, test

* Fix JobScheduler when cancelling job

* Fixing cancel already scheduled job when re-scheduling

* Job retry implementation

* Inserting Infinispan persistence on Job service

* Inserting Infinispan persistence on Job service

* fix infinispan repository

* Inserting persistence selector based on config property

* Fix scheduler manager and infinispan repository to work with config

* Fix JobResourceTest

* Removed fixed version on pom

* Update plugin on job-service pom

* Fix comments on the PR

* Job repository type by config, remove jobs on final state, add retry jobs when load job on startup
mswiderski pushed a commit that referenced this pull request Nov 20, 2019
* KOGITO-18 - Pluggable timer/jobs service that can be used as service

* Initial Job Service implementation

Initial Job Service implementation

inserting swagger

* Apply PR comments and some code refactoring, test

* Fix JobScheduler when cancelling job

* Fixing cancel already scheduled job when re-scheduling

* Job retry implementation

* Inserting Infinispan persistence on Job service

* Inserting Infinispan persistence on Job service

* fix infinispan repository

* Inserting persistence selector based on config property

* Fix scheduler manager and infinispan repository to work with config

* Fix JobResourceTest

* Removed fixed version on pom

* Update plugin on job-service pom

* Fix comments on the PR

* Job repository type by config, remove jobs on final state, add retry jobs when load job on startup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants