In our project we want to have an automatic productCatalog synchronizaton cronjob. We are facing the following issue:
Symptom
Customer created a syncJob to sync from staged to online. After running the syncJob by the first time - everything was working fine. After the second time, the changes were not reflecting in online version.
Reproducing the Issue
- Create a new CatalogVersionSyncJob.
- Do some changes on a product in the productCatalog, and run the syncJob.
- Do another changes on another product, and run the same syncJob again
- The changes are not present in the online catalog.
Cause
The customer triggers the same CronJob twice.
it’s not recommended to rerun the same cronjob, because it can and will cause errors, and the Synchronization will not workproperly.
After a cronjob finishes its task it creates dump media which holds the information about the synchronized items. After running it again, it will first compare the dump medias and search for changes only in the items, which are in the dump media. This causes why there are 0 items synchronized (no changes in online version) after rerun.
Does anyone facing the same issue? And what was your solution for this problem?
When a CatalogVersionSyncJob is executed, the pending items in each execution round are stored in a Dump Media file. In each round, only the pending items from the previous round will be synced until two consecutive Dump Media files have the same count of pending items, meaning nothing else can be synced.
If you run a sync CronJob that has already been executed, it will only try to sync the pending items from the latest execution, meaning successfully synced items won't be synced again.
For that reason, the standard approach for catalog syncing is to always create a new sync CronJob every time.
If you need to schedule a sync, you can add the Trigger to the Job instead of the CronJob.
The following example adds a Trigger to a sync job to run every minute:
$syncJobProductCatalog = sync <PRODUCT_CATALOG>\:Staged->Online
INSERT_UPDATE Trigger; job(code)[unique = true]; second; minute; hour; day; month; year; relative; active; maxAcceptableDelay
; $syncJobProductCatalog ; 0 ; 1 ; -1 ; -1 ; -1 ; -1 ; true ; true ; -1
Keep in mind that in this example, a new CronJob would be created every minute, so it's recommended to create an additional cleanup CronJob to prevent too many sync CronJob instances from piling up in the database.