Package ca.uhn.fhir.batch2.api
Interface IJobPersistence
- All Superinterfaces:
IWorkChunkPersistence
Some of this is tested in
ca.uhn.hapi.fhir.batch2.test.AbstractIJobPersistenceSpecificationTest
This is a transactional interface, but we have pushed the declaration of calls that have
@Transactional(propagation = Propagation.REQUIRES_NEW) down to the implementations since we have a synchronized
wrapper that was double-creating the NEW transaction.-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classstatic interfaceCallback to update a JobInstance within a locked transaction. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionbooleanadvanceJobStepAndUpdateChunkStatus(String theJobInstanceId, String theNextStepId, boolean theIsReductionStepBoolean) Atomically advance the given job to the given step and change the status of all QUEUED and GATE_WAITING chunks in the next step to READYcancelInstance(String theInstanceId) Marks an instance as cancelledcreateWorkChunk(WorkChunk theWorkChunk) voiddeleteChunksAndMarkInstanceAsChunksPurged(String theInstanceId) Deletes all work chunks associated with the instancevoiddeleteInstanceAndChunks(String theInstanceId) Deletes the instance and all associated work chunksvoidenqueueWorkChunkForProcessing(String theChunkId, Consumer<Integer> theCallback) org.springframework.data.domain.Page<WorkChunkMetadata>fetchAllWorkChunkMetadataForJobInStates(org.springframework.data.domain.Pageable thePageable, String theInstanceId, Set<WorkChunkStatusEnum> theStates) Fetches an iterator that retrieves WorkChunkMetadata from the db.fetchAllWorkChunksForStepStream(String theInstanceId, String theStepId) Fetch all chunks with data for a given instance for a given step id - read-only.fetchAllWorkChunksIterator(String theInstanceId, boolean theWithData) Fetch all chunks for a given instance.fetchInstance(String theInstanceId) Fetch an instancefetchInstances(int thePageSize, int thePageIndex) Fetch all instancesfetchInstances(FetchJobInstancesRequest theRequest, int theStart, int theBatchSize) Fetches any existing jobs matching provided request parametersfetchInstances(String theJobDefinitionId, Set<StatusEnum> theStatuses, Date theCutoff, org.springframework.data.domain.Pageable thePageable) fetchInstancesByJobDefinitionId(String theJobDefinitionId, int theCount, int theStart) Fetch all job instances for a given job definition idfetchInstancesByJobDefinitionIdAndStatus(String theJobDefinitionId, Set<StatusEnum> theRequestedStatuses, int thePageSize, int thePageIndex) org.springframework.data.domain.Page<JobInstance>fetchJobInstances(JobInstanceFetchRequest theRequest) Fetches all job instances based on the JobFetchRequestfetchRecentInstances(int thePageSize, int thePageIndex) Fetch instances ordered by myCreateTime DESCgetDistinctWorkChunkStatesForJobAndStep(String theInstanceId, String theCurrentStepId) Returns set of all distinct states for the specified job instance id and step id.booleanmarkInstanceAsStatusWhenStatusIn(String theInstance, StatusEnum theStatusEnum, Set<StatusEnum> thePriorStates) default booleanonChunkDequeued(String theJobInstanceId) Move from QUEUED->IN_PROGRESS when a work chunk arrives.default IJobPersistence.CreateResultonCreateWithFirstChunk(JobDefinition<?> theJobDefinition, String theParameters) Create the job, and it's first chunk.storeNewInstance(JobInstance theInstance) Store a new job instance.booleanupdateInstance(String theInstanceId, IJobPersistence.JobInstanceUpdateCallback theModifier) Brute-force hack for now to create a tx boundary - takes a write-lock on the instance while the theModifier runs.voidupdateInstanceUpdateTime(String theInstanceId) intupdatePollWaitingChunksForJobIfReady(String theInstanceId) Updates all Work Chunks in POLL_WAITING if their nextPollTime <= now for the given Job Instance.Methods inherited from interface ca.uhn.fhir.batch2.api.IWorkChunkPersistence
markWorkChunksWithStatusAndWipeData, onWorkChunkCompletion, onWorkChunkCreate, onWorkChunkDequeue, onWorkChunkError, onWorkChunkFailed, onWorkChunkPollDelay
-
Field Details
-
ourLog
-
-
Method Details
-
storeNewInstance
Store a new job instance. This will be called when a new job instance is being kicked off.- Parameters:
theInstance- The details
-
fetchInstance
Fetch an instance- Parameters:
theInstanceId- The instance ID
-
fetchInstances
List<JobInstance> fetchInstances(String theJobDefinitionId, Set<StatusEnum> theStatuses, Date theCutoff, org.springframework.data.domain.Pageable thePageable) -
fetchInstances
List<JobInstance> fetchInstances(FetchJobInstancesRequest theRequest, int theStart, int theBatchSize) Fetches any existing jobs matching provided request parameters -
fetchInstances
Fetch all instances -
enqueueWorkChunkForProcessing
@Transactional(propagation=REQUIRES_NEW) void enqueueWorkChunkForProcessing(String theChunkId, Consumer<Integer> theCallback) -
updatePollWaitingChunksForJobIfReady
Updates all Work Chunks in POLL_WAITING if their nextPollTime <= now for the given Job Instance.- Parameters:
theInstanceId- the instance id- Returns:
- the number of updated chunks
-
fetchRecentInstances
Fetch instances ordered by myCreateTime DESC -
fetchInstancesByJobDefinitionIdAndStatus
List<JobInstance> fetchInstancesByJobDefinitionIdAndStatus(String theJobDefinitionId, Set<StatusEnum> theRequestedStatuses, int thePageSize, int thePageIndex) -
fetchInstancesByJobDefinitionId
List<JobInstance> fetchInstancesByJobDefinitionId(String theJobDefinitionId, int theCount, int theStart) Fetch all job instances for a given job definition id -
fetchJobInstances
org.springframework.data.domain.Page<JobInstance> fetchJobInstances(JobInstanceFetchRequest theRequest) Fetches all job instances based on the JobFetchRequest- Parameters:
theRequest- - the job fetch request- Returns:
- - a page of job instances
-
getDistinctWorkChunkStatesForJobAndStep
@Transactional Set<WorkChunkStatusEnum> getDistinctWorkChunkStatesForJobAndStep(String theInstanceId, String theCurrentStepId) Returns set of all distinct states for the specified job instance id and step id. -
fetchAllWorkChunksIterator
Fetch all chunks for a given instance.- Specified by:
fetchAllWorkChunksIteratorin interfaceIWorkChunkPersistence- Parameters:
theInstanceId- - instance idtheWithData- - whether or not to include the data- Returns:
- - an iterator for fetching work chunks
-
fetchAllWorkChunksForStepStream
Fetch all chunks with data for a given instance for a given step id - read-only.- Specified by:
fetchAllWorkChunksForStepStreamin interfaceIWorkChunkPersistence- Returns:
- - a stream for fetching work chunks
-
fetchAllWorkChunkMetadataForJobInStates
@Transactional(propagation=SUPPORTS) org.springframework.data.domain.Page<WorkChunkMetadata> fetchAllWorkChunkMetadataForJobInStates(org.springframework.data.domain.Pageable thePageable, String theInstanceId, Set<WorkChunkStatusEnum> theStates) Fetches an iterator that retrieves WorkChunkMetadata from the db.- Parameters:
theInstanceId- instance id of job of interesttheStates- states of interset- Returns:
- an iterator for the workchunks
-
updateInstance
@Transactional boolean updateInstance(String theInstanceId, IJobPersistence.JobInstanceUpdateCallback theModifier) Brute-force hack for now to create a tx boundary - takes a write-lock on the instance while the theModifier runs. Keep the callback short to keep the lock-time short. If the status is changing, useJobInstanceStatusUpdaterinside theModifier to ensure state-change callbacks are invoked properly.- Parameters:
theInstanceId- the id of the instance to modifytheModifier- a hook to modify the instance - return true to finish the record write- Returns:
- true if the instance was modified
-
deleteInstanceAndChunks
Deletes the instance and all associated work chunks- Parameters:
theInstanceId- The instance ID
-
deleteChunksAndMarkInstanceAsChunksPurged
Deletes all work chunks associated with the instance- Parameters:
theInstanceId- The instance ID
-
markInstanceAsStatusWhenStatusIn
@Transactional(propagation=MANDATORY) boolean markInstanceAsStatusWhenStatusIn(String theInstance, StatusEnum theStatusEnum, Set<StatusEnum> thePriorStates) -
cancelInstance
Marks an instance as cancelled- Parameters:
theInstanceId- The instance ID
-
updateInstanceUpdateTime
-
onCreateWithFirstChunk
@Nonnull @Transactional(propagation=MANDATORY) default IJobPersistence.CreateResult onCreateWithFirstChunk(JobDefinition<?> theJobDefinition, String theParameters) Create the job, and it's first chunk. We create the chunk atomically with the job so that we never have a state with zero unfinished chunks left until the job is complete. Makes the maintenance run simpler.- Parameters:
theJobDefinition- what kind of jobtheParameters- params for the job- Returns:
- the ids of the instance and first chunk
-
onChunkDequeued
Move from QUEUED->IN_PROGRESS when a work chunk arrives. Ignore other prior states.- Returns:
- did the transition happen
-
createWorkChunk
-
advanceJobStepAndUpdateChunkStatus
@Transactional(propagation=REQUIRES_NEW) boolean advanceJobStepAndUpdateChunkStatus(String theJobInstanceId, String theNextStepId, boolean theIsReductionStepBoolean) Atomically advance the given job to the given step and change the status of all QUEUED and GATE_WAITING chunks in the next step to READY- Parameters:
theJobInstanceId- the id of the job instance to be updatedtheNextStepId- the id of the next job step- Returns:
- whether any changes were made
-