Hi,

We are using feed module to import the third party data to our site in a specific time interval(As often as possible). The third-party record is not updated automatically to our site. The record updated to our site only after manually running the Cron in admin end.

Please let us know if the "Import period" will run based on time period or it will run based on the CRON time.

Comments

John_sm created an issue. See original summary.

megachriz’s picture

Category: Bug report » Support request
Status: Active » Needs review
StatusFileSize
new1.34 KB

Yes, the import period depends on cron.

I see that this isn't mentioned on the form, while the D7 of Feeds did mention it. Attached a patch to fix that.

sethu_sk’s picture

Hi MegaChriz,

I have a question:

How do I run the feed CRON alone in every 'X' minutes without running the site CRON?

Please clarify it.

megachriz’s picture

You could write a shell script that runs every x minutes and in there run items from the queue "feeds_feed_refresh".

Example:

use Drupal\Core\Queue\RequeueException;
use Drupal\Core\Queue\SuspendQueueException;

/**
 * Number of seconds to run tasks from the "feeds_feed_refresh" queue.
 *
 * @var int
 */
const FEEDS_FEED_REFRESH_TIME = 60;

$queue_worker = \Drupal::service('plugin.manager.queue_worker')->createInstance('feeds_feed_refresh');
$end = time() + FEEDS_FEED_REFRESH_TIME;
$queue = $queue_factory->get($queue_name);
$lease_time = FEEDS_FEED_REFRESH_TIME;
while (time() < $end && ($item = $queue->claimItem($lease_time))) {
  try {
    if ($item->created > Drupal::time()->getRequestTime()) {
      // Item was postponed! Release the item and ontinue to the next one.
      $queue->releaseItem($item);
      continue;
    }

    $queue_worker->processItem($item->data);
    $queue->deleteItem($item);
  }
  catch (RequeueException $e) {
    // The worker requested the task be immediately requeued.
    $queue->releaseItem($item);
  }
  catch (SuspendQueueException $e) {
    // If the worker indicates there is a problem with the whole queue,
    // release the item and the queue.
    $queue->releaseItem($item);

    watchdog_exception('cron', $e);

    // Stop the loop.
    break;
  }
  catch (\Exception $e) {
    // In case of any other kind of exception, log it and leave the item
    // in the queue to be processed again later.
    watchdog_exception('cron', $e);
  }
}

  • MegaChriz committed 7b70887 on 8.x-3.x
    Issue #3070549 by MegaChriz: Clarified on the feed type form that the...
megachriz’s picture

Status: Needs review » Fixed
Issue tags: -automatic import is not working

Tests are passing for the patch, so committed #2.

megachriz’s picture

Oh wait, in a shell script you could also use the Drush command 'queue-run'. Is a lot simpler.

drush queue-run feeds_feed_refresh

https://drushcommands.com/drush-9x/queue/queue:run/

sethu_sk’s picture

Hi MegaChriz,

I am new to drupal 8, where do I need to write the code, do i need to create a module for this?

Kindly clarify it.

megachriz’s picture

Do the instructions on the following page help?
https://www.webfoobar.com/index.php/node/25

From the example there, instead of drush @site1 cron, your command would be drush @site1 queue-run feeds_feed_refresh.

The code presented there would go into a .crontab file.

Either way, you need to be able to run cron jobs to run imports regularly. With the method described above you can avoid running cron for all modules.

megachriz’s picture

After posting I just realized you'll get more control about which module's cron to run with the Ultimate Cron module.

On crontab you would configure to run regular cron every minute and with Ultimate Cron you can configure in the Drupal user interface per module and per queue how often they may run.

I haven't tried the module for D8 yet, but the D7 version worked great.

sethu_sk’s picture

Am getting below error message.

"Drupal\Component\Plugin\Exception\PluginNotFoundException: The "feeds_feed_refresh" plugin does not exist" issue while running the custom drush command for drupal 8.

megachriz’s picture

@John_sm
Ah, I forgot the queue "feeds_feed_refresh" is a derivative, which means in this case that a queue plugin is generated for every feed type. So the actual queue would be called something like "feeds_feed_refresh:my_feed_type" where "my_feed_type" is the machine name of your feed type.

drush @site1 queue-run feeds_feed_refresh:my_feed_type

Secondly, the queues can be empty, because they require feeds_cron() to be called in order to schedule imports. So it looks like your command would also need to call that function:

drush @site1 php:eval "feeds_cron();"
sethu_sk’s picture

@MegaChriz, i have added two drush command in cronjob to import the external data into our site. I have a question, in your above feeds_feed_refresh code, what is the value for $queue_name.

Will the above code work when we callback the method without any drush command?

megachriz’s picture

@John_sm
The queue name is feeds_feed_refresh: plus the feed type ID.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.