Checks whether a job is finished by querying the job item table for unfinished job items.
$tjid: The identifier of the job.
bool TRUE if the job is finished, FALSE otherwise.
function tmgmt_job_check_finished($tjid) {
return !\Drupal::entityQuery('tmgmt_job_item')
->accessCheck(TRUE)
->condition('tjid', $tjid)
->condition('state', [
JobItem::STATE_ACCEPTED,
JobItem::STATE_ABORTED,
], 'NOT IN')
->range(0, 1)
->count()
->execute();
}