Code Monkey home page Code Monkey logo

Comments (3)

OndroMih avatar OndroMih commented on August 26, 2024

I think the same API can be used for both purely dynamic configuration and registration during application startup, if a configuration object is passed to a CDI bean at application startup and could be also passed to a method that defines the job dynamically.

With a CDI bean, a job could be defined with e.g. a CDI event as follows (as described by @rmannibucau here):

void defineBatches(@Observes JobRegistrationCallback cb, JobOperator op, MyService service) {
    cb.defineJob("my-job")
       .batchlet("exec-sql", () -> service.executeBulkQuery().then(service::flush));
}

The CDI event would be fired at application startup, only once. This would be similar as when job is defined in a XML, which is also evaluated at startup.

And the same job definition could be applied on an instance of a JobOperator with a lambda argument as follows:

@Inject JobOperator op;
@Inject MyService service;

op.defineJob( (JobRegistrationCallback cb) -> {
    cb.defineJob("my-job")
       .batchlet("exec-sql", () -> service.executeBulkQuery().then(service::flush));
});

The defineJob method could even return the created Job definition instance that could be referenced to start a job instead of using the job name:

JobDefinition jobdef = op.defineJob( (JobRegistrationCallback cb) -> {
    return cb.defineJob("my-job");  
   // the `return` statement here isn't even necessary,
   // the `defineJob` method would get the definition from `cb` and return it
});
op.start( jobdef, new Properties() );

from batch.

rmannibucau avatar rmannibucau commented on August 26, 2024

If you make it a bean instead of an event it will remove the indirection in the API:

void defineBatches(@Observes @Initialized(ApplicationScoped.class) Object startup, JobRegistrationCallback cb /* optionally other services */) {
    cb.defineJob("my-job")
       .batchlet("exec-sql", () -> service.executeBulkQuery().then(service::flush));
}

and

@Inject JobRegistrationCallback cb;
@Inject MyService service;

cb.defineJob("my-job")
       .batchlet("exec-sql", () -> service.executeBulkQuery().then(service::flush));

Then no need to change JobOperator#start method signature since the job is named anyway (required to keep job operator reporting features).

from batch.

scottkurz avatar scottkurz commented on August 26, 2024

Seems we're not going to get to this in 2.1.

from batch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.