Skip to content

Product Update Cronjob

Introduction

Purpose

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.

ASA2 cronjob item refresh

Basics

To learn more about cronjobs in general, check out the Cronjobs Intro chapter.

Setup

To learn more about setting up and using ASA2's cronjobs, see the dedicated Cronjobs Setup chapter.

Usage

Name

The internal name of this cornjob is Asa2_Module_Repo_Cron_Refresh.

Therefore, use it with the Cronjobs Setup Serverside execution like this:

text
bash script.sh Asa2_Module_Repo_Cron_Refresh --limit=10 --cat=31,40 --lifetime=7200

And with Cronjobs Setup Wp Cron Api and ASA2's Cron Wrapper like this:

php
$cronWrapper = new \Asa2\Cron\Wrapper('Asa2_Module_Repo_Cron_Refresh');
$cronWrapper->setOptions([
    'limit' => 10,
    'cat' => '31,40',
    'lifetime' => 7200
]);
$cronWrapper->execute();

REST API Endpoint

The REST API endpoint name of this cronjob is product-update.

Example:

text
https://example.com/wp-json/asa2/v1/product-update/?token=[your-token]&limit=10&cat=31,40&lifetime=7200

Check Cronjobs Setup Rest Api for more details about running ASA2's cronjobs via URL.

Recommendations

INFO

It is highly recommended to use this cronjob in combination with option Options Advanced 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:

text
0 * * * * bash /[wp_path]/wp-content/plugins/amazon-simple-affiliate/scripts/script.sh Asa2_Module_Repo_Cron_Refresh --lifetime=86400 --limit=11

There are several Product Update Cronjob Options you can use to fit the cronjob to your requirements.

text
bash script.sh Asa2_Module_Repo_Cron_Refresh -lt=3600 --limit=50 -cat=31 tag=sale --verbose --log --logpath=/home/me/tmp/asa2

Cronjob Calculator

To find your perfect settings, please check ASA2's cronjob calculator.

Options

cat

Use the 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.

text
bash script.sh Asa2_Module_Repo_Cron_Refresh cat=31,40

country_code

Filters the result of prodcuts to be updated by country code. Mulitple country codes must be separated by comma.

text
// 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

having_asin

By using this option, only products that have an ASIN (i.e. Amazon products) will be updated.

text
bash script.sh Asa2_Module_Repo_Cron_Refresh --limit=10 --having_asin=1

help

Prints a help text showing all available options and how to use them.

text
bash script.sh Asa2_Module_Repo_Cron_Refresh --help

id

With this option you can limit the result to products of the specified IDs. Multiple IDs can be specified separated by commas (without spaces!).

text
bash script.sh Asa2_Module_Repo_Cron_Refresh id=254,636,4986

lifetime

Use the 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 products older than two hours, use a lifetime of 7200.

text
bash script.sh Asa2_Module_Repo_Cron_Refresh --limit=50 --lifetime=7200

limit

Limits the amount of products to be updated. Default is 20.

INFO

If this option is not used, the limit is automatically set to 20.

Example to raise the limit:

text
bash script.sh Asa2_Module_Repo_Cron_Refresh --limit=50

If you know what you are doing, you can turn off the limit with -1.

INFO

Working without a limit may not be beneficial if you have a lot of products in use, as the job could then load the system for a longer period of time.

Example to disable the limit:

text
bash script.sh Asa2_Module_Repo_Cron_Refresh --limit=-1

log

Activates the cronjob log. This will write the cronjob results to a file defined with logpath.

logpath

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.

text
bash script.sh Asa2_Module_Repo_Cron_Refresh --limit=50 --lifetime=7200 --log --logpath=/home/me/tmp/asa2

pause

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.

text
// inserts a pause of 2 seconds between API requests
bash script.sh Asa2_Module_Repo_Cron_Refresh --limit=3 --pause=3 --verbose

ASA2 cronjob item refresh with pause option

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

text
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

With this option you can limit the result to products of shop specified by the IDs. Multiple IDs can be specified separated by commas (without spaces!).

text
bash script.sh Asa2_Module_Repo_Cron_Refresh shop_id=302,412

tag

Use the tag option to filter the results by tag slug. You can define multiple tags as comma separated list.

For example, only update products with tag slug "green" and "sale".

text
bash script.sh Asa2_Module_Repo_Cron_Refresh tag=green,sale

You can combine the cat and tag options. For example, only update repo items from category 31 and 40 with tag slug "green" and "sale":

text
bash script.sh Asa2_Module_Repo_Cron_Refresh cat=31,40 tag=green,sale

verbose

Use the verbose option to get more information about the updated products.

text
bash script.sh Asa2_Module_Repo_Cron_Refresh --limit=50 --lifetime=7200 --verbose

Invalid Products

Products that are detected as permanently invalid (ASIN no longer exists on Amazon) are handled specially by the refresh cronjob. For full details about invalid products, see Invalid Products.

By default, the cronjob will attempt to refresh an invalid product up to 5 times. After that, the product is permanently excluded from future cronjob runs to save API quota. This limit is configurable via Options > Products > Invalid Products > Max refresh retries (see Products Options: Invalid Products).

Retry count vs. limitCronjob behavior
Counter < limitProduct is included in refresh, counter incremented if still invalid
Counter >= limitProduct is excluded from refresh
Refresh succeedsStatus reset to OK, counter cleared

Setting the max retries to 0 excludes all invalid products from the cronjob immediately.

To manually refresh a product regardless of the retry counter, use the "Refresh item data" checkbox on the product editor page.

ASA2 - The Amazon Affiliate Plugin for WordPress