Package org.jobrunr.scheduling
Class JobBuilder
java.lang.Object
org.jobrunr.scheduling.JobBuilder
This class is used to build a
Job
using a job lambda or a .
You can use it as follows:
A job lambda example:
MyService service = new MyService();
jobScheduler.create(aJob()
.withId(UUID.fromString(idRequestParam))
.withAmountOfRetries(3)
.scheduleIn(Duration.ofSeconds(10))
.withDetails(() -> service.sendMail(toRequestParam, subjectRequestParam, bodyRequestParam));
A JobRequest example:
jobRequestScheduler.create(aJob()
.withId(UUID.fromString(idRequestParam))
.withAmountOfRetries(3)
.scheduleIn(Duration.ofSeconds(10))
.withJobRequest(new SendMailRequest(toRequestParam, subjectRequestParam, bodyRequestParam));
-
Method Summary
Modifier and TypeMethodDescriptionstatic JobBuilder
aJob()
Creates a newJobBuilder
instance to create a Job using a Java 8 lambda.protected Job
build()
Not publicly visible as it will be used by theJobRequestScheduler
only.protected Job
build
(JobDetailsGenerator jobDetailsGenerator) Not publicly visible as it will be used by theJobScheduler
only.scheduleAt
(Instant scheduleAt) Allows to specify the instant on which the job will be enqueued.scheduleIn
(Duration duration) Allows to specify the duration after which the job should be enqueued.withAmountOfRetries
(int amountOfRetries) Allows to specify the amount of retries for a job when it fails<S> JobBuilder
withDetails
(IocJobLambda<S> jobLambda) Allows to provide the job details by means of Java 8 lambda.withDetails
(JobLambda jobLambda) Allows to provide the job details by means of Java 8 lambda.Allows to set the id of the job.withJobRequest
(JobRequest jobRequest) Allows to provide the job details by means ofJobRequest
.withLabels
(String... labels) Allows to provide a set of labels to be shown in the dashboard.withLabels
(Set<String> labels) Allows to provide a set of labels to be shown in the dashboard.Allows to set the name of the job for the dashboard.
-
Method Details
-
aJob
Creates a newJobBuilder
instance to create a Job using a Java 8 lambda.- Returns:
- a new
JobBuilder
instance
-
withId
Allows to set the id of the job. If a job with that id already exists, JobRunr will not save it again.- Parameters:
jobId
- the id of the job- Returns:
- the same builder instance which provides a fluent api
-
withName
Allows to set the name of the job for the dashboard.- Parameters:
jobName
- the name of the job for the dashboard- Returns:
- the same builder instance which provides a fluent api
-
scheduleIn
Allows to specify the duration after which the job should be enqueued.- Parameters:
duration
- the duration after which the job should be enqueued- Returns:
- the same builder instance which provides a fluent api
-
scheduleAt
Allows to specify the instant on which the job will be enqueued.- Parameters:
scheduleAt
- the instant on which the job will be enqueued- Returns:
- the same builder instance which provides a fluent api
-
withAmountOfRetries
Allows to specify the amount of retries for a job when it fails- Parameters:
amountOfRetries
- the amount of retries that JobRunr will perform in case the job fails- Returns:
- the same builder instance which provides a fluent api
-
withLabels
Allows to provide a set of labels to be shown in the dashboard. A maximum of 3 labels can be provided per job. Each label has a max length of 45 characters.- Parameters:
labels
- an array of labels to be added to the recurring job- Returns:
- the same builder instance which provides a fluent api
-
withLabels
Allows to provide a set of labels to be shown in the dashboard. A maximum of 3 labels can be provided per job. Each label has a max length of 45 characters.- Parameters:
labels
- an array of labels to be added to the recurring job- Returns:
- the same builder instance which provides a fluent api
-
withDetails
Allows to provide the job details by means of Java 8 lambda.- Parameters:
jobLambda
- the lambda which defines the job- Returns:
- the same builder instance that can be given to the
JobScheduler.create(JobBuilder)
method
-
withDetails
Allows to provide the job details by means of Java 8 lambda. The IoC container will be used to resolve an actual instance of the requested service.- Parameters:
jobLambda
- the lambda which defines the job- Returns:
- the same builder instance that can be given to the
JobScheduler.create(JobBuilder)
method
-
withJobRequest
Allows to provide the job details by means ofJobRequest
.- Parameters:
jobRequest
- the jobRequest which defines the job.- Returns:
- the same builder instance that can be given to the
JobRequestScheduler.create(JobBuilder)
method
-
build
Not publicly visible as it will be used by theJobScheduler
only.- Returns:
- the actual
Job
to create
-
build
Not publicly visible as it will be used by theJobRequestScheduler
only.- Returns:
- the actual
Job
to create
-