Problem/Motivation
Under certain circumstances content gets imported via a manual import, but not when running cron.
Possible causes:
- Insufficient permissions, as cron is ran as anonymous user.
#2541944: Switch to feed author or user 1 during imports (taxonomy mapping does not work with cron) - An incompatible combination of settings: "Periodic import" and "Import on submission" both turned off and using the standalone form.
#2445477: Process in background not working with certain combination of settings
Proposed resolution
Some causes are known (see above), but likely not all. The problem has been reported in multiple issues, so these issues should be sorted out to gather clues. When the other causes are known, it would be best if the bug(s) could be replicated with an automated test. This makes it easier to find out if a proposed fix really fixes the issue or just partly.
Remaining tasks
- Sort out the issues that reported this problem (and close duplicates).
- Find the cause of the issue.
- Replicate the issue with an automated test, if possible.
- Propose a fix for the issue.
Temporary Solution
The temporary solution is to manually kick off the feed import with a custom hook_cron(). For feeds not attached to nodes, the code will look like this:
function MODULE_NAME_cron() {
$name = 'FEED_NAME';
$source = feeds_source($name);
$source->import();
}
For feeds that are attached to nodes, you'll need to load a list of node ids then run the import on each one:
function MODULE_NAME_cron() {
$node_type = 'CONTENT_TYPE';
$feed_type = 'FEED_NAME';
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node');
$query->entityCondition('bundle', $node_type);
$result = $query->execute();
$feed_nids = array_keys($result['node']);
foreach ($feed_nids as $feed_nid) {
$source = feeds_source($feed_type, $feed_nid);
$source->import();
}
}
Related issues
These issues may be reports of the exact same problem:
- #1553190: data not import during cron run
- #1716084: Cron fails on import of csv from web published csv from a google spreadsheet
- #2305319: Feeds only importing occasionally
- #2450365: Importer is not rescheduled for new sources when using attach to node
- #2462475: News Feeds does not import all feeds?
- #2174841: Call FeedsSource::schedule() after manual import.
- #2059677: Feed using wrong importer when import attempted at Cron
- D6 #1873812: Feeds not importing on cron
- #1510432: Cron job doesn't import all feed items.
These issues look like a different problem, but are related to cron too:
- D6 #927782: No new items on cron (issues with job scheduler configuration)
- #1029102: Importing Large CSV document (downloaded and processed in the background)
- #2049561: Unable to import large document during cron
- #2445477: Process in background not working with certain combination of settings
- #2385521: Broken image if run by cron
- #2275893: Process for non-periodic imports will get stuck
- #1558118: Process in background does not queue cron task for import
- #1947288: job_scheduler always set for import in the past
- #1994876: Fetcher with batch process does not fully-import during cron
- #2513802: "Import on submission" stucks at 56 %
Closed cron issues:
- #2313267: Feeds cron dependant upon job scheduler cron?
- #2267597: Periodic Import not working
- #1515774: Feeds not updating with job scheduler + cron
- #1851426: Feeds Cron Schedule hangs
- #1889024: Cron task to auto run feed importer always running 2% at a time?
Original report by tamarackmedia
I am importing a CSV via a URL (HTTP Fetcher), set to periodic import "as often as possible."
I had successfully used the exact same setup to import via cron on another site running Feeds 7.x-2.0-alpha7.
Manual import works fine on the new site (running latest release, 7.x-2.0-alpha8), but nothing happens on cron. I rolled back to Feeds 7.x-2.0-alpha7 and it works fine.
Comment | File | Size | Author |
---|---|---|---|
#13 | feeds_periodic_import.png | 20.72 KB | dineshw |
Comments
Comment #1
twistor CreditAttribution: twistor commentedI just setup an importer to run as often as possible with alpha7, upgraded to alpha8, and it works fine.
Can you provide your configuration?
Comment #2
essenceofginger CreditAttribution: essenceofginger commentedI'm seeing the same thing. Other than the 'periodic import' setting, I can't figure out how else I should be configuring the import to run on cron. Driving me nuts!
Comment #3
twistor CreditAttribution: twistor commentedComment #4
ajayg CreditAttribution: ajayg commentedI am facing this issue and driving me nuts. I have a drupal multisite and it used to work for both sites and now it stopped only for one site.
Manual import works fine on both site but through cron works only for one site. On site where it does not work, The logs says cron ran and job scheduler processed n records. But the feed logs does not reflect new items created. No other error.
Comment #5
ajayg CreditAttribution: ajayg commentedComment #6
metabrown CreditAttribution: metabrown commented+1 upgrade to Feeds 7.x-2.0-alpha8 broke cron updating, rolling back to alpha7 fixed the issue.
Comment #7
ajayg CreditAttribution: ajayg commentedConfirming the multisite which was upgraded , cron does not work. But using same multisite code , a new site created on scratch, it works fine. So same code is bahaving differently which points to some database or variable discrepancy.
Comment #8
MhueD CreditAttribution: MhueD commentedFeeds 7.x-2.0-alpha8 AND 7.x-2.0-beta1 -- Cron hook has completely stopped working (on our sites) and is rather easy to detect. For instance, this code:
In this case the watchdog record DOES get written, and yet the Feed itself never runs. This last part is also easy to establish, because one can put a hook like:
Also, if we try:
...the 'die' statement runs...so I guess in the case above the startImport is failing but control continues getting passed on to the Watchdog call anyway.
FYI: This feed only takes a few seconds to run, and it DOES run completely successfully as a standalone form from the /import UI. Perhaps even stranger...it doesn't seem to fix the Cron call if the Feed is reset to work off of a node (a common fix listed in some threads on this topic). The site itself is 7.37 Core. Also, we have tried sandboxing with Ultimate Cron with no effect. If this is a setting/db-change, I would love to have some idea of what direction to take that research, because chasing down every conceivable 'cross-talk' interaction with every other module is beyond our scope at the moment!
Below is the export code of the Feed Definition. Please note, however, that we have changed quite a few of the settings, especially those effecting timing, and the behavior stays the same. For instance, having the import run 'as often as possible' has no effect on the success of each attempt, though it does initiate the attempts as requested.
Comment #9
MegaChriz CreditAttribution: MegaChriz at WebCoo commentedClosed #2625908: Cron Not triggering Feeds - Historical Problem Returns as a duplicate.
Comment #10
MegaChriz CreditAttribution: MegaChriz at WebCoo commentedI've created a summary of the issue. While I do know possible causes have been reported in this issue (and perhaps in other issues too), I've stated that the cause of the issue is still unknown. Because there are so many issues open about this problem, I have no overview of all possible causes and as such I can not judge if one of them is a real cause or a misunderstanding of how something in Feeds is supposed to work.
The first step is to consolidate the issues: gather clues from each of them and then close duplicates. Then with the clues gathered, we can look for the cause of the issue. Perhaps there is more than one cause. When the cause is known, it would be best if the bug could be replicated with an automated test. This makes it easier to find out if a proposed fix really fixes the issue or just partly.
Comment #11
dineshw CreditAttribution: dineshw as a volunteer and at TATA Consultancy Services for Pfizer, Inc. commentedThis should be straight but somehow it’s not working with feeds:
Can someone summarise steps for testing periodic import
Feed importer configured to import json fields works perfectly when run via import link
Same importer does not run via Cron run even after having option periodic import enabled.
Comment #12
MegaChriz CreditAttribution: MegaChriz at WebCoo commentedSteps for using periodic import:
Comment #13
dineshw CreditAttribution: dineshw as a volunteer and at TATA Consultancy Services for Pfizer, Inc. commentedHi Chriz,
See attached screenshot. My feeds are not attached to content type and set to Periodic import of 1 hour and I have crontab configured for every 15 mins.
But if I run cron either manually or via crontab, I dont see feeds getting imported in content.
But, If I simply use below hook in cusotm module to execute feeds import it does work.
Comment #14
pianomansam CreditAttribution: pianomansam commentedUpdating title to better reflect this as a meta issue.
Comment #15
pianomansam CreditAttribution: pianomansam commented@dineshw's hook_cron() example is helpful, but it only works on feeds not attached to nodes. Here's an example of how to handle node-attached feeds:
I've also updated the issue summary with these details.
Comment #16
daboo CreditAttribution: daboo as a volunteer commentedI'm having this exact same problem in Drupal 8. Feeds were working as expected and then as I added content and functionality to the site it stopped working. I attributed to another module, but have no idea exactly what the root cause is at this point.
Does anyone have a manual code change as listed above that may work for Drupal 8 as a workaround?
Comment #17
twistor CreditAttribution: twistor as a volunteer commented@daboo, your problem is a separate issue. This is for D7. The cron code in D8 is very different.
Comment #18
dineshw CreditAttribution: dineshw as a volunteer and at TATA Consultancy Services for Pfizer, Inc. commented@all : use drush feeds-import command to setup as cron, it works very straight!
Advise to look it as alternative instead ofdrupal cron.
To configure it over command line refer https://docs.acquia.com/cloud/manage/cron#direct
Comment #19
daboo CreditAttribution: daboo as a volunteer commentedThanks for clearing that up twistor
Comment #20
ervit CreditAttribution: ervit commentedI'm on 7.x-2.0-beta3 and cron execution broke when I changed the importer's expiry setting from 1 year to Never (it executed just a few or just one Feed out of over 20 that were based on the same importer). Manual cron launches weren't successful either. As soon as I changed the expiry back to 1 year, Feeds imported all feeds on cron run. I don't know if this is related or not, but it's not good.
Comment #21
ajayg CreditAttribution: ajayg as a volunteer commentedI had faced these issues in the past but for some reason they have disappeared for now for several months. Is anyone using latest Drupal build and latest feeds beta3 facing these? Perhaps the issue was outside Feeds.
Comment #22
MegaChriz CreditAttribution: MegaChriz at WebCoo commented@ajayg
This is still an issue. Today I found out two things:
Earlier I became aware that due that cron is ran as an anonymous user, import may not run due to insufficient permissions. This is being handled in #2541944: Switch to feed author or user 1 during imports (taxonomy mapping does not work with cron).
Comment #23
ajayg CreditAttribution: ajayg as a volunteer commentedWow @MegaChriz, kudos to your persistence for chasing this.
Just FYI, I used to get this issue with Periodic Import "on" and Process in background "on". Actually it would appear suddenly on a running site where it used to work and suddenly stop without the changes to those settings. Fortunately it has not happened for a while so this issue may look same but may be multiple reasons underneath.
Comment #24
MegaChriz CreditAttribution: MegaChriz at WebCoo commented@ajayg
If you have many importers, maybe you want to try out the patch from #2868134: Show next time that the source will be imported to see if it gives any false information? I hope that the changes provided in that patch will give more insight for people running into this issue. The patch make Feeds check the queue and job_schedule tables to see if any imports are scheduled. If people running into this issue see 'Next import: not scheduled.' on the import page then at least they know import didn't suddenly stop because of permission issues. What exactly caused the importers to suddenly stop in this case, is a whole other story.
Comment #25
Barnettech CreditAttribution: Barnettech commentedmaking the module and running from cron works for feeds attached to nodes, but how to run more than one feed, this should work, but it doesn't? What am I missing? Just the first feed runs on cron run, the 2nd one never runs.
I'm seeing the error: FeedsHTTPRequestException: Download of failed because its scheme could not be determined. The URL is expected to start with something like 'http
Comment #26
Barnettech CreditAttribution: Barnettech commentedfyi, this worked and solved the FeedsHTTPRequestException error
and it works with multiple feeds.
Comment #27
joelpittet