Reset cron jobs
Sometimes, Magento cron jobs do not finish executing and persist in a running
status, which prevents other cron jobs from running. This can happen for a number of reasons, such as network issues, application crashes, redeployment issues.
Symptom
Symptoms of cron jobs that must be reset include:
- Large quantity of jobs appear in the
cron_schedule
queue - Site performance starts to degrade
- Jobs fail to execute on schedule
Solution
To resolve this issue, you must reset the cron job(s) using the cron:unlock
command. This command changes the status of the cron job in the database, ending the job forcefully to allow other scheduled jobs to continue.
Running this command without the --job-code
option resets all cron jobs, including those currently running, so we recommend using it only in exceptional cases, such as after you have verified that all cron jobs must be reset. Re-deployment runs this command by default to reset cron jobs, so they recover appropriately after the environment is back up. Avoid using this solution when indexers are running.
-
Open a terminal and use your SSH keys to connect to the affected environment.
-
Get the MySQL database credentials:
1
echo $MAGENTO_CLOUD_RELATIONSHIPS | base64 -d | json_pp
-
Connect to the database using
mysql
:1
mysql -hdatabase.internal -uuser -ppassword main
-
Select the
main
database:1
use main
-
Find all running cron jobs:
1
SELECT * FROM cron_schedule WHERE status = 'running';
-
Copy the
schedule_id
of any job running longer than usual. -
Use the schedule IDs from the previous step to unlock specific cron jobs:
1
./vendor/bin/ece-tools cron:unlock --job-code=<schedule_id> --job-code=<schedule_id>