Shop Data Sync Cronjob¶
Introduction¶
Purpose¶
Use this cronjob to automatically perform the Shop Data Synchronization.
Note
ASA2 automatically determines which shops will be processed based on whether a data source is set up and whether the data freshness setting requires updating.
This cronjob runs the same process as clicking the big sync button on the shop data page.
Basics¶
To learn more about cronjobs in general, check out the Introduction chapter.
Setup¶
To learn more about setting up and using ASA2’s cronjobs, see the dedicated Cronjob Setup chapter.
Usage¶
Name¶
The internal name of this cronnjob is \Asa2\Module\Shops\Cron\SyncShopData
.
Therefore, use it with the Server-side execution like this:
bash script.sh Asa2SyncShopData --shop_id=1,2,3 --verbose=1
And with WP Cron API and ASA2’s Cron Wrapper like this:
$cronWrapper = new \Asa2\Cron\Wrapper('\Asa2\Module\Shops\Cron\SyncShopData');
$cronWrapper->setOptions([
'shop_id' => '1,2,3',
'verbose' => 1
]);
$cronWrapper->execute();
REST API Endpoint¶
The REST API endpoint name of this cronjob is sync-shop-data
.
Example:
https://example.com/wp-json/asa2/v1/sync-shop-data/?token=[your-token]&shop_id=1,2,3&verbose=1
Check Cron REST API for more details about running ASA2’s cronjobs via URL.
Recommendations¶
The frequency of execution should be adjusted to the data freshness setting (see Data Freshness) of all shops that have data. For example, if you set the data freshness for one shop to 12 hours, the cronjob should also run at least every 12 hours.
Also note the limit option. This should not prevent a regular update. For example, if you have two shops with a data freshness set to 6 hours and the cronjob runs every 12 hours with a limit of 1, one shop cannot be processed. Here the limit should be set to at least 2 or the cronjob should run every 6 hours.
Server Capacity¶
If many shops with external CSV data sources are used, it is essential to ensure that the data synchronization process is adapted to the server capacities. If there are hundreds of thousands of records or more from all the shops combined, it may take a while to process them. This can bring the server to a certain load.
If it is a fairly powerful server, e.g. a dedicated server, all this should not be a problem and you can use system monitoring to check to what extent the performance limits are reached.
However, if it is a simple, inexpensive web hosting package, the server capacities are shared with other instances and it could lead to performance peaks if you synchronize all shop data at once. In this case, it would be better to use the shop_id option to create a single cronjob for each shop and run the jobs at different times over the course of the day (or better yet, only at night).
Options¶
force¶
Use the force
option to start the synchronization although the shop data is still fresh.
bash script.sh Asa2SyncShopData --shop_id=42 --force=1
help¶
Prints a help text showing all available options and how to use them.
bash script.sh Asa2SyncShopData --help
limit¶
Limits the amount of shops to be synchronized.
Note
If this option is not used, all shops will be considered.
Example to raise the limit:
bash script.sh Asa2SyncShopData --limit=50
If you know what you are doing, you can turn off the limit with -1
.
Note
Working without a limit may not be beneficial if you have a lot of shops in use, as the job could then load the system for a longer period of time.
Example to disable the limit:
bash script.sh Asa2SyncShopData --limit=-1
php¶
With the php
option, you can tell the ASA2 cronjob what PHP executable it should use to execute the command. With some webhosters the standard command “php” executes an outdated version and there is a special command for each version, e.g. “php74”, “php81” or “/opt/php81/bin/php”.
Please check which PHP version is required for the use of ASA2 here: https://bit.ly/asa2-php-version
bash script.sh Asa2_Module_Repo_Cron_Refresh --limit=10 --php=php74
bash script.sh Asa2_Module_Repo_Cron_Refresh --limit=10 --php=/opt/php81/bin/php
shop_id¶
This option allows you to specify the shops that should be processed. This is useful, for example, if you want to have the data of a particular shop always updated at the same time. Multiple IDs can be specified separated by commas (without spaces!).
If no shop IDs are defined, ASA2 determines the shops automatically.
You can find the ID of a shop in the ID column on the overview page of the shop section.
bash script.sh Asa2SyncShopData --shop_id=302,412
verbose¶
Use the verbose
option to get more information about the processed shops.
bash script.sh Asa2SyncShopData --shop_id=302,412 --verbose=1