Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 12-16-2014, 03:36 PM
Mko's Avatar
Mko Mko is offline
 
Join Date: May 2009
Location: East Coast, USA
Posts: 60
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Scheduled Task - Run Every 5 Seconds

I've created a Scheduled Task that will submit a request to an API and store the value returned in a table in my database.
I'm interested in having this Scheduled Task run every 5 seconds, yet in the vB3 AdminCP, the only fields I see are Day of the Week, Day of the Month, Hour, and Minute. However, Minute has 6 fields attributed to it, which I am also confused about.

How would I get my Scheduled Task to run every 5 seconds through vBulletin?

Thanks,
Mark
Reply With Quote
  #2  
Old 12-16-2014, 03:45 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

There are 6 "minute" fields because you can schedule a task to run up to 6 times per hour at certain minutes of the hour. If you choose '*' then it will run once per minute, but that's the most often you can schedule a task to run (unless you modify the code somehow).

I'm assuming that you're using the returned value somewhere, maybe you could do something like before it's displayed check to see if it's more than 5 seconds old, and if it is, request it before displaying it. But then I guess you'd also need a way to keep it from constantly being requested by multiple threads, especially if you have a very busy site,
Reply With Quote
  #3  
Old 12-16-2014, 03:54 PM
Mko's Avatar
Mko Mko is offline
 
Join Date: May 2009
Location: East Coast, USA
Posts: 60
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
There are 6 "minute" fields because you can schedule a task to run up to 6 times per hour at certain minutes of the hour. If you choose '*' then it will run once per minute, but that's the most often you can schedule a task to run (unless you modify the code somehow).

I'm assuming that you're using the returned value somewhere, maybe you could do something like before it's displayed check to see if it's more than 5 seconds old, and if it is, request it before displaying it. But then I guess you'd also need a way to keep it from constantly being requested by multiple threads, especially if you have a very busy site,
I see. Thanks for the suggestion!

Would the following settings be what I'm after if I wish to have my Task run every minute?
Reply With Quote
  #4  
Old 12-16-2014, 03:59 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yes, I believe that would do it.

But in case you're not aware, the tasks run when users view your forum pages, so the timing it approximate, and it will only run once per minute if you have enough traffic to your site.
Reply With Quote
Благодарность от:
Mko
  #5  
Old 12-16-2014, 04:00 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That should do it. Be aware that the Scheduled Tasks only run if you have users on your site. The tasks will backup if you don't have people clicking on your site.
Reply With Quote
Благодарность от:
Mko
  #6  
Old 12-16-2014, 04:24 PM
Mko's Avatar
Mko Mko is offline
 
Join Date: May 2009
Location: East Coast, USA
Posts: 60
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I see! Thanks for the information.

As a follow-up question...
I have a custom bridge I developed with vB. Since both you reminded me how a user needs to be viewing the forum in order for Scheduled Tasks to execute, I decided to generate $cronimage in my site-wide header (not present on my directory with my vBulletin files) so that Scheduled Tasks hopefully would execute even if nobody is viewing the Forum Index.

Here is what I included (community/ is the directory where I have my vBulletin):
PHP Code:
        if ($vbulletin->cron <= TIMENOW)
        {
            
$cronimage '<img src="' create_full_url('community/cron.php?' $vbulletin->session->vars['sessionurl'] . 'rand=' .  TIMENOW) . '" alt="" width="0" height="0" border="0" style="display: none;" />';
        }
        else
        {
            
$cronimage '';
        }
        echo 
$cronimage
It outputs correctly, but I just want to double check that this is the proper way of "inducing" Scheduled Tasks to run from an external page.

Thanks again!
Reply With Quote
  #7  
Old 12-16-2014, 05:11 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It seems right, but to be honest I don't know for sure.
Reply With Quote
  #8  
Old 12-16-2014, 09:37 PM
ozzy47's Avatar
ozzy47 ozzy47 is offline
 
Join Date: Jul 2009
Location: USA
Posts: 10,929
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yeah it looks ok to me also. But I don't understand, what is it you need to run so often?
Reply With Quote
Благодарность от:
Mko
  #9  
Old 12-16-2014, 10:19 PM
Mko's Avatar
Mko Mko is offline
 
Join Date: May 2009
Location: East Coast, USA
Posts: 60
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by ozzy47 View Post
Yeah it looks ok to me also. But I don't understand, what is it you need to run so often?
I was initially going to call the API to fetch the amount of players logged in, but I opted to do it using a table in my db and not using a Scheduled Task.

Anyways, good to see that the code I added in the header looks OK. Thanks for all the help!
Reply With Quote
  #10  
Old 12-16-2014, 10:23 PM
ozzy47's Avatar
ozzy47 ozzy47 is offline
 
Join Date: Jul 2009
Location: USA
Posts: 10,929
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Gotcha. Glad to see you found a way to do what you wanted though.
Reply With Quote
Reply

Thread Tools
Display Modes

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 12:35 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.04700 seconds
  • Memory Usage 2,260KB
  • Queries Executed 11 (?)
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
  • (1)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (3)post_thanks_box_bit
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (3)post_thanks_postbit
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)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_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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete