Cron Jobs
Learn how to set up and use Cron Jobs in MkSaaS
MkSaaS supports integrating Cron Jobs, which is a free and open-source cron job scheduler, for scheduled tasks, allowing you to automate your website's tasks, like distributing credits to users.
If you enable credits system, you must setup cron jobs to distribute credits to users and handle credit expiration.
Credits
Learn more about Credits
Setup
- Create a new account in Cron Job.
- Go to Cron Job Dashboard >
Cronjobs, clickCREATE CRONJOB. - Set
TitleandURLinCron Job Commonsection, and setExecution scheduleto run every day, the time is arbitrary, for example,00:00. The URL is in the format ofhttps://{=YOUR-DOMAIN}/api/distribute-credits.

- Set
UsernameandPasswordinCron Job Advancesection, and setTimeoutto30seconds.
The username and password are not the account password of CronJob website, but the basic authentication credentials for the cron job to access the API of the website, please keep them secret.

- After creating the cron job, set the
UsernameandPasswordin the.envfile.
CRON_JOBS_USERNAME=YOUR-USERNAME
CRON_JOBS_PASSWORD=YOUR-PASSWORDIf you are setting up the environment, now you can go back to the Environment Setup guide and continue. The rest of this guide can be read later.
Environment Setup
Set up environment variables
Cron Job System Structure
The file src/app/api/distribute-credits/route.ts is the cron job API route for distributing credits to users.
Usage
There is only one cron job for now, for distributing credits to users, and handling credit expiration. It should be run every day, so you should set the right Execution schedule when creating the cron job.
When the cron job is triggered, it will make a request to the /api/distribute-credits route, with the Username and Password as basic authentication credentials, and distribute credits to users, and handle credit expiration.
You can test the cron job by clicking the TEST RUN button in the cron job page, and check the response in the Response tab in the image below. You can also view the execution history of the cron job.

Reference
Next Steps
Now that you have enabled the cron job, you may want to explore these related integrations:
MkSaaS Docs