Class JobService
java.lang.Object
edu.ucsb.cs156.frontiers.services.jobs.JobService
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetJobLogs(Long jobId) runAsJob(JobContextConsumer jobFunction) voidrunJobAsync(Job job, JobContextConsumer jobFunction) Runs a job asynchronously.
-
Constructor Details
-
JobService
public JobService()
-
-
Method Details
-
runAsJob
-
runJobAsync
Runs a job asynchronously.This method uses a TransactionTemplate because outside of the Spring context, you cannot delete entities that are unmanaged by Hibernate. Using the transactionTemplate lambda keeps the database session open and allows Hibernate to maintain it's knowledge of the object graph (i.e. the entities)
To learn more, read about Hibernate and the concept of a Spring Context.
Note that using the transactionTemplate lambda means that if there is an unhandled exception, either every database transactions succeeds, or all of them are rolled back.
However, the job entity metadata will still be saved.
- Parameters:
job- metadata entity about the jobjobFunction- runnable job function
-
getJobLogs
-