<p>You can cancel a FeedMe job before it starts by invalidating the <code>EVENT_BEFORE_PROCESS_FEED</code> event in the <code>Process</code> class. In your case, it sounds like you want to check whether the Feed is already in the queue, so from within a module you could do something like this:</p>
<pre class="lang-php prettyprint-override"><code>Event::on(Process::class, Process::EVENT_BEFORE_PROCESS_FEED, function(FeedProcessEvent $event)
  {
    $existingJob = 0;
    foreach(array_column(Craft::$app-&gt;queue-&gt;jobInfo, 'description') as $index =&gt; $string) {
      if (strpos($string, $event-&gt;feed-&gt;name) !== FALSE) {
        ++$existingJob;
        if ($existingJob &gt; 1) {
          $event-&gt;isValid = false;
        }
      }
    }
  }
);
</code></pre>

CC BY-SA 4.0
2022-04-11T15:13:56.677Z
2022-04-11T15:13:56.677Z
andrewmenich
<p>I’d like to prevent a feedme feed from running more than once when multiple requests are received within a few seconds of each other.</p>
<p>My first guess is that I would want to target an event such as ‘’’BeforeFetchFeed’’’ to determine when to prevent the feed from being parsed.</p>
<p>Another more lo-fi option may be to use the Guzzle option ‘’’Delay’’’ and setting the value to increase after each subsequent run. Would this be possible in the config options?</p>
<p>Any ideas?</p>

<plugin-development><plugin-feedme><events><guzzle>
Feed Me Plugin - Prevent Feed from Being Triggered Multiple Times in Quick Succession
# Feed Me Plugin - Prevent Feed from Being Triggered Multiple Times in Quick Succession

(Asked by: username_0 on 2022-04-09)

I’d like to prevent a feedme feed from running more than once when multiple requests are received within a few seconds of each other.

My first guess is that I would want to target an event such as ‘’’BeforeFetchFeed’’’ to determine when to prevent the feed from being parsed.

Another more lo-fi option may be to use the Guzzle option ‘’’Delay’’’ and setting the value to increase after each subsequent run. Would this be possible in the config options?

Any ideas?

**Tags:** plugin-development, plugin-feedme, events, guzzle

---

## 1 answers

### Answer by username_1 on 2022-04-11. Score: 1 | Accepted answer

You can cancel a FeedMe job before it starts by invalidating the EVENT_BEFORE_PROCESS_FEED event in the Process class. In your case, it sounds like you want to check whether the Feed is already in the queue, so from within a module you could do something like this:
Event::on(Process::class, Process::EVENT_BEFORE_PROCESS_FEED, function(FeedProcessEvent $event)
  {
    $existingJob = 0;
    foreach(array_column(Craft::$app->queue->jobInfo, 'description') as $index => $string) {
      if (strpos($string, $event->feed->name) !== FALSE) {
        ++$existingJob;
        if ($existingJob > 1) {
          $event->isValid = false;
        }
      }
    }
  }
);


---

