Class JobService

java.lang.Object
edu.ucsb.cs156.frontiers.services.jobs.JobService

@Service public class JobService extends Object
  • Constructor Details

    • JobService

      public JobService()
  • Method Details

    • runAsJob

      public Job runAsJob(JobContextConsumer jobFunction)
    • runJobAsync

      @Async public void runJobAsync(Job job, JobContextConsumer jobFunction)
      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 job
      jobFunction - runnable job function
    • getJobLogs

      public String getJobLogs(Long jobId)