XF 2.1 Cron entry title

grantus

Active member
I'm inserting a cron job like this:

Code:
$updateFight = $db->insert('xf_cron_entry', 
 [
   'entry_id' => 'fight' . $newBattleId,
   'cron_class' => 'Battles\ILL\Cron\Fights',
   'cron_method' => 'fightInsert',
   'run_rules' => '{"day_type":"dom","dom":[22],"hours":[15],"minutes":[17],"battle":[' . $newBattleId . ']}', 
   'active' => 1, 
   'next_run' => 1726838148, 
    'addon_id' => 'Battles/ILL'
 ]
);

But when I look at the entries in the admincp, in the list it shows "cron_entry.fight256" (256 is correct). When I click it and view the entry, the title is empty. Where is the title stored? Because there's no title column in the xf_cron_entry table.
 
It's a phrase. I'm not sure I'd recommend inserted cron jobs at runtime like this. It may be better to store your records in another table and have a single cron job which processes them. Or use the job system.

If you really need to create them programmatically, you should likely use the entity system. You can see \XF\Admin\Controller\CronEntryController::cronSaveProcess to see how the title is set.
 
It's a phrase. I'm not sure I'd recommend inserted cron jobs at runtime like this. It may be better to store your records in another table and have a single cron job which processes them. Or use the job system.

If you really need to create them programmatically, you should likely use the entity system. You can see \XF\Admin\Controller\CronEntryController::cronSaveProcess to see how the title is set.
It's a battle system I have set up, so right now it's basically User1 challenges User2. If User2 accepts, a cron job is created with a battle start and end time. At the end time the cron job will trigger the code that calculates the results.

So I have everything in a separate table, it's just the issue is I want the results at the end time, rather than just run a cron job once a hour, for example.

What would be the difference with the job system? I haven't found how to set up jobs.
 
The more I look at it, I think processing the finished battles all at once is the best approach since it's less strain on the server. This way there's only one cron job.
 
Back
Top Bottom