Cron and command line
On this page

This page is for version 1.0. Read the current version.

Cron and command line

For the developer who looks after the store. The store owner runs feeds from the admin; this page is what is underneath: the cron jobs and indexers that build and deliver the feeds, how to check them, how to run a feed from the command line, and where the files and the log are.

The cron jobs

Every feed is delivered by the Magento cron, from a catalogue Magento's own indexer cron keeps up to date. The jobs run every minute and return at once when there is nothing to do.

Job Group Schedule Does
indexer_update_all_views index every minute Magento's own: applies the changelogs, which builds the catalogue rows of the products that changed and tells each feed sent row by row which of its products did, and which prices and stock moved.
indexer_reindex_all_invalid index every minute Magento's own: builds the whole catalogue again when it is invalid, after the upgrade or a change to what the feeds read.
arlanix_feed_deliver arlanix_feed every minute Delivers every feed with something to deliver: a file feed at its schedule or after Generate (Deliver to SFTP on an SFTP feed), a Merchant API feed whenever a row changed.
arlanix_feed_mark_stuck_runs default every 5 minutes Marks a run that has reported no progress for 30 minutes, by default, and whose process has ended, as stuck; the grid's Health then says Stopped responding.
arlanix_feed_refresh_delivered default 02:20 daily For a channel whose platform drops a product it is not sent again, such as Google's Merchant API, picks the products of the switched-on feeds that were sent and have not changed for the channel's refresh_after_days, and the next delivery sends them again.
arlanix_feed_clean_runs default 03:25 daily Removes runs older than the run history setting, 30 days by default, with what they said, and the files a process that died left in var/. It keeps each feed's last run, which the grid reads, and stops after 30 seconds, leaving the rest for the next night.

The arlanix_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.

Every run keeps what it said, so a long run history grows the arlanix_feed_run and arlanix_feed_run_message tables. The settings the jobs read are in Configuration.

The indexers

The modules add four indexers:

Indexer Code Does
Arlanix Feed Products arlanix_feed_product Builds the catalogue every feed is mapped from: a row per product and store view a feed reads.
Arlanix Feed Categories arlanix_feed_category Hands Arlanix Feed Products the products of a changed category.
Arlanix Feed Prices and Stock arlanix_feed_price_stock Tells each feed sent row by row which of its products' price or stock changed, an order's included. It builds no row, since prices and stock are read as a feed is delivered, and does nothing on a store with file feeds only.
Arlanix Feed Inventory Sources arlanix_feed_inventory Hands Arlanix Feed Prices and Stock the products of a changed source quantity. From Arlanix_FeedInventory, which also hands it the products whose salability MSI's inventory.reservations.updateSalabilityStatus consumer changes after an order, and maps every feed again after a whole inventory reindex, which follows enabling or disabling a source.

With Multi Source Inventory, an order reaches a feed sent row by row through that consumer, until the order ships and its source quantity changes: the cron's consumers_runner starts it unless env.php leaves it out of cron_consumers_runner, and bin/magento queue:consumers:start inventory.reservations.updateSalabilityStatus runs it by hand.

They belong on schedule:

  • Installing a module puts its indexers on Update by Schedule, once: Magento 2.4.7 would leave an indexer that setup:upgrade meets for the first time on Update on Save. Arlanix Feed Inventory Sources is left alone where MSI is off.
  • After that the mode is yours: an upgrade never changes it again. While one of them is on Update on Save, the feed grid and form show a warning that names it and the command that puts it back, bin/magento indexer:set-mode schedule arlanix_feed_product arlanix_feed_category arlanix_feed_price_stock arlanix_feed_inventory.

On schedule, the database triggers of each indexer 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. Magento's indexer_update_all_views applies them within a minute; the command line applies them itself, so a store without that job still delivers what changed when the command runs.

While Arlanix Feed Products is invalid, no feed is delivered: after the upgrade, after indexer:invalidate, or after a change to what the feeds read (a URL setting, a feed reading an attribute the catalogue was not built with). indexer_reindex_all_invalid builds it within a minute; bin/magento indexer:reindex arlanix_feed_product builds it on the spot. indexer:reindex arlanix_feed_category alone does nothing: the categories are in the product rows, which the product indexer's own full build reads.

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.

Run a feed from the command line

arlanix:feed:generate brings the catalogue up to date, 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: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.
--build-only Brings the catalogue up to date and delivers nothing.
--deliver-only Delivers from the catalogue as it stands, without bringing it up to date first.

Name a feed with --feed, or use --all, even with --build-only: the catalogue is the whole store's, so --build-only brings every store view up to date whichever feed is named. --build-only and --deliver-only cannot be used together.

The command prints what it does, where the file went, and how each feed's run ended:

Bringing the catalogue up to date
google-shopping
  Delivered 181 row(s) to https://your-store/media/arlanix/feeds/google-shopping.csv.
  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 The catalogue of the feed's store view has not been fully built yet, so there is nothing to map.
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 and printed No active feeds.
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 The options were wrong: neither --feed nor --all, which prints Specify --feed=<identifier> or --all., or both --build-only and --deliver-only, which prints --build-only and --deliver-only are mutually exclusive.

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/feeds/:

https://your-store/media/arlanix/feeds/google-shopping.csv

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/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/media on storage the servers share, such as NFS, as Magento's catalogue images already need. Sharing only pub/media/arlanix/feeds is 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/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/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/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/feeds/") {
    return (pass);
}

On a CDN, add a rule that bypasses its cache for /media/arlanix/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/feeds/google-shopping.tsv | grep -i last-modified

What the jobs write to var/log/arlanix.log is in The log.