<commit_before><?php
/**
 * Created by mcfedr on 8/4/16 12:12
 */
namespace Mcfedr\QueueManagerBundle\Subscriber;

use Mcfedr\QueueManagerBundle\Command\RunnerCommand;
use Mcfedr\QueueManagerBundle\Event\FailedJobEvent;
use Doctrine\Bundle\DoctrineBundle\Registry;
use Mcfedr\QueueManagerBundle\Event\FinishedJobEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class DoctrineResetSubscriber implements EventSubscriberInterface
{
    /**
     * @var Registry
     */
    private $doctrine;

    /**
     * @param Registry $doctrine
     */
    public function __construct(Registry $doctrine = null)
    {
        $this->doctrine = $doctrine;
    }

    public function onJobFailed(FailedJobEvent $e)
    {
        $this->reset();
    }

    public function onJobFinished(FinishedJobEvent $e)
    {
        $this->reset();
    }

    private function reset()
    {
        if ($this->doctrine) {
            $this->doctrine->resetManager();
        }
    }

    public static function getSubscribedEvents()
    {
        return [
            RunnerCommand::JOB_FINISHED_EVENT => 'onJobFinished',
            RunnerCommand::JOB_FAILED_EVENT => 'onJobFailed'<commit_msg>Close the connection before reseting doctrine manager<commit_after><?php
/**
 * Created by mcfedr on 8/4/16 12:12
 */
namespace Mcfedr\QueueManagerBundle\Subscriber;

use Mcfedr\QueueManagerBundle\Command\RunnerCommand;
use Mcfedr\QueueManagerBundle\Event\FailedJobEvent;
use Doctrine\Bundle\DoctrineBundle\Registry;
use Mcfedr\QueueManagerBundle\Event\FinishedJobEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class DoctrineResetSubscriber implements EventSubscriberInterface
{
    /**
     * @var Registry
     */
    private $doctrine;

    /**
     * @param Registry $doctrine
     */
    public function __construct(Registry $doctrine = null)
    {
        $this->doctrine = $doctrine;
    }

    public function onJobFailed(FailedJobEvent $e)
    {
        $this->reset();
    }

    public function onJobFinished(FinishedJobEvent $e)
    {
        $this->reset();
    }

    private function reset()
    {
        if ($this->doctrine) {
            /** @var Connection $c */
            $c = $this->doctrine->getConnection();
            $c->close();
            $this->doctrine->resetManager();
        }
    }

    public static function getSubscribedEvents()
    {
        return [
            RunnerCommand::JOB_FINISHED_EVENT => 'onJobFinished',
            RunnerCommand::JOB_FAILED_EVENT => 'onJobFailed'
{'fraction_non_alphanumeric': 0.10781990521327015, 'fraction_numerical': 0.00631911532385466, 'mean_word_length': 2.867175572519084, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6440746', 'n_tokens_mistral': 762, 'n_tokens_neox': 733, 'n_words': 135}