Closed (fixed)
Project:
Feeds
Version:
7.x-2.0-beta4
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
31 Jul 2019 at 06:02 UTC
Updated:
16 Aug 2019 at 08:24 UTC
Jump to comment: Most recent
Comments
Comment #2
megachrizYou could use the lock system to ensure the fetcher does only one API call at a time:
lock_acquire()to create a lock. If it returnsTRUE, then continue and make the API call. If it returnsFALSE, then abort.lock_release(). It would be wise to wrap the API call in a try-catch block, so you can release the lock whenever an exception occurs.The tricky part is ensuring that the aborted import can start at a later time. Maybe it's enough to just throw a FeedsLockException whenever fetching cannot happen. Else you may need to use Job Scheduler to schedule the import task at a later time. From
FeedsSource::scheduleImport():You can decide whether you want to check for locks in the implementation of the fetcher or at the start of an import, by implementing the hook
hook_feeds_before_import().. There could be more than one fetch in a single import, but this depends on the implementation of the fetcher: the fetcher may report that fetching is not complete. See FeedsFileFetcher:Comment #3
oppure commentedHi
thank you very much for your help!
On my development environment I was unable to reproduce a situation where my custom feed is called more than once at the same time when feed is run by cron. Anyway running two feeds manually or one manually and one by cron worked ok to call the custom fetcher more than once at the same time.
Using lock_acquire() seems to work very well to prevent more than one call at the same time.
As you guessed throwing a FeedsLockException will cause the job to be rescheduled at a later time (rescheduling happens at the next cron run and according to parameter set in "Periodic import" so if "Periodic import" is set to off no rescheduling will happen), so it's perfect!