Heroku | Run Cakephp Code as Cron Job

Author - Webner

Problem

The requirement was to run CakePHP controller action as cron job on Heroku. In order to achieve this you need to schedule this action so that it runs at specific time intervals on Heroku.
To run the code you need to add Heroku scheduler in Heroku app. The scheduler accepts the cake command and shell file name to run the cron job. The problem we were facing was when we run the code directly from browser using the url it used to run successfully. But when we were trying to run it from scheduler using the cake command it was not able to connect to database.

Solution

While looking into the problem we found that the parameters that are required for cakephp to connect to database were not accessible to the database.php script. Since we were retrieving the database details from heroku app url, and while we run the app from command line using cake command it was not invoking any url and hence not able to retrieve these database parameters. For resolving the database connection issue with cake command line, we manually passed the database parameters in database.php file and the connection issue was resolved.

Webner Solutions is a Software Development company focused on developing CRM apps (Salesforce, Zoho), LMS Apps (Moodle/Totara), Websites and Mobile apps. If you need Web development or any other software development assistance please contact us at webdevelopment@webners.com

Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at dev@webners.com for your Insurance, eLearning and Salesforce applications.

Leave a Reply

Your email address will not be published. Required fields are marked *