Quote:
Originally Posted by nhawk
I see...
I do believe the nextrun is calculated after the run is complete. I could be wrong.
The easiest way to check it is to run your task and see what nextrun says before it completes.
|
Quote:
Originally Posted by kh99
You're right that the time that the task runs won't be exact, especially if your forum isn't busy, since it only runs when users request a page (that is, if you're talking about vb "scheduled tasks" and not actual cron jobs). Anyway, maybe another idea would be to let the task run on some regular schedule but have your code check a db field to see if it should do anything.
|
Thanks for your reply guys. What I'm going to have to do is what nhawk suggested; I have the task (vb task yes) setup to run tonight at midnight. I'm going to add my code in there and use "nextrun" field value to see when it creates the event. I can only speculate but I think that it should use the new value; think about it, the task is already running so why would the nextrun time still be the same. I'm trying to narrow it down to the second so I know this can be difficult. I could have the code in the task check a db field but the only value that I know for a fact that I can use to setup an event on the same exact time as the next task/cron is in the field I mentioned. Anything else could be subject to other circumstances, using this field I eliminate any other variable that might have been overlooked. Or what I just thought about now, would be to set up somehow that my code to create the event runs (in a separate file) as soon as the cron is completed running, that way I know that the field has been updated already. In any case i'll let you guys know my results as soon as the task runs tonight, I'll post here for anyone to use a future reference of when this field is updated although if you have any more thoughts or ideas please do tell
--------------- Added [DATE]1313719820[/DATE] at [TIME]1313719820[/TIME] ---------------
OK guys got it working better than I had hoped
I used the previous code in my cron file and waited for the task to run. Had to make some posts throughout the night to make the forum "active" so the task would run and when it did at first with the code mentioned before :
PHP Code:
$aotw_next_time = time() + 604800;
This worked but the time it gave me was 13 second late

This in turn created the event but 13 seconds past the time it needs to be; vb for some reason places single events in the calendar at 00:00:00 GMT, if you set the event 13 seconds late the event although recorded in the database does not appear in the calendar. Even if it's 13 secs past 00:00:00. Anywho I created a hybrid of our ideas, used this code but also a db recording I have of the time set as "start time" ,here's a snippet of the entire cron file.
PHP Code:
//This will get the edition # of said contest//
$result0 = $vbulletin->db->query_read("SELECT * FROM cotw_aotw_time_end ORDER BY id DESC LIMIT 1");
$row0 = mysql_fetch_row($result0);
$edition = $row0[0] - 1;
$next_edition = $row0[0] + 1;
//This will get the next contest date for settting next event of said contest//
$result1 = $vbulletin->db->query_read("SELECT aotw_unix_start FROM cotw_aotw_contest_start_unix");
$row1 = mysql_fetch_row($result1);
$aotw_next_time = $row1[0] + (604800 * $edition);
//Create Next Weeks Event/Contest//====================================================================================//
//===================================//==========================================================================//
$vbulletin->db->query_write('INSERT INTO `event` (`eventid`, `userid`, `event`, `title`, `allowsmilies`, `recurring`, `recuroption`, `calendarid`, `customfields`, `visible`, `dateline`, `utc`, `dst`, `dateline_from`, `dateline_to`) VALUES (NULL, \'1\', \'Contest Type: '.$vbulletin->options['cotw_aotw_next_type'].'\', \'Avatar of the Week # '.$next_edition.'\', \'1\', \'0\', \'\', \'2\', \'a:0:{}\', \'1\', \'1313616397\', \'0.00\', \'0\', '.$aotw_next_time.', \'0\');');
//==============================================================================================================//
This worked PERFECT, to the second! This way it also gives the user a chance to "deactivate" the contest and then restart it with a new date whenever.
There's some other aspects to work out but the initial issue of this thread is SOLVED my friends. Thanks for your help again, your help has been incredibly helpful for my learning process.