Class MongoDBStorageProvider
java.lang.Object
org.jobrunr.storage.AbstractStorageProvider
org.jobrunr.storage.nosql.mongo.MongoDBStorageProvider
- All Implemented Interfaces:
AutoCloseable, NoSqlStorageProvider, StorageProvider
- Direct Known Subclasses:
AmazonDocumentDBStorageProvider
-
Nested Class Summary
Nested classes/interfaces inherited from interface StorageProvider
StorageProvider.StorageProviderInfo -
Field Summary
FieldsFields inherited from interface StorageProvider
BATCH_SIZE -
Constructor Summary
ConstructorsConstructorDescriptionMongoDBStorageProvider(com.mongodb.client.MongoClient mongoClient) MongoDBStorageProvider(com.mongodb.client.MongoClient mongoClient, String dbName) MongoDBStorageProvider(com.mongodb.client.MongoClient mongoClient, String dbName, String collectionPrefix) MongoDBStorageProvider(com.mongodb.client.MongoClient mongoClient, String dbName, String collectionPrefix, StorageProviderUtils.DatabaseOptions databaseOptions) MongoDBStorageProvider(com.mongodb.client.MongoClient mongoClient, String dbName, String collectionPrefix, StorageProviderUtils.DatabaseOptions databaseOptions, RateLimiter changeListenerNotificationRateLimit) MongoDBStorageProvider(com.mongodb.client.MongoClient mongoClient, String dbName, StorageProviderUtils.DatabaseOptions databaseOptions) MongoDBStorageProvider(com.mongodb.client.MongoClient mongoClient, StorageProviderUtils.DatabaseOptions databaseOptions, RateLimiter changeListenerNotificationRateLimit) MongoDBStorageProvider(com.mongodb.client.MongoClient mongoClient, RateLimiter changeListenerNotificationRateLimit) MongoDBStorageProvider(String hostName, int port) -
Method Summary
Modifier and TypeMethodDescriptionvoidannounceBackgroundJobServer(BackgroundJobServerStatus serverStatus) 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.protected voidexplainAggregation(List<org.bson.conversions.Bson> query, String collectionName) used to perform query analysis for performance tuningprotected voidexplainQuery(org.bson.conversions.Bson query) used to perform query analysis for performance tuninggetCarbonAwareJobList(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 existgetJobList(StateName state, Instant updatedBefore, AmountRequest amountRequest) getJobList(StateName state, AmountRequest amountRequest) Returns all the jobs matching the givenStateNameandAmountRequest.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) 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) voidpublishTotalAmountOfSucceededJobs(int amount) booleanrecurringJobsUpdated(Long recurringJobsUpdatedHash) intremoveTimedOutBackgroundJobServers(Instant heartbeatOlderThan) protected voidrunMigrations(com.mongodb.client.MongoClient mongoClient, String dbName, String collectionPrefix) 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) static Stringprotected voidvalidateTables(com.mongodb.client.MongoClient mongoClient, String dbName, String collectionPrefix) Methods inherited from class AbstractStorageProvider
addJobStorageOnChangeListener, close, getStorageProviderInfo, notifyJobStatsOnChangeListeners, notifyJobStatsOnChangeListenersIf, notifyMetadataChangeListeners, notifyMetadataChangeListenersIf, notifyMetadataChangeListenersOnCurrentThread, removeJobStorageOnChangeListener, validatePollInterval, validateRecurringJobIntervalModifier and TypeMethodDescriptionvoidAllows to listen for changes related tojobs.voidclose()protected voidprotected voidnotifyJobStatsOnChangeListenersIf(boolean mustNotify) protected voidprotected voidnotifyMetadataChangeListenersIf(boolean mustNotify) protected voidvoidRemove the given listener that listens for changes toJobsfinal voidvalidatePollInterval(Duration pollInterval) final voidvalidateRecurringJobInterval(Duration durationBetweenRecurringJobInstances) Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface StorageProvider
getJobById, getJobs, getJobsToProcess, getScheduledJobsModifier and TypeMethodDescriptiondefault JobgetJobById(JobId jobId) Returns theJobwith the given id or throws aJobNotFoundExceptionif the job does not existgetJobs(StateName state, PageRequest pageRequest) getJobsToProcess(BackgroundJobServer backgroundJobServer, AmountRequest amountRequest) getScheduledJobs(Instant scheduledBefore, PageRequest pageRequest)
-
Field Details
-
DEFAULT_DB_NAME
- See Also:
-
-
Constructor Details
-
MongoDBStorageProvider
-
MongoDBStorageProvider
public MongoDBStorageProvider(com.mongodb.client.MongoClient mongoClient) -
MongoDBStorageProvider
-
MongoDBStorageProvider
public MongoDBStorageProvider(com.mongodb.client.MongoClient mongoClient, String dbName, StorageProviderUtils.DatabaseOptions databaseOptions) -
MongoDBStorageProvider
-
MongoDBStorageProvider
public MongoDBStorageProvider(com.mongodb.client.MongoClient mongoClient, String dbName, String collectionPrefix, StorageProviderUtils.DatabaseOptions databaseOptions) -
MongoDBStorageProvider
public MongoDBStorageProvider(com.mongodb.client.MongoClient mongoClient, RateLimiter changeListenerNotificationRateLimit) -
MongoDBStorageProvider
public MongoDBStorageProvider(com.mongodb.client.MongoClient mongoClient, StorageProviderUtils.DatabaseOptions databaseOptions, RateLimiter changeListenerNotificationRateLimit) -
MongoDBStorageProvider
public MongoDBStorageProvider(com.mongodb.client.MongoClient mongoClient, String dbName, String collectionPrefix, StorageProviderUtils.DatabaseOptions databaseOptions, RateLimiter changeListenerNotificationRateLimit)
-
-
Method Details
-
setJobMapper
- Specified by:
setJobMapperin interfaceStorageProvider
-
setUpStorageProvider
Description copied from interface:StorageProviderThis 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
- Specified by:
setUpStorageProviderin interfaceStorageProvider- Parameters:
databaseOptions- defines whether to set up the StorageProvider or validate whether the StorageProvider is set up correctly.
-
announceBackgroundJobServer
- Specified by:
announceBackgroundJobServerin interfaceStorageProvider
-
signalBackgroundJobServerAlive
- Specified by:
signalBackgroundJobServerAlivein interfaceStorageProvider
-
signalBackgroundJobServerStopped
- Specified by:
signalBackgroundJobServerStoppedin interfaceStorageProvider
-
getBackgroundJobServers
- Specified by:
getBackgroundJobServersin interfaceStorageProvider
-
getLongestRunningBackgroundJobServerId
- Specified by:
getLongestRunningBackgroundJobServerIdin interfaceStorageProvider
-
removeTimedOutBackgroundJobServers
- Specified by:
removeTimedOutBackgroundJobServersin interfaceStorageProvider
-
saveMetadata
- Specified by:
saveMetadatain interfaceStorageProvider
-
getMetadata
- Specified by:
getMetadatain interfaceStorageProvider
-
getMetadata
- Specified by:
getMetadatain interfaceStorageProvider
-
deleteMetadata
- Specified by:
deleteMetadatain interfaceStorageProvider
-
deleteMetadata
- Specified by:
deleteMetadatain interfaceStorageProvider
-
save
Description copied from interface:StorageProviderSave theJoband increases the version if saving succeeded.- Specified by:
savein interfaceStorageProvider- Parameters:
job- the job to save- Returns:
- the same job with an increased version
-
deletePermanently
Description copied from interface:StorageProviderDeletes theJobwith the given id and returns the amount of deleted jobs (either 0 or 1).- Specified by:
deletePermanentlyin interfaceStorageProvider- Parameters:
id- the id of the Job to delete- Returns:
- 1 if the job with the given id was deleted, 0 otherwise
-
getJobById
Description copied from interface:StorageProviderReturns theJobwith the given id or throws aJobNotFoundExceptionif the job does not exist- Specified by:
getJobByIdin interfaceStorageProvider- Parameters:
id- the id of the Job to fetch- Returns:
- the requested Job
-
countJobs
Description copied from interface:StorageProviderCounts all the jobs matching the givenStateName.- Specified by:
countJobsin interfaceStorageProvider- Parameters:
state- the StateName to test eachJobagainst- Returns:
- the amount of jobs matching the given
StateName.
-
save
Description copied from interface:StorageProvider- Specified by:
savein interfaceStorageProvider- Parameters:
jobs- the list of jobs to save- Returns:
- the same list of jobs with an increased version
-
deleteJobsPermanently
- Specified by:
deleteJobsPermanentlyin interfaceStorageProvider
-
getDistinctJobSignatures
- Specified by:
getDistinctJobSignaturesin interfaceStorageProvider
-
getRecurringJobLatestScheduledInstant
Description copied from interface:StorageProviderReturns the scheduled instant of the lastJob, in one of the given states, created by theRecurringJobwith the given recurringJobId.- Specified by:
getRecurringJobLatestScheduledInstantin interfaceStorageProvider- Parameters:
recurringJobId- the id of the RecurringJob for which to get the latest scheduled instantstates- the possible states for theJob(can be empty, then match against all possible states)- Returns:
- the scheduled instant of the last created
Job
-
saveRecurringJob
Description copied from interface:StorageProviderSaves aRecurringJobto the database. If aRecurringJobwith the same id exists, it will be overwritten- Specified by:
saveRecurringJobin interfaceStorageProvider- Parameters:
recurringJob- the RecurringJob to save- Returns:
- the same RecurringJob
-
getRecurringJobs
Description copied from interface:StorageProviderReturns a listRecurringJobs.- Specified by:
getRecurringJobsin interfaceStorageProvider- Returns:
- a list
RecurringJobs.
-
recurringJobsUpdated
- Specified by:
recurringJobsUpdatedin interfaceStorageProvider
-
deleteRecurringJob
Description copied from interface:StorageProviderDeletes theRecurringJobwith the given id.- Specified by:
deleteRecurringJobin interfaceStorageProvider- Parameters:
id- the id of the RecurringJob to delete- Returns:
- 1 if the RecurringJob with the given id was deleted, 0 otherwise
-
getJobStats
Description copied from interface:StorageProviderReturns 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 theStorageProvider.addJobStorageOnChangeListener(StorageProviderChangeListener).- Specified by:
getJobStatsin interfaceStorageProvider- Returns:
- the
JobStats
-
publishTotalAmountOfSucceededJobs
public void publishTotalAmountOfSucceededJobs(int amount) - Specified by:
publishTotalAmountOfSucceededJobsin interfaceStorageProvider
-
toMongoId
-
runMigrations
-
validateTables
-
explainQuery
protected void explainQuery(org.bson.conversions.Bson query) used to perform query analysis for performance tuning -
explainAggregation
-