Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 08-18-2011, 05:46 PM
EquinoxWorld EquinoxWorld is offline
 
Join Date: Nov 2009
Location: Naples
Posts: 354
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default When does "nextrun" field update from SQL table cron?

Hello everyone, I was wondering if anyone knew when is the field "nextrun" in the SQL table cron updated? Here's my situation:

I have a SQL update query that I runs in a cron file that I setup to run every week. In that SQL query I need to specify the date of the next time this cron will run. If use the field "nextrun" from the table cron within this cron job will the date be the next already or the current one of that day still? Basically what I am asking is if the cron is being executed will the nextrun time be already updated for next run If I call that field from within the cron file and use it in a query? I know it's a bit confusing but If anyone has any info please let me know. Thank you for your time.

Regards.
Reply With Quote
  #2  
Old 08-18-2011, 05:59 PM
nhawk nhawk is offline
 
Join Date: Jan 2011
Posts: 1,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If you have the task set up to run once a week on a given day and time, once the scheduled task runs it will automatically update itself to run the next week on the same day and time. There's no need to update the schedule manually in your code.

If you run the task manually, it does not affect the next scheduled run day/time.
Reply With Quote
  #3  
Old 08-18-2011, 06:09 PM
EquinoxWorld EquinoxWorld is offline
 
Join Date: Nov 2009
Location: Naples
Posts: 354
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by nhawk View Post
If you have the task set up to run once a week on a given day and time, once the scheduled task runs it will automatically update itself to run the next week on the same day and time. There's no need to update the schedule manually in your code.

If you run the task manually, it does not affect the next scheduled run day/time.
Thanks for your reply nhawk. I realize that the cron task updates itself but my question is if I wanted to call that field (nextrun) from within the cron that's being executed to use as a time to set an "event" will tha time still be the current one or the next already? Basically I want to use the value of the field "nextrun" to create an event on the calendar. This event will be created within the cron thats being run, so my quesiton is If I call the field "nextrun" from within the file that's being executed by the cron will the time have already been updated for the next run? Basically asking does the "nextrun" field update before the task runs, as the task runs or after the task runs.

Another solution to this would be just to use this to set the next event (same time as "nextrun")

PHP Code:
$aotw_next_time time() + 604800
(604800 being a week in unix time). Although to be more exact and make sure that both values will be exactly the same ti would be better to use "nextrun" value, I'm not sure if time() will be the same every time (server might stall or something for a second). Any ideas?
Reply With Quote
  #4  
Old 08-18-2011, 06:21 PM
nhawk nhawk is offline
 
Join Date: Jan 2011
Posts: 1,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #5  
Old 08-18-2011, 06:26 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by EquinoxWorld View Post
Another solution to this would be just to use this to set the next event (same time as "nextrun")

PHP Code:
$aotw_next_time time() + 604800
(604800 being a week in unix time). Although to be more exact and make sure that both values will be exactly the same ti would be better to use "nextrun" value, I'm not sure if time() will be the same every time (server might stall or something for a second). Any ideas?
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.
Reply With Quote
  #6  
Old 08-18-2011, 06:58 PM
EquinoxWorld EquinoxWorld is offline
 
Join Date: Nov 2009
Location: Naples
Posts: 354
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by nhawk View Post
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 View Post
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.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:55 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.13302 seconds
  • Memory Usage 2,251KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (4)bbcode_php
  • (4)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (6)post_thanks_box
  • (6)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (6)post_thanks_postbit_info
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete