protected function ensureUnPublishJob($when)
    {
        // Check if there is a prior job
        if ($this->owner->UnPublishJobID) {
            $job = $this->owner->UnPublishJob();
            // Use timestamp for sake of comparison.
            if ($job && $job->exists() && DBDatetime::create()->setValue($job->StartAfter)->getTimestamp() == $when) {
                return;
            }
            $this->clearUnPublishJob();
        }

        // Create a new job with the specified schedule
        $job = new WorkflowPublishTargetJob($this->owner, 'unpublish');
        $this->owner->UnPublishJobID = Injector::inst()->get(QueuedJobService::class)
            ->queueJob($job, $when ? date('Y-m-d H:i:s', $when) : null);
    }