How to Find and Remove Hanging Cron Jobs in Magento

Recently, one of our Magento client reported that their website stopped sending out order confirmation. However, invoice and shipment emails seemed to work with no issue. After an investigation, we discovered their site has caused a hanging Cron Jobs.

How to Find and Remove Hanging Cron Jobs in Magento

Starting from version 1.9.1, order confirmation emails are not sent directly during checkout, instead, they are queued in Magento, and then send out later by execution of Cron Jobs. A hanging Cron Job will cause email send stopped.

Check if Magento Cron Jobs is Hanging

Log into the server and run the following command:

As the screenshot below, you can see a couple lines of outputs

Magento Hanging Cron Jobs

The first line is the Cron daemon process running on this server.

The second line shows the command we just ran.

The third and fourth lines are Magento Cron Jobs that are currently being executed.

Furthermore, take a look at the second column from the right, that is the execution time of the process. Magento Cron Jobs usually runs real quick. So if it is caught by our ps command, and showing a long execution time, I would say if it is longer than 30 mins,  then it is possibly hanging.

Kill Hanging Cron Job

Now find the pid(second column) of the hanging process ending with ‘-mdefault’, in our case above, which is 10231, kill the process with the command below.

Make sure replace  10231 with the pid showing on your console, and you may run the ps aufx | grep cron command again to confirm the hanging Cron Job is killed.  Your Magento Cron Job should resume momentarily.

Usually, following the procedure above will resolve the hanging Cron Job for Magent, but if the Cron Job is still not working normally, or becomes hanging again. I suggest:, First check if you have your Magento Cron Job setup correctly. Check this post if you are not sure how to configure Magento Cron Job.

You can also try doing a truncate (delete all records) for table cron_schedule, and then run the commands again, see if new Cron Job tasks are populated in the cron_schedule table. Additionally, identifying the Cron Job task that is hanging with RUNNING status in the cron_schedule table may help you locate the module which is causing the hanging Cron Job.

 

 

 

Magento Checkout Error: PayPal gateway has rejected request.

We recently did a troubleshooting for an escalated ticket from one of our Magento clients. They were having occasionally checkout failure. Their customer reported that they ran into an error when trying to check out using PayPal. After clicking ‘Place Order’ button, they got redirected to the cart page, and an error message is showing like below:

PayPal gateway has rejected request. The totals of the cart item amounts do not match order amounts.

We did not receive the checkout failure emails from Magento. As the error message suggests, PayPal is declining the transaction because the order total does not match the total price for each product adding up together.  In other words, say you are buying item A ($1), and item B ($2), PayPal is seeing a total which is not $3.

After digging into it, we figured out this error will occur whenever the customer is checkout with a gift card applied and the rest on PayPal. Obviously, PayPal knows nothing about a gift card has been used, and total being brought down by it so it will decline the transition. The error must be cast on the PayPal side. Because we are fine using a credit card to check out.

If you have any 3rd part extension installed on your Magento that will update order total, for example, a promotion extension, which applies a discount to the order, or maybe a layaway extensin, and in our case, a gift card extension, you can possibly run into an error like this.

How to resolve it

After reviewing the options for resolving this error, we decided not to debug the gift card plugin and make it  ‘PayPal compatible’. Instead, we chose to turn off the ‘Transfer Cart Line Items’ option for PayPal payment method in Magento(where to turn it off? see the screenshot below).

By doing so, the price for each item in the order will not be transferred to PayPal, and your customer will not be able to see the cart detail when they go to PayPal to finish checkout. PayPal will not notice the mismatch between order total and the sum of all items’ price. So the transaction will not be declined. This should be the most straightforward way. After we turned off the option, the error went away.

Magento PayPal gateway has rejected request. The totals of the cart item amounts do not match order amounts

I hope my post can help you when you run into a similar issue just like this. If you have noticed a different cause of this error or a different solution. Please leave a comment. Appreciate your help and time to the community!