Interface StorageProvider
- All Superinterfaces:
AutoCloseable
- All Known Subinterfaces:
NoSqlStorageProvider, SqlStorageProvider
- All Known Implementing Classes:
AbstractStorageProvider, AmazonDocumentDBStorageProvider, DB2StorageProvider, DefaultSqlStorageProvider, H2StorageProvider, InMemoryStorageProvider, MariaDbStorageProvider, MongoDBStorageProvider, MySqlStorageProvider, OracleStorageProvider, PostgresStorageProvider, SqLiteStorageProvider, SQLServerStorageProvider, ThreadSafeStorageProvider
The StorageProvider allows to store, retrieve and delete background jobs.
This API is public and JobRunr major version will change of this StorageProvider API changes.
- Since:
- 0.9.0
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoidAllows to listen for changes related tojobs.voidannounceBackgroundJobServer(BackgroundJobServerStatus serverStatus) voidclose()longCounts all the jobs matching the givenStateName.intdeleteJobsPermanently(StateName state, Instant updatedBefore) voiddeleteMetadata(String name) voiddeleteMetadata(String name, String owner) intDeletes theJobwith the given id and returns the amount of deleted jobs (either 0 or 1).intDeletes theRecurringJobwith the given id.getCarbonAwareJobList(Instant deadlineBefore, AmountRequest amountRequest) Returns all carbon aware jobs with a deadline before the givenInstant.getDistinctJobSignatures(StateName... states) getJobById(UUID id) Returns theJobwith the given id or throws aJobNotFoundExceptionif the job does not existdefault JobgetJobById(JobId jobId) Returns theJobwith the given id or throws aJobNotFoundExceptionif the job does not existgetJobList(StateName state, Instant updatedBefore, AmountRequest amountRequest) getJobList(StateName state, AmountRequest amountRequest) Returns all the jobs matching the givenStateNameandAmountRequest.getJobs(StateName state, PageRequest pageRequest) Returns the statistics of the jobs (amount enqueued, amount scheduled, ...) Important: in most cases, this results in a intensive query.getJobsToProcess(BackgroundJobServer backgroundJobServer, AmountRequest amountRequest) getMetadata(String name) getMetadata(String name, String owner) getRecurringJobLatestScheduledInstant(String recurringJobId, StateName... states) Returns the scheduled instant of the lastJob, in one of the given states, created by theRecurringJobwith the given recurringJobId.Returns a listRecurringJobs.getScheduledJobs(Instant scheduledBefore, AmountRequest amountRequest) getScheduledJobs(Instant scheduledBefore, PageRequest pageRequest) voidpublishTotalAmountOfSucceededJobs(int amount) booleanrecurringJobsUpdated(Long recurringJobsUpdatedHash) voidRemove the given listener that listens for changes toJobsintremoveTimedOutBackgroundJobServers(Instant heartbeatOlderThan) Save theJoband increases the version if saving succeeded.voidsaveMetadata(JobRunrMetadata metadata) saveRecurringJob(RecurringJob recurringJob) Saves aRecurringJobto the database.voidsetJobMapper(JobMapper jobMapper) voidsetUpStorageProvider(StorageProviderUtils.DatabaseOptions databaseOptions) This method allows to reinitialize the StorageProvider.booleansignalBackgroundJobServerAlive(BackgroundJobServerStatus serverStatus) voidsignalBackgroundJobServerStopped(BackgroundJobServerStatus serverStatus) voidvalidatePollInterval(Duration pollInterval) voidvalidateRecurringJobInterval(Duration durationBetweenRecurringJobInstances)
-
Field Details
-
BATCH_SIZE
static final int BATCH_SIZE- See Also:
-
-
Method Details
-
getStorageProviderInfo
StorageProvider.StorageProviderInfo getStorageProviderInfo() -
setJobMapper
-
setUpStorageProvider
This method allows to reinitialize the StorageProvider. It can be used if you are using Flyway or Liquibase to setup your database manually.By default, this method is automatically called on construction of the StorageProvider
- Parameters:
databaseOptions- defines whether to set up the StorageProvider or validate whether the StorageProvider is set up correctly.
-
addJobStorageOnChangeListener
Allows to listen for changes related tojobs.- Parameters:
listener- the listener to notify if there are any changes.- See Also:
-
removeJobStorageOnChangeListener
Remove the given listener that listens for changes toJobs- Parameters:
listener- the listener to remove
-
announceBackgroundJobServer
-
signalBackgroundJobServerAlive
-
signalBackgroundJobServerStopped
-
getBackgroundJobServers
List<BackgroundJobServerStatus> getBackgroundJobServers() -
getLongestRunningBackgroundJobServerId
UUID getLongestRunningBackgroundJobServerId() -
removeTimedOutBackgroundJobServers
-
saveMetadata
-
getMetadata
-
getMetadata
-
deleteMetadata
-
deleteMetadata
-
save
Save theJoband increases the version if saving succeeded.- Parameters:
job- the job to save- Returns:
- the same job with an increased version
- Throws:
ConcurrentJobModificationException- if the already stored job was newer then the given version
-
save
- Parameters:
jobs- the list of jobs to save- Returns:
- the same list of jobs with an increased version
- Throws:
ConcurrentJobModificationException- if any already stored job was newer then the given version
-
getJobById
Returns theJobwith the given id or throws aJobNotFoundExceptionif the job does not exist- Parameters:
id- the id of the Job to fetch- Returns:
- the requested Job
- Throws:
JobNotFoundException- if the job is not found or does not exist anymore.
-
getJobById
Returns theJobwith the given id or throws aJobNotFoundExceptionif the job does not exist- Parameters:
jobId- the id of the Job to fetch- Returns:
- the requested Job
- Throws:
JobNotFoundException- if the job is not found or does not exist anymore.
-
countJobs
-
deletePermanently
-
deleteJobsPermanently
-
getDistinctJobSignatures
-
getRecurringJobLatestScheduledInstant
Returns the scheduled instant of the lastJob, in one of the given states, created by theRecurringJobwith the given recurringJobId. -
saveRecurringJob
Saves aRecurringJobto the database. If aRecurringJobwith the same id exists, it will be overwritten- Parameters:
recurringJob- the RecurringJob to save- Returns:
- the same RecurringJob
-
getRecurringJobs
-
recurringJobsUpdated
-
deleteRecurringJob
Deletes theRecurringJobwith the given id.- Parameters:
id- the id of the RecurringJob to delete- Returns:
- 1 if the RecurringJob with the given id was deleted, 0 otherwise
-
getJobStats
JobStats getJobStats()Returns the statistics of the jobs (amount enqueued, amount scheduled, ...) Important: in most cases, this results in a intensive query. JobRunr is designed to not call this method too often to limit database CPU utilization. If you need access to this info, please use aJobStatsChangeListenerand register it using theaddJobStorageOnChangeListener(StorageProviderChangeListener).- Returns:
- the
JobStats
-
publishTotalAmountOfSucceededJobs
void publishTotalAmountOfSucceededJobs(int amount) -
close
void close()- Specified by:
closein interfaceAutoCloseable
-
validatePollInterval
-
validateRecurringJobInterval
-