1

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?

1 Answer 1

1

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;
        }
      }
    }
  }
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.