For arlanix/product-feed 1.0.0
Cron and command line
Commands, background jobs and hosting requirements for feed delivery.
The cron jobs
Every feed is delivered by the Magento cron. The jobs run every minute and return at once when there is nothing to do.
| Job | Group | Schedule | Does |
|---|---|---|---|
arlanix_product_feed_deliver |
arlanix_product_feed |
every minute | Collects changes for up to 20 seconds, then delivers due file feeds and pending Merchant API products. Each feed runs under its own lock. |
arlanix_product_feed_mark_stuck_runs |
default |
every 5 minutes | Marks ended processes with no progress for the configured timeout as stuck; default 30 minutes. |
arlanix_product_feed_refresh_delivered |
default |
02:20 daily | Queues unchanged products for refresh according to the channel’s refreshAfterDays. |
arlanix_product_feed_clean_runs |
default |
03:25 daily | Removes expired runs and abandoned temporary files, working for up to 30 seconds. Retention is set in Configuration. |
The arlanix_product_feed group runs in a separate process (use_separate_process), so a long delivery does not hold up the rest of the store's cron, and the feeds' work never runs in Magento's index group. Prices and stock are still Magento's: its own indexer cron writes them to its price and stock indexes, and the feeds hear of them once it has.
Every run keeps what it said, so a long run history grows the arlanix_product_feed_run and arlanix_product_feed_run_message tables. The settings the jobs read are in Configuration.
The feed views
The modules add four mview views. Their database triggers record every change to products, categories and stock: a save in the admin, Update attributes from the product grid, an import, an ERP writing to the tables. What they record is for the feeds sent row by row: a file feed reads the catalogue whole each time it is delivered and needs no record of what changed.
| View | Records | Its changes |
|---|---|---|
arlanix_product_feed_category |
categories | Hand the products of the category, and of every category below it, to arlanix_product_feed_product. |
arlanix_product_feed_inventory |
source quantities, from Arlanix_ProductFeedInventory |
Hand the products to arlanix_product_feed_price_stock. |
arlanix_product_feed_product |
products, their websites, links and categories | Tell each feed sent row by row which of its products changed: its next run reads them from the catalogue, compares their rows with what its platform holds and sends the ones that moved. |
arlanix_product_feed_price_stock |
stock items, and the products whose price or stock status Magento's price and stock indexers have just written | Tell each feed sent row by row which of its products' price or stock changed, an order's included. |
These views are managed by the feed module, not Magento’s indexer commands. They do not appear in System → Index Management. setup:upgrade subscribes their triggers.
For MSI stock updates, keep the inventory.reservations.updateSalabilityStatus consumer running. Magento’s consumers_runner starts it unless excluded in env.php. To start it manually, run bin/magento queue:consumers:start inventory.reservations.updateSalabilityStatus.
How a feed reads the catalogue
File feeds read the selected catalogue in batches of 500 products. Merchant API feeds map changed products and store their payloads for delivery and retries; changes to feed settings trigger a full pass.
Magento's indexes
Feeds use Magento’s price and stock indexes: catalog_product_price, cataloginventory_stock and, with MSI, inventory. An invalid index pauses delivery with waiting until Magento reindexes it. A full reindex already in progress does not block delivery: feeds use the previous index until Magento replaces it.
If a valid price index has no row for a product, the feed obtains its price through Magento’s pricing framework for the feed’s customer group. Product selection still follows the feed’s conditions and stock settings, independently of storefront stock filtering.
Magento’s indexer_reindex_all_invalid job rebuilds invalid indexes. To rebuild prices manually, run bin/magento indexer:reindex catalog_product_price.
Check that the cron runs
The crontab of the Magento file system owner must have a line with bin/magento cron:run. To see it, run the following as that user:
crontab -l
To see whether the Arlanix jobs ran:
SELECT job_code, status, MAX(finished_at) AS last_finished, COUNT(*) AS n
FROM cron_schedule
WHERE job_code LIKE 'arlanix_%'
GROUP BY job_code, status
ORDER BY job_code, status;
A success row with a recent last_finished for each job means all is well. The admin needs no SSH for the same answer: the Cron state item of the support bundle reports when the Arlanix jobs last ran and how the last 24 hours went.
When a feed never runs, Troubleshooting says what to check.
See where the feeds stand
bin/magento arlanix:product-feed:status
It changes nothing, and prints:
- under Changes waiting, how many changes each feed view still holds for the feeds sent row by row;
- Magento's indexes, valid or the ones that need a reindex, which every feed waits for; see Magento's indexes;
- under Active feeds, how each active feed's last run ended and when, in UTC, how many runs in a row did not deliver, a run under way, and what the feed waits for.
A count under Changes waiting that keeps growing means the sync does not keep up or does not run: see Check that the cron runs. bin/magento arlanix:product-feed:generate --all takes every change, then delivers every feed.
Run a feed from the command line
arlanix:product-feed:generate takes the changes waiting for the feeds sent row by row, then delivers feeds as Generate does, without waiting for the cron. It is the way to run a feed before the cron is set up, on a store with no cron at all, or from a deployment script.
To deliver one feed, run the following in the Magento root:
bin/magento arlanix:product-feed:generate --feed=FEED_IDENTIFIER
Replace FEED_IDENTIFIER with the feed's identifier, as the Identifier column of Arlanix → Feeds shows it.
The command takes these options:
| Option | Does |
|---|---|
-f, --feed=FEED_IDENTIFIER |
Delivers this feed. |
-a, --all |
Delivers every active feed. |
Name a feed with --feed, or use --all.
The command prints what it does, where the file went, and how each feed's run ended:
Taking the changes waiting
google-shopping
Delivered 181 row(s) to https://your-store/media/arlanix/product-feeds/google-shopping.xml.
done
The last line of each feed is one of the following:
| Line | Means |
|---|---|
done |
The feed was delivered. |
busy |
The cron or another command was running the same feed, so this one did nothing. |
waiting |
One of Magento's price and stock indexes needs a reindex; see Magento's indexes. |
refused |
Every product was left out and the feed does not allow an empty one: nothing was published or taken down, and the published file is unchanged; see An empty feed is never published. |
failed |
The run failed, for the reason printed on the line before. |
The command exits with one of these codes:
| Code | When |
|---|---|
0 |
Every feed ended done, busy or waiting, or --all found no active feed |
1 |
At least one feed ended refused or failed, or the command stopped before any feed ran, such as for a feed identifier that does not exist. |
2 |
Neither --feed nor --all was provided. |
A deployment script that must know a feed went out checks for done, since busy and waiting also exit with 0.
Runs from the command line are recorded as triggered by cli, with the version and limits of the command-line PHP they ran under; the support bundle's Feed run history lists them.
Where the files are
A file feed is published under pub/media/arlanix/product-feeds/:
https://your-store/media/arlanix/product-feeds/google-shopping.xml
When the feed's File name is empty, the file is named after the feed's identifier, with the extension of its format: .csv, .tsv, .xml, .json or .ndjson. A file name the store types is kept, with its extension set to the format's when the feed is saved. The web server decides the Content-Type from the extension, so make sure it knows .json and .ndjson. The platforms fetch this address, so it must be reachable from the internet without a login: a staging site behind HTTP authentication or an IP allow-list cannot be fetched.
The file is replaced on every run; a run that fails leaves the previous file in place.
More than one web server
The cron writes the file into pub/media/arlanix/product-feeds/ on the server it runs on. A platform that fetches the feed can be answered by any web server behind your load balancer, so all of them must see the same file. Use one of these:
- Keep
pub/mediaon storage the servers share, such as NFS, as Magento's catalogue images already need. Sharing onlypub/media/arlanix/product-feedsis enough for the feeds. - Keep media in S3 with Magento's remote storage; see Media in S3.
Magento's database media storage, Database (Deprecated) under Storage Configuration for Media, does not carry the feeds: the file stays on the disk of the server that ran the feed, and the other servers answer 404.
The cron can run on any of the servers. With Magento's default lock provider, db, a feed's lock is in the database, so a feed is never run twice at once, whichever servers run the cron; with the file provider each server has its own locks, so run the cron on one server only. The file is built in var/arlanix/product-feed/artifacts on the server that runs it, which needs room for the largest feed.
Media in S3
With Magento's remote storage, set up with bin/magento setup:config:set --remote-storage-driver=aws-s3 and the bucket's options, the feed is uploaded to the bucket as media/arlanix/product-feeds/<file name>. It is uploaded whole, so a platform fetching it during a run gets the previous file or the new one, never half of one. The feed's address is the store view's media URL: point Base URL for User Media Files and Secure Base URL for User Media Files at the bucket, or at the CDN in front of it, as for the catalogue's images. The file is built on the server's own disk first, in var/arlanix/product-feed/artifacts.
Varnish and a CDN
A feed keeps its address from run to run, so a cache in front of the store that keeps files from /media/ gives the platforms the old file until its copy expires. The platform then shows the prices and stock of an earlier run, while the grid says the feed was delivered.
Magento's own Varnish configuration, exported under Stores → Configuration → Advanced → System → Full Page Cache, passes /media/ to the web server uncached. A VCL changed to cache media, a hosting provider's VCL or a CDN may not. Magento's sample nginx and Apache configurations send Cache-Control: no-store for .xml and .csv files in pub/media, which keeps them out of such a cache, but not for .tsv, .json, .ndjson or a file name with another extension.
To keep the feeds out of Varnish, pass their folder in vcl_recv, before any rule that caches media:
if (req.url ~ "^/(pub/)?media/arlanix/product-feeds/") {
return (pass);
}
On a CDN, add a rule that bypasses its cache for /media/arlanix/product-feeds/.
To see whether a cache answers, compare the file's Last-Modified with the time of the feed's last run in the grid:
curl -sI https://your-store/media/arlanix/product-feeds/google-shopping.tsv | grep -i last-modified
See The log for diagnostic checks.