XF 2.2 How can I restore a missing row in the xf_job table

AndyB

Well-known member
What is the method to restore a missing row in xf_job table?

There should be two rows like this:

1622484339693.webp

But currently there is only one row like this:

1622484383865.webp
 
You can basically insert job entry into table.
SQL:
INSERT INTO `xf_job` (
    `unique_key`, `execute_class`, `execute_data`,
    `manual_execute`, `trigger_date`, `last_run_date`
) VALUES (
    'cron', 'XF\\Job\\Cron', 'a:0:{}',
    0, 0, 0
);
 
I know this is old, but it happened to me over the weekend. In my situation, I know why it happened (it was due to what looks like a MySQL bug). Specifically, there was a situation where prepared statements would fail with MySQL fetch error [2014]: Commands out of sync; you can't run this command now. Not so coincidentally, the cron job entry record was lost in all XF2 sites, and it was not lost in XF1 sites (didn't really dig into the differences on how XF1 handles the xf_deferred table vs. XF2 xf_job). But whatever that difference is, it caused the issue for me only in XF2.

I'm not super worried about it, because it was the first time I'd seen MySQL do something like that in what is probably 20 years now of running it, and I filed a bug report so hopefully whatever it was will be fixed going forward: https://bugs.mysql.com/bug.php?id=106588

That being said, it would be nice if XF had an integrity check of some sort so it could "self heal" if the xf_job cron record was lost (for whatever reason). For example, maybe have a hidden debug setting/timestamp of the last time there was a check to make sure the cron record exists. Add the check to XF\Job\Manager::__construct() where if more than 24 hours (or 1 hour, or whatever) has passed since it last checked for the record, add it (and log an entry into the error log so someone knows something happened to it). In my case, I didn't realize the cron tasks weren't running for awhile. Having a simple check for the record like that would make XenForo a bit more durable when something unforeseen happens to that record.
 
Thank you, Kruzya. I appreciate your time and sharing an alternative way to add a missing row, this can be very useful should it happen on another table.
 
I know this is old, but it happened to me over the weekend. In my situation, I know why it happened (it was due to what looks like a MySQL bug). Specifically, there was a situation where prepared statements would fail with MySQL fetch error [2014]: Commands out of sync; you can't run this command now. Not so coincidentally, the cron job entry record was lost in all XF2 sites, and it was not lost in XF1 sites (didn't really dig into the differences on how XF1 handles the xf_deferred table vs. XF2 xf_job). But whatever that difference is, it caused the issue for me only in XF2.

I'm not super worried about it, because it was the first time I'd seen MySQL do something like that in what is probably 20 years now of running it, and I filed a bug report so hopefully whatever it was will be fixed going forward: https://bugs.mysql.com/bug.php?id=106588

That being said, it would be nice if XF had an integrity check of some sort so it could "self heal" if the xf_job cron record was lost (for whatever reason). For example, maybe have a hidden debug setting/timestamp of the last time there was a check to make sure the cron record exists. Add the check to XF\Job\Manager::__construct() where if more than 24 hours (or 1 hour, or whatever) has passed since it last checked for the record, add it (and log an entry into the error log so someone knows something happened to it). In my case, I didn't realize the cron tasks weren't running for awhile. Having a simple check for the record like that would make XenForo a bit more durable when something unforeseen happens to that record.
This also happened to me today. Turning the cron entry off and on fixed the issue.
 
Top Bottom