<?php

namespace AppBundle\Model;

use Bprs\CommandLineBundle\Model\JobService;
use AppBundle\Entity\Asset;
use Doctrine\ORM\Event\LifecycleEventArgs;

class ArchyWorkerService {

    private $jobservice;
    const QUEUE = "md5";

    public function __construct(JobService $jobservice)
    {
        $this->jobservice = $jobservice;
    }

    public function addMD5Job(Asset $asset)
    {
        $this->jobservice->addJob('AppBundle\Model\AssetJob' , array('id' => $asset->getId()), $this::QUEUE);
    }

    public function postPersist(LifecycleEventArgs $args)
    {
        $entity = $args->getEntity();

        if ($entity instanceof Asset) {
            $this->addMD5Job($entity);
        }
    }

    public function openMD5Queue()
    {
        $this->jobservice->startWorker($this::QUEUE);
    }

    public function closeAllQueues()
    {
        $this->jobservice->stopWorkers();
    }
}
?>
