Package org.graylog.scheduler
Class DBJobTriggerService
java.lang.Object
org.graylog.scheduler.DBJobTriggerService
-
Field Summary
-
Constructor Summary
ConstructorDescriptionDBJobTriggerService
(MongoConnection mongoConnection, MongoJackObjectMapperProvider mapper, NodeId nodeId, JobSchedulerClock clock, SchedulerCapabilitiesService schedulerCapabilitiesService, com.github.joschi.jadconfig.util.Duration lockExpirationDuration) -
Method Summary
Modifier and TypeMethodDescriptionall()
Loads all existing records and returns them.cancelTriggerByQuery
(org.mongojack.DBQuery.Query query) Cancel a JobTrigger that matches a querylong
countByQuery
(org.mongojack.DBQuery.Query query) create
(JobTriggerDto trigger) Creates a new record in the database.boolean
Deletes the trigger with the given ID.int
deleteByQuery
(org.mongojack.DBQuery.Query query) Deletes job triggers using the given query.int
deleteCompletedOnceSchedulesOlderThan
(long timeValue, TimeUnit unit) Deletes completed / cancelledOnceJobSchedule
triggers that are older than the provided timefindByQuery
(org.mongojack.DBQuery.Query query) Find triggers by using the provided query.int
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!Loads the record for the given ID.getAllForJob
(String jobDefinitionId) getForJobs
(Collection<String> jobDefinitionIds) Returns all job triggers for the given job definition IDs, grouped by job definition ID.getOneForJob
(String jobDefinitionId) Returns one trigger for the given job definition ID.Locks and returns the next runnable trigger.boolean
releaseTrigger
(JobTriggerDto trigger, JobTriggerUpdate triggerUpdate) Releases a locked trigger.boolean
setTriggerError
(JobTriggerDto trigger) Mark the given trigger as defective to make sure it will not be scheduled anymore.boolean
update
(JobTriggerDto trigger) Updates the given trigger record in the database.void
int
updateProgress
(JobTriggerDto trigger, int progress) Update the job progress on a trigger
-
Field Details
-
COLLECTION_NAME
- See Also:
-
-
Constructor Details
-
DBJobTriggerService
@Inject public DBJobTriggerService(MongoConnection mongoConnection, MongoJackObjectMapperProvider mapper, NodeId nodeId, JobSchedulerClock clock, SchedulerCapabilitiesService schedulerCapabilitiesService, @Named("job_scheduler_lock_expiration_duration") com.github.joschi.jadconfig.util.Duration lockExpirationDuration)
-
-
Method Details
-
all
Loads all existing records and returns them.- Returns:
- list of records
-
get
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
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
-
getForJobs
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
Creates a new record in the database. The givenJobTriggerDto
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
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
Deletes the trigger with the given ID.- Parameters:
triggerId
- the trigger ID to delete- Returns:
- true if the trigger got deleted, false otherwise
-
deleteCompletedOnceSchedulesOlderThan
Deletes completed / cancelledOnceJobSchedule
triggers that are older than the provided time- Parameters:
timeValue
- the time range of triggers to be removedunit
- 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
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
Releases a locked trigger. The trigger is only released if it's owned by the calling node.- Parameters:
trigger
- trigger that should be releasedtriggerUpdate
- 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 staleRUNNING
status after an unclean JVM or Graylog server shutdown.- Returns:
- number of released triggers
-
setTriggerError
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
Update the job progress on a trigger- Parameters:
trigger
- the trigger to updateprogress
- the job progress in percent (0-100)
-
cancelTriggerByQuery
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
Find triggers by using the provided query. Use judiciously!- Parameters:
query
- The query- Returns:
- All found JobTriggers
-