CLI Job / Cron Runner

CLI Job / Cron Runner 2.1.1

No permission to download
Note that after installing the latest version, if you are seeing the message "There are scheduled jobs outstanding which have not run. Jobs may not be getting triggered when expected."

View attachment 236235

... check to see whether you are still using the --time command line option.

This option has been renamed to --max-execution-time to match the option names used in the core job runner.

Make sure you have updated all of your cron tasks to use --max-execution-time
Hi @Sim,

thank you for this great addon. I am using it and most times I visit admin.php I see that message. But cron jobs are executed (as I can see when I visit admin.php?cron/). We have a lot of background-jobs working and set --max-execution-time=240.

So, my guess is, that every time a cron runs longer than 1 minute (which seems to happen quite frequently), we get this message, because the next jobs are already waiting.

Can that be the case?
 
Hi @Sim,

thank you for this great addon. I am using it and most times I visit admin.php I see that message. But cron jobs are executed (as I can see when I visit admin.php?cron/). We have a lot of background-jobs working and set --max-execution-time=240.

So, my guess is, that every time a cron runs longer than 1 minute (which seems to happen quite frequently), we get this message, because the next jobs are already waiting.

Can that be the case?

Yes, the system generally only processes one task at a time, so if there are tasks which are taking longer than 1 minute then you'll likely see the message.

In particular if you have any Cron tasks which are scheduled to run every minute - you'll probably get this message a lot, since there will almost always be a Job outstanding to trigger the Cron tasks.

You can check on which jobs are outstanding by running the hg:show-jobs command from the CLI - it lists the next run time for any outstanding jobs, and shows the current time (according to the forums) at the bottom, so you can tell whether the job is delayed or still pending.
 
I see. That's quite annoying. This message also hides any outstanding manual jobs (i.e. you cannot see both "outstanding" messages, cron and manual tasks, at the same time; at least that's my experience).

Is it possible to show this message only if jobs are outstanding for at least X minutes?
 
Is it possible to just run one job, a job that has no cron?
Then I could just add one file to the server and say: go, baby, go!
 
Is it possible to just run one job, a job that has no cron?
Then I could just add one file to the server and say: go, baby, go!

No - jobs don't work like that, you need to create a job entry in the database for the job to run.

If you have a single simple task you need to execute, just create a cron without a job and execute the cron manually using the hg:run-cron tool I decribe on the overview page.

Better yet, just create a CLI command and run that directly - you'll have a lot more control over things.

Perhaps if you describe what you are trying to achieve I can suggest the best method for executing it?
 
Thank you, have done it with a template-mod and a switch in the rebuild-tools.


What I would like to have?

Sometimes i use php to do something because it is faster to write. Example from today:
open DB, fetch all resources, fetch the thread, copy the resource_icons/[floor_int]/res_id... to thread_icon/[another_floor_int]/thread_id...

Called by website.com/xyz/icon.php

It would be nice to do it as a class and throw it into /addons/me/MyTools/Job/name_of_tool.php
and call it by

... cmd.php xf:magic_power /me/MyTools/Job/name_of_tool
to have the same result like using website.com/xyz/name_of_tool.php

But for next time i have now this dummy add-on and just rename the needed class from "tool_for_copy_pictures" to "active_tool" and start it by rebuild.
 
I create CLI commands for one-off tasks - easy to run, easy to debug, and no timeout issues compared to running something through the browser.
 

Not working how?

You can show outstanding jobs by running: $ php cmd.php hg:show-jobs

You can also show debugging information for jobs: $ php cmd.php hg:run-jobs -v ... or add -vv or -vvv for even more info.

the cron also doesn't trigger any errors:

Are you expecting errors from the cron? Again, you can use -v, -vv or -vvv to show more information about the cron task being executed.
 
Last edited:
Not working how?
It says "Link status check is successfully scheduled and will run once there are some visitors on your site" which means the cron is waiting for visitors even when it is running through CLI
 
It says "Link status check is successfully scheduled and will run once there are some visitors on your site" which means the cron is waiting for visitors even when it is running through CLI

Is the job actually running though? What does hg:show-jobs say?

I'm wondering whether this is just a phrasing problem for that addon?
 
We haven been running this add-on for a few years now, and it is a great piece for work, @Sim!

I have a question regarding cron frequency. We run our server cron once a minute with the max-ececution-time flag set to 238 seconds.

I wonder if it makes sense and/or causes problems, if we run our server cron ever 10 seconds.

That is possible when using the sleep shell command.


Background: We want avoid, that the cron system "sleeps" for up to 1 minute (when a con run is finished shortly after the next one would have been started), because when our forum is very busy or we are sending out mass-DMs, the xf_job and xf_mail_queue tables can get a big backlog.

🤔
 
Background: We want avoid, that the cron system "sleeps" for up to 1 minute (when a con run is finished shortly after the next one would have been started), because when our forum is very busy or we are sending out mass-DMs, the xf_job and xf_mail_queue tables can get a big backlog.

The job system sleeps only when there is no more work left to do.

If there is a bunch of work, it will keep working until the max execution time expires. The whole point is to avoid it running a new job while the previous job is still running - they are not intended to run in parallel.

If you're getting a big backlog, then you may need to look at other things such as why is your mail taking so long to send? Are you sending via SMTP or via HTTP using a 3rd party mailing system?

Is your database too slow to accept writes for large number of DMs?

That being said, I do think the job system may need to be re-written to use real queueing that allows multiple job runners to execute in parallel.
 
I don't understand how when I manually run this from cli "hg:run-jobs"
All outstanding jobs have run.

And 5 seconds later I refresh Admin Panel and this message is there:
There are scheduled jobs outstanding which have not run. Jobs may not be getting triggered when expected.

It just randomly appears disappear every second.
 
I don't understand how when I manually run this from cli "hg:run-jobs"
All outstanding jobs have run.

And 5 seconds later I refresh Admin Panel and this message is there:
There are scheduled jobs outstanding which have not run. Jobs may not be getting triggered when expected.

It just randomly appears disappear every second.

Yes, it happens to me too on some of my sites (but not all).

I've not had the time to work out exactly what causes it - I suspect it may be some kind of race condition.

It's annoying, but things are still working as they should, despite the message.

I should mention that you don't really need to use this addon any more - the built in xf:run-jobs command does the same thing.

The only real reason to use my version is if you are debugging your own cron tasks or jobs - or if you need a bit more control over execution than what the core version offers.
 
Back
Top Bottom