Class JobContext
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
ConstructorsConstructorDescriptionJobContext(JobLogRepository jobLogRepository, Job job, org.springframework.transaction.support.TransactionTemplate logTransactionTemplate) JobContext(JobsRepository jobsRepository, Job job) Deprecated. -
Method Summary
-
Constructor Details
-
JobContext
Deprecated.kept only so existing test code written against v0.1.x (new JobContext(null, job)) keeps compiling; thejobsRepositoryparameter is ignored. UseJobContext(JobLogRepository, Job, TransactionTemplate). -
JobContext
public JobContext(JobLogRepository jobLogRepository, Job job, org.springframework.transaction.support.TransactionTemplate logTransactionTemplate)
-
-
Method Details
-
log
-
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 bylog(java.lang.String)any more (see class javadoc) — it reflects whatever the caller last set it to, typically nothing.
-
new JobContext(null, job)) keeps compiling; thejobsRepositoryparameter is ignored.