Package org.jobrunr.storage
Interface StorageProvider
- All Superinterfaces:
AutoCloseable
- All Known Subinterfaces:
NoSqlStorageProvider
,SqlStorageProvider
- All Known Implementing Classes:
AbstractStorageProvider
,AmazonDocumentDBStorageProvider
,DB2StorageProvider
,DefaultSqlStorageProvider
,ElasticSearchStorageProvider
,H2StorageProvider
,InMemoryStorageProvider
,JedisRedisStorageProvider
,LettuceRedisStorageProvider
,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
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Allows to listen for changes related tojobs
.void
announceBackgroundJobServer
(BackgroundJobServerStatus serverStatus) void
close()
long
Deprecated.int
deleteJobsPermanently
(StateName state, Instant updatedBefore) void
deleteMetadata
(String name) int
Deletes theJob
with the given id and returns the amount of deleted jobs (either 0 or 1).int
Deletes theRecurringJob
with the given id.boolean
exists
(JobDetails jobDetails, StateName... states) getDistinctJobSignatures
(StateName... states) getJobById
(UUID id) Returns theJob
with the given id or throws aJobNotFoundException
if the job does not existdefault Job
getJobById
(JobId jobId) Returns theJob
with the given id or throws aJobNotFoundException
if the job does not existgetJobPage
(StateName state, PageRequest pageRequest) getJobs
(StateName state, Instant updatedBefore, PageRequest pageRequest) 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.getMetadata
(String name) getMetadata
(String name, String owner) Returns a listRecurringJobs
.getScheduledJobs
(Instant scheduledBefore, PageRequest pageRequest) void
publishTotalAmountOfSucceededJobs
(int amount) boolean
recurringJobExists
(String recurringJobId, StateName... states) Returns true when aJob
created by theRecurringJob
with the given id exists with one of the given states.boolean
recurringJobsUpdated
(Long recurringJobsUpdatedHash) void
Remove the given listener that listens for changes toJobs
int
removeTimedOutBackgroundJobServers
(Instant heartbeatOlderThan) Save theJob
and increases the version if saving succeeded.void
saveMetadata
(JobRunrMetadata metadata) saveRecurringJob
(RecurringJob recurringJob) Saves aRecurringJob
to the database.void
setJobMapper
(JobMapper jobMapper) void
setUpStorageProvider
(StorageProviderUtils.DatabaseOptions databaseOptions) This method allows to reinitialize the StorageProvider.boolean
signalBackgroundJobServerAlive
(BackgroundJobServerStatus serverStatus) void
signalBackgroundJobServerStopped
(BackgroundJobServerStatus serverStatus)
-
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
-
save
Save theJob
and 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 theJob
with the given id or throws aJobNotFoundException
if 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 theJob
with the given id or throws aJobNotFoundException
if 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.
-
getJobs
-
getScheduledJobs
-
getJobs
-
getJobPage
-
deletePermanently
Deletes theJob
with the given id and returns the amount of deleted jobs (either 0 or 1).- Parameters:
id
- the id of the Job to delete- Returns:
- 1 if the job with the given id was deleted, 0 otherwise
-
deleteJobsPermanently
-
getDistinctJobSignatures
-
exists
-
recurringJobExists
Returns true when aJob
created by theRecurringJob
with the given id exists with one of the given states.- Parameters:
recurringJobId
- the id of the RecurringJob for which the check whether a Job existsstates
- the possible states for the Job (can be empty)- Returns:
- true if a Job exists created by a RecurringJob with the given id.
-
saveRecurringJob
Saves aRecurringJob
to the database. If aRecurringJob
with the same id exists, it will be overwritten- Parameters:
recurringJob
- the RecurringJob to save- Returns:
- the same RecurringJob
-
countRecurringJobs
Deprecated. -
getRecurringJobs
RecurringJobsResult getRecurringJobs()Returns a listRecurringJobs
.- Returns:
- a list
RecurringJobs
.
-
recurringJobsUpdated
-
deleteRecurringJob
Deletes theRecurringJob
with 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 aJobStatsChangeListener
and register it using theaddJobStorageOnChangeListener(StorageProviderChangeListener)
.- Returns:
- the
JobStats
-
publishTotalAmountOfSucceededJobs
void publishTotalAmountOfSucceededJobs(int amount) -
close
void close()- Specified by:
close
in interfaceAutoCloseable
-