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

public interface StorageProvider extends AutoCloseable
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
  • Field Details

  • Method Details

    • getStorageProviderInfo

      StorageProvider.StorageProviderInfo getStorageProviderInfo()
    • setJobMapper

      void setJobMapper(JobMapper jobMapper)
    • setUpStorageProvider

      void setUpStorageProvider(StorageProviderUtils.DatabaseOptions databaseOptions)
      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

      void addJobStorageOnChangeListener(StorageProviderChangeListener listener)
      Allows to listen for changes related to jobs.
      Parameters:
      listener - the listener to notify if there are any changes.
      See Also:
    • removeJobStorageOnChangeListener

      void removeJobStorageOnChangeListener(StorageProviderChangeListener listener)
      Remove the given listener that listens for changes to Jobs
      Parameters:
      listener - the listener to remove
    • announceBackgroundJobServer

      void announceBackgroundJobServer(BackgroundJobServerStatus serverStatus)
    • signalBackgroundJobServerAlive

      boolean signalBackgroundJobServerAlive(BackgroundJobServerStatus serverStatus)
    • signalBackgroundJobServerStopped

      void signalBackgroundJobServerStopped(BackgroundJobServerStatus serverStatus)
    • getBackgroundJobServers

      List<BackgroundJobServerStatus> getBackgroundJobServers()
    • getLongestRunningBackgroundJobServerId

      UUID getLongestRunningBackgroundJobServerId()
    • removeTimedOutBackgroundJobServers

      int removeTimedOutBackgroundJobServers(Instant heartbeatOlderThan)
    • saveMetadata

      void saveMetadata(JobRunrMetadata metadata)
    • getMetadata

      List<JobRunrMetadata> getMetadata(String name)
    • getMetadata

      JobRunrMetadata getMetadata(String name, String owner)
    • deleteMetadata

      void deleteMetadata(String name)
    • save

      Save the Job 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

      Saves a list of Jobs and increases the version of each successfully saved Job.
      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

      Job getJobById(UUID id) throws JobNotFoundException
      Returns the Job with the given id or throws a JobNotFoundException 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

      default Job getJobById(JobId jobId) throws JobNotFoundException
      Returns the Job with the given id or throws a JobNotFoundException 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

      List<Job> getJobs(StateName state, Instant updatedBefore, PageRequest pageRequest)
    • getScheduledJobs

      List<Job> getScheduledJobs(Instant scheduledBefore, PageRequest pageRequest)
    • getJobs

      List<Job> getJobs(StateName state, PageRequest pageRequest)
    • getJobPage

      Page<Job> getJobPage(StateName state, PageRequest pageRequest)
    • deletePermanently

      int deletePermanently(UUID id)
      Deletes the Job 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

      int deleteJobsPermanently(StateName state, Instant updatedBefore)
    • getDistinctJobSignatures

      Set<String> getDistinctJobSignatures(StateName... states)
    • exists

      boolean exists(JobDetails jobDetails, StateName... states)
    • recurringJobExists

      boolean recurringJobExists(String recurringJobId, StateName... states)
      Returns true when a Job created by the RecurringJob 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 exists
      states - the possible states for the Job (can be empty)
      Returns:
      true if a Job exists created by a RecurringJob with the given id.
    • saveRecurringJob

      RecurringJob saveRecurringJob(RecurringJob recurringJob)
      Saves a RecurringJob to the database. If a RecurringJob with the same id exists, it will be overwritten
      Parameters:
      recurringJob - the RecurringJob to save
      Returns:
      the same RecurringJob
    • countRecurringJobs

      @Deprecated long countRecurringJobs()
      Deprecated.
    • getRecurringJobs

      RecurringJobsResult getRecurringJobs()
      Returns a list RecurringJobs.
      Returns:
      a list RecurringJobs.
    • recurringJobsUpdated

      boolean recurringJobsUpdated(Long recurringJobsUpdatedHash)
    • deleteRecurringJob

      int deleteRecurringJob(String id)
      Deletes the RecurringJob 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 a JobStatsChangeListener and register it using the addJobStorageOnChangeListener(StorageProviderChangeListener).
      Returns:
      the JobStats
    • publishTotalAmountOfSucceededJobs

      void publishTotalAmountOfSucceededJobs(int amount)
    • close

      void close()
      Specified by:
      close in interface AutoCloseable