Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions cron-jobs.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

[TOC]

## Introduction

Check failure on line 5 in cron-jobs.md

View workflow job for this annotation

GitHub Actions / lint

Headings should be surrounded by blank lines

cron-jobs.md:5 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## Introduction"] https://github.com/DavidAnson/markdownlint/blob/v0.31.1/doc/md022.md
Cron jobs are scheduled tasks that run automatically at specified intervals. Magento uses cron jobs to run tasks such as

Check failure on line 6 in cron-jobs.md

View workflow job for this annotation

GitHub Actions / lint

Line length

cron-jobs.md:6:81 MD013/line-length Line length [Expected: 80; Actual: 120] https://github.com/DavidAnson/markdownlint/blob/v0.31.1/doc/md013.md
reindexing, generating reports, sending newsletters, and many more. Cron jobs are essential to keep your Magento 2 store

Check failure on line 7 in cron-jobs.md

View workflow job for this annotation

GitHub Actions / lint

Line length

cron-jobs.md:7:81 MD013/line-length Line length [Expected: 80; Actual: 120] https://github.com/DavidAnson/markdownlint/blob/v0.31.1/doc/md013.md
functioning correctly.

## Setting up a Cron Job

Check failure on line 10 in cron-jobs.md

View workflow job for this annotation

GitHub Actions / lint

Headings should be surrounded by blank lines

cron-jobs.md:10 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## Setting up a Cron Job"] https://github.com/DavidAnson/markdownlint/blob/v0.31.1/doc/md022.md
Setting up a cron job in Magento involves two main steps: declaring the cron job in the `crontab.xml` file, and defining

Check failure on line 11 in cron-jobs.md

View workflow job for this annotation

GitHub Actions / lint

Line length

cron-jobs.md:11:81 MD013/line-length Line length [Expected: 80; Actual: 120] https://github.com/DavidAnson/markdownlint/blob/v0.31.1/doc/md013.md
the method that will be executed when the cron job runs.

### Step 1: Declare the Cron Job in `crontab.xml`

Check failure on line 14 in cron-jobs.md

View workflow job for this annotation

GitHub Actions / lint

Headings should be surrounded by blank lines

cron-jobs.md:14 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "### Step 1: Declare the Cron Job in `crontab.xml`"] https://github.com/DavidAnson/markdownlint/blob/v0.31.1/doc/md022.md
First, we need to declare our cron job in a `crontab.xml` file. This file should be located in the `etc` directory of

Check failure on line 15 in cron-jobs.md

View workflow job for this annotation

GitHub Actions / lint

Line length

cron-jobs.md:15:81 MD013/line-length Line length [Expected: 80; Actual: 117] https://github.com/DavidAnson/markdownlint/blob/v0.31.1/doc/md013.md
your module. If it doesn't exist, create one.

The syntax of the `crontab.xml` file is as follows:
Expand All @@ -32,12 +32,12 @@
In the above code:

- `job name`: It's an identifier for your cron job.
- `instance`: This is the class in your module that will be invoked when the cron job runs.

Check failure on line 35 in cron-jobs.md

View workflow job for this annotation

GitHub Actions / lint

Line length

cron-jobs.md:35:81 MD013/line-length Line length [Expected: 80; Actual: 91] https://github.com/DavidAnson/markdownlint/blob/v0.31.1/doc/md013.md
- `method`: This is the method in your class that will be called.
- `schedule`: This determines how often your cron job will run, based on cron syntax.

### Step 2: Define the Cron Job Method

Check failure on line 39 in cron-jobs.md

View workflow job for this annotation

GitHub Actions / lint

Headings should be surrounded by blank lines

cron-jobs.md:39 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "### Step 2: Define the Cron Job Method"] https://github.com/DavidAnson/markdownlint/blob/v0.31.1/doc/md022.md
Now, we need to create the cron class in the `Vendor\Module\Cron` directory and define the `execute()` method. This is

Check failure on line 40 in cron-jobs.md

View workflow job for this annotation

GitHub Actions / lint

Line length

cron-jobs.md:40:81 MD013/line-length Line length [Expected: 80; Actual: 118] https://github.com/DavidAnson/markdownlint/blob/v0.31.1/doc/md013.md
the method that will be executed when the cron job runs.

Here is an example of how to define this method:
Expand Down Expand Up @@ -87,14 +87,12 @@
This command will display a table containing information about each cron job, including the job code, status, created
date, scheduled date, executed date, and finished date.

If you need to remove a specific job from the cron schedule, you can do so with the following command:
If you need to remove the tasks from crontab, you can do so with the following command:

```bash
php bin/magento cron:remove <job_code>
php bin/magento cron:remove
```

Replace `<job_code>` with the code of the job you wish to remove.

## Cron Groups
Magento 2 uses cron groups to manage related tasks together. A cron group is a set of cron jobs that are managed as a
unit. All cron jobs in a group will run in the same process to ensure the resources are effectively used.
Expand Down