<commit_before><?php

namespace Rocket\Plugin\QueueGroups;

use Rocket\Plugin\AbstractPlugin;
use Rocket\Job\JobEvent;
use Rocket\Job\Job;
use Rocket\Queue\Queue;
use Rocket\Queue\QueueEvent;
use Rocket\Queue\QueueInterface;

class QueueGroupsPlugin extends AbstractPlugin
{
    use \Rocket\ObjectCacheTrait;
    use \Rocket\JqTrait;

    protected $groupQueuesHash;
    protected $allGroupsSet;

    //Assumption: A queue is a member of a single group

    public function register()
    {
        $this->getEventDispatcher()->addListener(Job::EVENT_SCHEDULE, function (JobEvent $event) {
            $this->addQueueGroupFromJob($event->getJob(), $event->getJob()->getQueueName());
        });

        $this->getEventDispatcher()->addListener(Job::EVENT_QUEUE, function (JobEvent $event) {
            $this->addQueueGroupFromJob($event->getJob(), $event->getJob()->getQueueName());
            $this->getGroupWaitingSet($event->getJob()->getGroupName())->addItem($event->getJob()->getId());
        });

        $this->getEventDispatcher()->addListener(Job::EVENT_START, function (JobEvent $event) {
            $this->getGroupWaitingSet($event->getJob()->getGroupName())->deleteItem($event->getJob()->getId());
            $this->getGroupRunningSet($event->getJob()->getGroupName())->addItem($event->getJob()->getId());
        });

        $this->getEventDispatcher()->addListener(Job::EVENT_COMPLETE, function (JobEvent $event) {
            $this->getGroupRunningSet($event->getJob()->getGroupName())->deleteItem($event->getJob()->getId());
        });

        $this->getEventDispatcher()->addListener(Job::EVENT_FAIL, function (JobEvent $event) {
            $this->getGroupRunningSet($event->getJob()->getGroupName())->deleteItem($event->getJob()->getId());
        });

        $this->getEventDispatcher()->addListener(Job::EVENT_DELETE, function (JobEvent $event) {
            $this->getGroupWaitingSet($event->getJob()->getGroupName())->deleteItem($event->getJob()->getId());
            $this->getGroupRunningSet($event->getJob()->getGroupName())->deleteItem($event->getJob()->getId());
        });

        $this->getEventDispatcher()->addListener(Queue::EVENT_DELETE, function (QueueEvent $event) {<commit_msg>Fixes cancel issue with group counts<commit_after><?php

namespace Rocket\Plugin\QueueGroups;

use Rocket\Plugin\AbstractPlugin;
use Rocket\Job\JobEvent;
use Rocket\Job\Job;
use Rocket\Queue\Queue;
use Rocket\Queue\QueueEvent;
use Rocket\Queue\QueueInterface;

class QueueGroupsPlugin extends AbstractPlugin
{
    use \Rocket\ObjectCacheTrait;
    use \Rocket\JqTrait;

    protected $groupQueuesHash;
    protected $allGroupsSet;

    //Assumption: A queue is a member of a single group

    public function register()
    {
        $this->getEventDispatcher()->addListener(Job::EVENT_SCHEDULE, function (JobEvent $event) {
            $this->addQueueGroupFromJob($event->getJob(), $event->getJob()->getQueueName());
        });

        $this->getEventDispatcher()->addListener(Job::EVENT_QUEUE, function (JobEvent $event) {
            $this->addQueueGroupFromJob($event->getJob(), $event->getJob()->getQueueName());
            $this->getGroupWaitingSet($event->getJob()->getGroupName())->addItem($event->getJob()->getId());
        });

        $this->getEventDispatcher()->addListener(Job::EVENT_START, function (JobEvent $event) {
            $this->getGroupWaitingSet($event->getJob()->getGroupName())->deleteItem($event->getJob()->getId());
            $this->getGroupRunningSet($event->getJob()->getGroupName())->addItem($event->getJob()->getId());
        });

        $this->getEventDispatcher()->addListener(Job::EVENT_COMPLETE, function (JobEvent $event) {
            $this->getGroupRunningSet($event->getJob()->getGroupName())->deleteItem($event->getJob()->getId());
        });

        $this->getEventDispatcher()->addListener(Job::EVENT_FAIL, function (JobEvent $event) {
            $this->getGroupRunningSet($event->getJob()->getGroupName())->deleteItem($event->getJob()->getId());
        });

        $this->getEventDispatcher()->addListener(Job::EVENT_CANCEL, function (JobEvent $event) {
            $this->getGroupWaitingSet($event->getJob()->getGroupName())->deleteItem($event->getJob()->getId());
            $this->getGroupRunningSet($event->getJob()->getGroupName())->deleteItem($event->getJob()->getId());
        });

        $this->getEventDispatcher()->addListener(Job::EVENT_DELETE, function (JobEvent $event) {
            $this->getGroupWaitingSet($event->getJob()->getGroupName())->deleteItem($event->getJob()->getId());
            $this->getGroupRunningSet($event->getJob()->getGroupName())->deleteItem($event->getJob()->getId());
        });

        $this->getEventDispatcher()->addListener(Queue::EVENT_DELETE, function (QueueEvent $event) {
{'fraction_non_alphanumeric': 0.18332986905009355, 'fraction_numerical': 0.0, 'mean_word_length': 4.190938511326861, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 145, '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': '3012992', 'n_tokens_mistral': 1369, 'n_tokens_neox': 1354, 'n_words': 169}