Class JobContext

java.lang.Object
edu.ucsb.cs156.jobs.services.JobContext

public class JobContext extends Object
Handed to a running JobContextConsumer; each log(java.lang.String) call appends one line to the job's log, so admins can watch progress live.

Since v0.2.0, each line is its own row in job_logs (see JobLog) rather than a read-modify-write of one growing TEXT column on jobs — an O(1) insert instead of an O(N) rewrite of everything logged so far. The job body runs inside one all-or-nothing transaction (see JobService.runJobAsync(edu.ucsb.cs156.jobs.entities.Job, edu.ucsb.cs156.jobs.services.JobContextConsumer)), so log writes must NOT join it: they would be invisible to the admin UI until the whole job commits. When a logTransactionTemplate is provided (configured REQUIRES_NEW by JobContextFactory), each line commits in its own transaction immediately.

A null jobLogRepository is tolerated as a test seam: the log accumulates on job's (Java-only, @Transient) log field instead of being persisted anywhere. The apps' job tests conventionally run jobs against new JobContext(null, job) and assert on job.getLog(); that legacy two-arg constructor is preserved unchanged for exactly this reason.

  • Constructor Summary

    Constructors
    Constructor
    Description
    JobContext(JobLogRepository jobLogRepository, Job job, org.springframework.transaction.support.TransactionTemplate logTransactionTemplate)
     
    JobContext(JobsRepository jobsRepository, Job job)
    Deprecated.
    kept only so existing test code written against v0.1.x (new JobContext(null, job)) keeps compiling; the jobsRepository parameter is ignored.
  • Method Summary

    Modifier and Type
    Method
    Description
    Exposes the underlying job, mainly so job bodies and their tests can inspect state (e.g.
    void
    log(String message)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • log

      public void log(String message)
    • getJob

      public Job getJob()
      Exposes the underlying job, mainly so job bodies and their tests can inspect state (e.g. ctx.getJob().getLog()) without threading a separate reference through. Note: for a real (non-test-seam) run, job.getLog() is not kept up to date by log(java.lang.String) any more (see class javadoc) — it reflects whatever the caller last set it to, typically nothing.