Milk Admin

Make your first job

Revision: 2025/10/20

Warning! For cron to work, you need to install the Job module and enable cron in PHP!

MilkAdmin has minimal cron management, consisting only of providing the file to which the cron is associated. This file simply calls hooks that can be registered at various points in the code.

Before using the Cron module, ensure that:

  • The cron service is enabled on your server
  • You have the necessary permissions to create and modify cron jobs
  • You have a database connection configured in your application

Add the following line to your crontab file:

In the shell, run the following command:

crontab -e

Then add the following line:

* * * * * php /home/fhmilkad/milk-admin/milkadmincron.php

Save and exit the editor. The cron job will now run every minute.

Make your first job

Go to milkadmin_local/functions.php and add the following code:

use App\Get;
!defined('MILK_DIR') && die(); // Avoid direct access
Hooks::set('jobs-init', function() {
    $jobs_contract = Get::make('jobs_contract');
    $jobs_contract::register(
        'my_first_jobs', 
        function($metadata) {
           // do something
          return true;
         },
        'hourly',
        'A description',
    );
});

Go to jobs page in the admin panel and you will see your job.

Go to the Cron Module Documentation for more information.

Loading...