Laravel/Configure cronjobs

From Aimeos documentation

Laravel
Other languages:
English 100%


2018.x+ version

Aimeos jobs are implemented for maintenance tasks like clean up or sending e-mails. Some of them need to be executed very often, others only once a day.

Setup

A job should be executed by a regularly running cronjob. You can also execute jobs by hand at any time but some jobs need to run very often, e.g. every minute. Aimeos jobs can be executed on the command line using the Laravel "artisan" command:

php <appdir>/artisan aimeos:jobs "<jobs>" "<sites>"

jobs (mandatory) 
The jobs parameter can be the name of a single job or a list of job names separated by a white space. These jobs are available:
  • admin/cache (remove old cache entries)
  • admin/log (remove old log entries)
  • catalog/import/csv (import categories from CSV files)
  • customer/email/account (create new customer accounts and send e-mails)
  • customer/email/watch (customer notification e-mails on product updates)
  • index/optimize (optimize the product index for fastest access)
  • index/rebuild (rebuilds the product index)
  • media/scale (rescales the product images to the new sizes)
  • order/cleanup/unfinished (removes unfinished orders)
  • order/cleanup/unpaid (removes unpaid orders)
  • order/email/delivery (order delivery related e-mails)
  • order/email/payment (order payment related e-mails)
  • order/email/voucher (e-mails containing the voucher code)
  • order/export/csv (export orders in admin interface)
  • order/service/async (batch update of payment/delivery status)
  • order/service/delivery (process order delivery services like sending orders to ERP systems)
  • order/service/payment (capture authorized payments)
  • product/bought (automatically generated product suggestions)
  • product/export (export products)
  • product/export/sitemap (generate product sitemaps for search engines)
  • product/import/csv (import products from CSV files)
  • subscription/export/csv (export subscriptions in admin interface)
  • subscription/process/begin (start subscription period and add permissions if applicable)
  • subscription/process/renew (renew subscriptions on next date)
  • subscription/process/end (finish subscription period and revoke permissions if applicable)
sites (standard is "default") 
This must be one or more locale site codes that you have used in the administration interface. Several sites must be separated by a white space.

Configuration

For some jobs (especially the tasks that are sending e-mails) a few configuration settings are required in the config/shop.php file of your application. This includes the e-mail address of your shop, the name displayed in the "From:" line of all sent e-mails and the base URL to the product images:

  1. 'client' => array( 
  2.     'html' => array(
  3.         'common' => array(
  4.             'content' => array(
  5.                   'baseurl' => 'http://yourdomain.com/',
  6.             ),
  7.             'template' => array(
  8.                  'baseurl' => public_path('packages/aimeos/shop/themes/elegance'),
  9.             ),
  10.         ),
  11.         'email' => array(
  12.             'from-email' => 'demo@aimeos.org',
  13.             'from-name' => 'Demo shop',
  14.         ),
  15.         ...
  16.     ),
  17. ),

To use another theme CSS for the sent e-mails, you can set the client/html/common/template/baseurl parameter like shown above. As the job controller is executed via a cronjob, you must configure an absolute path to the theme files. The easiest way is to use the "public_path()" helper function which creates absolute paths to the ./public/ directory of your Laravel application.

E-mails with products also contains links to these products on your web site. But e-mails are sent from the command line and Laravel can't guess the base URL in this case. This is solved by setting the base URL in your ./config/app.php file:

  1.     'url' => 'http://<your public root>',

Tasks

Every minute

Some Aimeos jobs should run very often, like the job for sending order confirmation e-mails after an order was placed successfully. This task can also be used for other jobs that should also run frequently:

  • Order CSV export (export of orders marked in the admin interface)
  • Order delivery related e-mails (customer notification e-mails on delivery status changes)
  • Order payment related e-mails (customer notification e-mails on payment status changes and order confirmation e-mails)
  • Order voucher e-mails (e-mails to customers containing the code for the voucher they bought)
  • Process order delivery services (send paid orders to ERP systems or logistic partners)
  • Subscription CSV export (export of subscriptions marked in the admin interface)
* * * * * php /path/to/artisan aimeos:jobs "order/export/csv order/email/delivery order/email/payment order/email/voucher order/service/delivery subscription/export/csv"

Every hour

The same must be done for jobs that have to be executed every hour (or at least several times a day):

  • Product notification e-mails (customer notification for price and stock updates)
  • Removes unfinished orders (unblock product stock and coupon codes)
  • Batch update of payment/delivery status (asynchronous updates via uploaded files)
  • Capture authorized payments (if payments are first authorized and captured later)
30 * * * * php /path/to/artisan aimeos:jobs "customer/email/watch order/cleanup/unfinished order/service/async order/service/payment"

Once a day

These jobs should be executed once a day (best at times of low traffic):

  • Cache cleanup (remove old cache entries)
  • Catalog import (import categories from CSV files)
  • Log cleanup (remove old log entries)
  • Removes unpaid orders (delete orders without payment)
  • Product import (import products from CSV files)
  • Products bought together (automatically generated product suggestions)
  • Index rebuild (re-create the product index)
  • Index optimize (optimizes the index for fastest query execution)
  • Product sitemap (generate product sitemaps for search engines)
  • Start subscription period (start subscription period and add permissions if applicable)
  • Renew subscriptions (renew subscriptions on next date)
  • End subscription period (finish subscriptions and revoke permissions if applicable)
0 1 * * * php /path/to/artisan aimeos:jobs "admin/cache admin/log catalog/import/csv order/cleanup/unpaid product/import/csv product/bought index/rebuild index/optimize product/export/sitemap subscription/process/begin subscription/process/renew subscription/process/end"


<< Previous: Setup the admininstration interface | Next: Clear caches, execute jobs and setup the database >>