Welcome Guest, Not a member yet? Register   Sign In
Task runs just once
#1

Hi,
I'm not sure if I've understood the the Tasks package correctly, but, to test, I I've configured a very simple task to run every 5 minutes.
tasks.php
Code:
public function init(Scheduler $schedule)
    { 
      $schedule->call(function() {
          add_to_log_test::log_a_message();
      })->everyMinute(5)->named('testing');
    }
add_to_log_test
Code:
class add_to_log_test
{
    public static function log_a_message()
    {
         log_message('notice', '[SUCCESS] {file}-{line}, WE ARE LOGGING A MESSAGE EVERY 5 MINUTES TO TEST THE TASK SCHEDULER');
         return;
    }
}
Using terminal on my server, I run
Code:
php spark tasks:run --task testing

The task runs OK, but then stops. It does not execute the task every 5 minutes ( ->everyMinute(5)) as expected.

Code:
[server-folder]$ php spark tasks:run --task testing
Running Tasks...
[2025-02-20 10:02:58] Processing: testing
[2025-02-20 10:02:58] Executed: testing
Completed Running Tasks

[server-folder]$ 


Have I interpreted the use of Tasks incorrectly, or have I missed something ?
Any help would be appreciated.
Reply
#2

UPDATE
If from terminal I run
Code:
php spark tasks:run --task testing
My tasks runs ok
If I then run
Code:
php spark tasks:list
The task reports the Next Run is due to be executed at (below), 5 minutes after the Last Run - this is correct. However the task does not run.
Code:
+---------+---------+-------------+---------------------+---------------------+--------------+
| Name    | Type    | Schedule    | Last Run            | Next Run            | Runs        |
+---------+---------+-------------+---------------------+---------------------+--------------+
| testing | closure | */5 * * * * | 2025-02-20 11:25:57 | 2025-02-20 11:30:36 | in 2 minutes |
+---------+---------+-------------+---------------------+---------------------+--------------+
If I call the list again, some time later. The tasks reports the Next Run is due to be executed at (below), 5 minutes after the previous "Next Run", and reports Last Run as original - this is correct as the task did not run as scheduled (above). That said, again the task does not run at the Next Run time.
Code:
+---------+---------+-------------+---------------------+---------------------+--------------+
| Name    | Type    | Schedule    | Last Run            | Next Run            | Runs        |
+---------+---------+-------------+---------------------+---------------------+--------------+
| testing | closure | */5 * * * * | 2025-02-20 11:25:57 | 2025-02-20 11:35:34 | in 2 minutes |
+---------+---------+-------------+---------------------+---------------------+--------------+

Very strange, or perhaps not?
Reply
#3

You're supposed to set a CRON job, that will manage tasks you defined: https://tasks.codeigniter.com/configurat...e-cron-job
Reply
#4

(02-20-2025, 05:45 AM)michalsn Wrote: You're supposed to set a CRON job, that will manage tasks you defined: https://tasks.codeigniter.com/configurat...e-cron-job

Thank you, I most definitely mis-understood.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB