Stratus Guides - Debugging Cron Errors

Crons can be difficult to debug, even on a standard dedicated server. Cron tasks on the common Linux server log their execution to a file, typically cron.log in /var/log. On Webscale STRATUS, this activity is not logged directly. Cron logs are typically useless other than to know the task attempted to run; a cron.log file does not tell you if the command ran correctly.

NOTE: All Magento 2 stores hosted on Webscale STRATUS are required to have installed the MageMojo Cron extension. This extension helps prevent many of the cron issues inherent with Magento 2.

Debugging Magento Cron Tasks

Magento has its own default cron that runs and executes internal jobs and schedules. The best way to confirm these are running is using the [n98-magerun(2) utility][1].

To confirm any jobs have ran recently, do the following:

  1. Connect to the Webscale STRATUS environment via SSH.
  2. Change to the Magento root directory.
  3. Run n98-magerun2 sys:cron:history | head -25 (For Magento 1.x, use n98-magerun sys:cron:history | head -25)

Below is an example output from this command:

bash
Last executed jobs
Times shown in America/Los_Angeles
+-----------------------------------------------+---------+---------------------+
| Job                                           | Status  | Finished            |
+-----------------------------------------------+---------+---------------------+
| consumers_runner                              | success | 2021-03-01 07:54:07 |
| indexer_reindex_all_invalid                   | success | 2021-03-01 07:54:07 |
| indexer_update_all_views                      | success | 2021-03-01 07:54:07 |
| sales_send_order_shipment_emails              | success | 2021-03-01 07:54:06 |
| sales_send_order_creditmemo_emails            | success | 2021-03-01 07:54:06 |
| magento_newrelicreporting_cron                | success | 2021-03-01 07:54:06 |
| bulk_cleanup                                  | success | 2021-03-01 07:54:06 |
| catalog_product_outdated_price_values_cleanup | success | 2021-03-01 07:54:05 |
| catalog_product_frontend_actions_flush        | success | 2021-03-01 07:54:05 |
| outdated_authentication_failures_cleanup      | success | 2021-03-01 07:54:05 |
| sales_grid_order_async_insert                 | success | 2021-03-01 07:54:05 |
| sales_grid_order_invoice_async_insert         | success | 2021-03-01 07:54:05 |
| sales_grid_order_shipment_async_insert        | success | 2021-03-01 07:54:05 |
| sales_grid_order_creditmemo_async_insert      | success | 2021-03-01 07:54:05 |
| sales_send_order_emails                       | success | 2021-03-01 07:54:05 |
| sales_send_order_invoice_emails               | success | 2021-03-01 07:54:05 |

In this example, the times show jobs that recently ran, which indicates that the cron tasks appear to be running at proper intervals. If a gap of time beyond the expected interval span exists, it would indicate that one or more tasks did not operate properly.

If a time gap does exist, confirm that:

  • The cron commands and paths listed in the Webscale STRATUS Cron Schedule panel are correct.
  • Check any output if the tasks are directing the cron commands to a file.

Running a Specific Magento Cron Task

Many time the failure of a cron task is due to a single cronjob failing and stopping others from completing. To run a single cronjob:

  1. Connect to the Webscale STRATUS environment via SSH.

  2. Change to the Magento root directory.

  3. Run n98-magerun2 sys:cron:run (For Magento 1.x, use n98-magerun sys:cron:run)

     bash
     ~/public_html$ n98-magerun2 sys:cron:run
       Cronjob
     [1] aggregate_sales_report_bestsellers_data
     [2] aggregate_sales_report_coupons_data
     [3] aggregate_sales_report_invoiced_data
     [4] aggregate_sales_report_order_data
     [5] aggregate_sales_report_refunded_data
     [6] aggregate_sales_report_shipment_data
     [7] aggregate_sales_report_tax_data
     [8] amazon_payments_process_queued_refunds
     [9] analytics_collect_data
     [10] analytics_subscribe
     [11] analytics_update
     [12] backend_clean_cache
     [13] bulk_cleanup
     [14] captcha_delete_expired_imag
    
  4. Enter the job number (in brackets) to run a specific job. The output will report either “success” or “failure,” as well as other errors which can help diagnose the issue.

Restarting stopped crons

  1. Connect to the STRATUS environment via SSH.
  2. Run [/usr/share/stratus/cli crons.stop][6]
  3. Run pkill -u www -f 'cron|consumer'
  4. Change to the Magento root directory.
  5. Run rm -rf var/cron/* (This deletes the schedule files in var/cron/)
  6. Run n98-magerun2 db:console (This will log you in to MySQL)
  7. Run delete from cron_schedule;(This deletes the cron schedule)
  8. Run [/usr/share/stratus/cli crons.start][7]

Testing Crons on a Development Environment

Crons are not set to run in development Environments of a Magento store. However, you can still test your crons using the Magento CLI commands.


Last modified January 1, 0001