Product Update Cronjob¶
Table of contents
Use this cronjob to automatically update the items in your Products section (see Products).
This way you can avoid products being updated via API when a visitor opens a page.
The internal name of this cornjob is
Therefore, use it with the Server-side execution like this:
bash script.sh Asa2_Module_Repo_Cron_Refresh --limit=10 --cat=31,40 --lifetime=7200
$cronWrapper = new \Asa2\Cron\Wrapper('Asa2_Module_Repo_Cron_Refresh'); $cronWrapper->setOptions([ 'limit' => 10, 'cat' => '31,40', 'lifetime' => 7200 ]); $cronWrapper->execute();
It is highly recommended to use this cronjob in combination with option Server-side request limit handling.
If you are a power user with several hundret products to be refreshed via this cronjob, you should use the server-side cronjob.
Let’s assume you have 250 products in your Products section and you want to refresh them once a day. If you configure the cronjob to run once every hour, it should refresh 11 products in every run: 250 products / 24 hours = 10.41 products per hour.
To make sure all 250 products will be handled within 24 hours, set option
lifetime to “86400” (seconds) which means a product will only get refreshed once per day.
Replace [wp_path] with the local server path of your WordPress installation.
This cron job will run at minute zero, every hour:
0 * * * * /[wp_path]/wp-content/plugins/amazon-simple-affiliate/scripts/script.sh Asa2_Module_Repo_Cron_Refresh --lifetime=86400 --limit=11
There are several Options you can use to fit the cronjob to your requirements.
bash script.sh Asa2_Module_Repo_Cron_Refresh -lt=3600 --limit=50 -cat=31 tag=sale --verbose --log --logpath=/home/me/tmp/asa2
cat option to filter the results by category ID. You can define multiple categories as comma separated list.
For example, only update repo items from category 31 and 40.
bash script.sh Asa2_Module_Repo_Cron_Refresh cat=31,40
Filters the result of repo items to be updated by country code. Mulitple country codes must be separated by comma.
// update 10 items from the US and German store: bash script.sh Asa2_Module_Repo_Cron_Refresh --limit=10 --country_code=DE,US // update all items from the Canadian store bash script.sh Asa2_Module_Repo_Cron_Refresh --limit=-1 --country_code=CA
Prints a help text showing all available options and how to use them.
bash script.sh Asa2_Module_Repo_Cron_Refresh --help
With this option you can limit the result to products of the specified IDs. Multiple IDs can be specified separated by commas (without spaces!).
bash script.sh Asa2_Module_Repo_Cron_Refresh id=254,636,4986
lifetime option to only include items with a last refresh time older than the defined lifetime in seconds. Default is 86400 (one day).
For example, if you want to use the cronjob to only update repo items older than two hours, use a lifetime of 7200.
bash script.sh Asa2_Module_Repo_Cron_Refresh --limit=50 --lifetime=7200
Limits the amount of repo items to be updated. Default is 10.
bash script.sh Asa2_Module_Repo_Cron_Refresh --limit=50
-1 for no limit.
bash script.sh Asa2_Module_Repo_Cron_Refresh --limit=-1
If you want to use the
log feature, you must define a directory path. It must be writable. ASA2 will create a log file asa2reporefresh.log there. Using a log rotate function new files will be created when the old reaches 20MB.
bash script.sh Asa2_Module_Repo_Cron_Refresh --limit=50 --lifetime=7200 --log --logpath=/home/me/tmp/asa2
Can be used to insert a fixed pause of the specified seconds between two API requests. This may help to avoid the RequestThrottled API issue.
// inserts a pause of 2 seconds between API requests bash script.sh Asa2_Module_Repo_Cron_Refresh --limit=3 --pause=3 --verbose
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. “php73” or “php74”.
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
tag option to filter the results by tag slug. You can define multiple tags as comma separated list.
For example, only update repo items with tag slug “green” and “sale”.
bash script.sh Asa2_Module_Repo_Cron_Refresh tag=green,sale
You can combine the
tag options. For example, only update repo items from category 31 and 40 with tag slug “green” and “sale”:
bash script.sh Asa2_Module_Repo_Cron_Refresh cat=31,40 tag=green,sale