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

Reply
 
Thread Tools Display Modes
  #1  
Old 04-27-2015, 10:52 AM
JamesAB JamesAB is offline
 
Join Date: Dec 2003
Posts: 125
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Run scheduled task from plugin?

I'm working on a plugin that needs to call for a scheduled task to run at that moment, without waiting for the next scheduled task run time.

Is there a way to force a scheduled task to run from inside the plugin code?

Thanks,
James
Reply With Quote
  #2  
Old 04-27-2015, 11:14 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I haven't tested it, but looking at the code in admincp/cronadmin.php for running a scheduled task, I think this might work:
PHP Code:
if ($nextitem $db->query_first("SELECT * FROM " TABLE_PREFIX "cron WHERE cronid = " $cronid))
{
    
ignore_user_abort(1);
    @
set_time_limit(0);

    require_once(
DIR '/includes/functions_cron.php');
    include_once(
DIR '/' $nextitem['filename']);

where $cronid would have to be set to the id of the task before the above code is executed.

I don't know, you may or may not want the ignore_user_abort and/or the set_time_limit calls in your plugin.
Reply With Quote
  #3  
Old 04-27-2015, 12:38 PM
JamesAB JamesAB is offline
 
Join Date: Dec 2003
Posts: 125
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for your help.
I got the scheduled task ID from the Scheduled Task manager:
Scheduled Task: Process FFMPEG queue (id: 31)

I'm putting this code in the attachdata_postsave hook, so I tried changing it to this:
Code:
if ($nextitem = $this->registry->db->query_first("SELECT * FROM " . TABLE_PREFIX . "cron WHERE cronid = 31"))
{
    ignore_user_abort(1);
    @set_time_limit(0);

    require_once(DIR . '/includes/functions_cron.php');
    include_once(DIR . '/' . $nextitem['filename']);
}
Hoever, its producing this error now:
Code:
Fatal error: Call to a member function query_first() on a non-object in /home/forum321/public_html/includes/class_dm_attachment.php(659) : eval()'d code on line 99
Any help would be appreciated.
Reply With Quote
  #4  
Old 04-27-2015, 12:44 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hmm...seems like that should be right. You could try
PHP Code:
global $vbulletin;
if (
$nextitem $vbulletin->db->query_first("SELECT * FROM " TABLE_PREFIX "cron WHERE cronid = 31"))
{
// etc 

but I don't see why $this->registry wouldn't work.
Reply With Quote
Благодарность от:
Lynne
  #5  
Old 04-27-2015, 01:00 PM
JamesAB JamesAB is offline
 
Join Date: Dec 2003
Posts: 125
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you very much

That change appears to make it work as intended. My working code is now:
Code:
global $vbulletin;
if ($nextitem = $vbulletin->db->query_first("SELECT * FROM " . TABLE_PREFIX . "cron WHERE cronid = 31"))
{
    ignore_user_abort(1);
    @set_time_limit(0);

    require_once(DIR . '/includes/functions_cron.php');
    include_once(DIR . '/' . $nextitem['filename']);
}
Is there any way to suppress the output from my scheduled task when it's called from the attachdata_postsave hook, but allow it when the scheduled task is manually run from the AdminCP?

For example, I'm using echo commands in the scheduled task that are nice to show the progress in the AdminCP, but I'd like to hide them from the Manage Attachments window when attachdata_postsave is called from there.

Currently all the echo outup from the scheduled task shows up at the top of the Manage Attachments window after the attachdata_postsave hook is called and processes the scheduled task.

Thanks again,
James
Reply With Quote
  #6  
Old 04-27-2015, 01:04 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You can check for VB_AREA == 'AdminCP' and only echo if that's true.
Reply With Quote
Благодарность от:
Lynne
  #7  
Old 04-27-2015, 01:13 PM
JamesAB JamesAB is offline
 
Join Date: Dec 2003
Posts: 125
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That works perfectly.
Thanks for all your help.
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 03:48 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.04169 seconds
  • Memory Usage 2,229KB
  • 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
  • (3)bbcode_code
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (2)post_thanks_box_bit
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (2)post_thanks_postbit
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)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
  • 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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete