try {
if (immediate) {
// If we have too many jobs in the queue, we don't allow any new ones
if (_todo.size() > _todoLimit)
throw new ContextException("The execution queue is backed up... Forcing ContextException");
// Immediate scheduling means we put it in the DB for safe keeping
_db.insertJob(job, _nodeId, true);
// And add it to our todo list .
addTodoOnCommit(job);
__log.debug("scheduled immediate job: " + job.jobId);
} else if (nearfuture) {
// Near future, assign the job to ourselves (why? -- this makes it very unlikely that we
// would get two nodes trying to process the same instance, which causes unsightly rollbacks).
_db.insertJob(job, _nodeId, false);
__log.debug("scheduled near-future job: " + job.jobId);
} else /* far future */{
// Not the near future, we don't assign a node-id, we'll assign it later.
_db.insertJob(job, null, false);
__log.debug("scheduled far-future job: " + job.jobId);
}
} catch (DatabaseException dbe) {
__log.error("Database error.", dbe);
throw new ContextException("Database error.", dbe);
}
return job.jobId;
}