Class DBJobTriggerService

java.lang.Object
org.graylog.scheduler.DBJobTriggerService

public class DBJobTriggerService extends Object
  • Field Details

  • Constructor Details

  • Method Details

    • all

      public List<JobTriggerDto> all()
      Loads all existing records and returns them.
      Returns:
      list of records
    • get

      public Optional<JobTriggerDto> get(String id)
      Loads the record for the given ID.
      Parameters:
      id - record ID to load
      Returns:
      filled optional when the record exists, an empty optional otherwise
    • getOneForJob

      public Optional<JobTriggerDto> getOneForJob(String jobDefinitionId)
      Returns one trigger for the given job definition ID. TODO: Don't throw exception when there is more than one trigger for a job definition. (see source code)
      Parameters:
      jobDefinitionId - the job definition ID
      Returns:
      One found job trigger
    • getAllForJob

      public List<JobTriggerDto> getAllForJob(String jobDefinitionId)
    • getForJobs

      public Map<String,List<JobTriggerDto>> getForJobs(Collection<String> jobDefinitionIds)
      Returns all job triggers for the given job definition IDs, grouped by job definition ID. TODO: Don't throw exception when there is more than one trigger for a job definition. (see source code)
      Parameters:
      jobDefinitionIds - the job definition IDs
      Returns:
      list of found job triggers
    • create

      public JobTriggerDto create(JobTriggerDto trigger)
      Creates a new record in the database. The given JobTriggerDto object must not have an ID to make sure a new record is created.
      Parameters:
      trigger - the new trigger object (without an ID set)
      Returns:
      the newly created trigger object
      Throws:
      IllegalArgumentException - if the passed trigger has an ID set
    • update

      public boolean update(JobTriggerDto trigger)
      Updates the given trigger record in the database. This method takes care of not overwriting any locks and state data with the update.
      Parameters:
      trigger - the trigger to update
      Returns:
      true when the update was successful, false otherwise
      Throws:
      IllegalArgumentException - if the passed trigger doesn't have an ID set
    • delete

      public boolean delete(String triggerId)
      Deletes the trigger with the given ID.
      Parameters:
      triggerId - the trigger ID to delete
      Returns:
      true if the trigger got deleted, false otherwise
    • deleteCompletedOnceSchedulesOlderThan

      public int deleteCompletedOnceSchedulesOlderThan(long timeValue, TimeUnit unit)
      Deletes completed / cancelled OnceJobSchedule triggers that are older than the provided time
      Parameters:
      timeValue - the time range of triggers to be removed
      unit - the unit of the provided timeValue
      Returns:
      the number of deleted triggers
    • deleteByQuery

      public int deleteByQuery(org.mongojack.DBQuery.Query query)
      Deletes job triggers using the given query. Use judiciously, as will make assumptions about the internal data structure of triggers.
    • countByQuery

      public long countByQuery(org.mongojack.DBQuery.Query query)
    • nextRunnableTrigger

      public Optional<JobTriggerDto> nextRunnableTrigger()
      Locks and returns the next runnable trigger. The caller needs to take care of releasing the trigger lock.
      Returns:
      next runnable trigger if any exists, an empty Optional otherwise
    • releaseTrigger

      public boolean releaseTrigger(JobTriggerDto trigger, JobTriggerUpdate triggerUpdate)
      Releases a locked trigger. The trigger is only released if it's owned by the calling node.
      Parameters:
      trigger - trigger that should be released
      triggerUpdate - update to apply to the trigger
      Returns:
      true if the trigger has been modified, false otherwise
    • forceReleaseOwnedTriggers

      public int forceReleaseOwnedTriggers()
      WARNING: This should only be called before the job scheduler is started! Calling this while the scheduler is running might result in data corruption or inconsistencies!

      This method will release all triggers that are locked by the calling node. It should be called before starting the scheduler service on the current node to release all triggers that might be in a stale RUNNING status after an unclean JVM or Graylog server shutdown.
      Returns:
      number of released triggers
    • setTriggerError

      public boolean setTriggerError(JobTriggerDto trigger)
      Mark the given trigger as defective to make sure it will not be scheduled anymore.
      Parameters:
      trigger - trigger that should be marked as defective
      Returns:
      true if the trigger has been modified, false otherwise
    • updateLockedJobTriggers

      public void updateLockedJobTriggers()
    • updateProgress

      public int updateProgress(JobTriggerDto trigger, int progress)
      Update the job progress on a trigger
      Parameters:
      trigger - the trigger to update
      progress - the job progress in percent (0-100)
    • cancelTriggerByQuery

      public Optional<JobTriggerDto> cancelTriggerByQuery(org.mongojack.DBQuery.Query query)
      Cancel a JobTrigger that matches a query
      Parameters:
      query - the db query
      Returns:
      an Optional of the trigger that was cancelled. Empty if no matching trigger was found.
    • findByQuery

      public List<JobTriggerDto> findByQuery(org.mongojack.DBQuery.Query query)
      Find triggers by using the provided query. Use judiciously!
      Parameters:
      query - The query
      Returns:
      All found JobTriggers