News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

How to create Scheduled Tasks in SMF 2.0

Started by Arantor, August 09, 2009, 03:30:45 PM

Previous topic - Next topic

Zaine

Removed my last question and asking it in a better way :)

How should you handle if it your scheduled tasks errors?   I'm logging errors using log_error(); and returning false from the Scheduled task function but the interface still happily reports that the task completed successfully, even when logging a critical error.

I'm getting the errors in the error log, which is good, but I was expecting to see that interface warn me that the manual run failed.


emanuele

Hi Zaine,

it's the first time for me looking into scheduled tasks, but as far as I can understand from the code it seems that if the scheduled function returns false the task should not be logged:
Code (from ScheduledTasks.php lines 124-129) Select
// Do the task...
$completed = call_user_func('scheduled_' . $row['task']);

// Log that we did it ;)
if ($completed)
{


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

DanCarroll

Here's a tip for anyone looking to run a task on a given day of the month such as the first.

Just schedule your task as a daily and do a check at the beginning to see if it is the first and then decide what code to run.

Iomega0318

Can this be used to run a link, I have a cron job I would like SMF to handle and was wanting to schedule it for once a week. However the cron job has a link for it, and before you ask, my server won't let me run cron jobs normally..
UOFreeshards.net
UOFreeshards.net 2.1 Aplha Test Site
"I believe in Christianity as I believe in the sun...
not because I see it but because by it I see everything else."
C.S. Lewis

Heed what I say, for it shall be mentioned only once.

live627

No. No way other than the code shown in the OP.

emanuele

fetch_web_data? :P

Of course I mean create a function that call fetch_web_data.


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

Acans

Very useful tutorial. Perfect for updating my member count across multiple shared forums :) (Instead of pressing that damn recount button everyday :P)
"The Book of Arantor, 17:3-5
  And I said unto him, thy database query shalt always be sent by the messenger of $smcFunc
  And $smcFunc shall protect you against injections and evil
  And so it came to pass that mysql_query was declared deprecated and even though he says he is not
  dead yet, the time was soon to come to pass when mysql_query shall be gone and no more

live627


DieGoO

I managed to create a scheduled task, but it seems like it isn't running automatically, or  at least, it doesn't show on the task log..

But if i run it manually it does show on the task log..

Did i miss something?

Arantor


DieGoO

Nevermind  :P .. After reading through the topic again, i figured out why it wasn't working..

live627


Arantor

You realise that the IT Crowd was practically a documentary rather than a comedy, right? ;)

live627


4Kstore

Sorry for the bump, but I need to ask for save some time, there is no hook actually for this? SMF 2.0?
I read something http://www.simplemachines.org/community/index.php?topic=510873.0

¡¡NEW MOD: Sparkles User Names!!!

live627


Arantor

I wrote this years ago. Off the top of my head there is no hook in 2.0, the one in 2.1 is not ideal IMO.

4Kstore


¡¡NEW MOD: Sparkles User Names!!!

PopUpSteve

Steve
"Even a broken clock is right twice a day, unless it's digital."

pirma

Very helpful article. Perfect for upgrading my new member count number across numerous contributed message boards.

Advertisement: