public function createInstruction(InputDescriptor $input, TemplateInterface $template, array $flags = [])
    {
        if (!$template->getManaged()) {
            return null;
        }

        $cacheItem = $this->cacheManager->findByTemplateAndFile($template->getKey(), $input->getFileId(), $input->getFileVersion());

        if (in_array(Batch::FILTER_ERROR, $flags) && $cacheItem && !$this->isError($cacheItem)) {
            $this->logger->info('Skipping non-error item');

            return null;
        }

        if (in_array(Batch::FILTER_MISSING, $flags) && $cacheItem && !$this->isMissing($cacheItem)) {
            $this->logger->info('Skipping non-missing item');

            return null;
        }

        if (in_array(Batch::FILTER_UNCACHED, $flags) && $cacheItem && $this->isCached($cacheItem)) {
            $this->logger->info('Skipping cached item');

            return null;
        }

        if (!$cacheItem) {
            $cacheItem = new CacheItem();
            $cacheItem
                ->setId($this->cacheIdStrategy->createCacheId($template, $input))
                ->setVolumeId($input->getVolumeId())
                ->setFileId($input->getFileId())
                ->setFileVersion($input->getFileVersion())
                ->setTemplateKey($template->getKey())
                ->setTemplateRevision($template->getRevision())
                ->setCacheStatus(CacheItem::STATUS_WAITING)
                ->setQueueStatus(CacheItem::QUEUE_WAITING)
                ->setCreatedAt(new \DateTime());
        }

        $cacheItem
            ->setQueuedAt(new \DateTime());

        return new Instruction($input, $template, $cacheItem);
    }