Register Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools
  #1  
Old 27 Apr 2015, 12:52
JamesAB JamesAB is offline
 
Join Date: Jan 2004
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
__________________
Custom HTTP Error Pages
Reply With Quote
  #2  
Old 27 Apr 2015, 13:14
kh99 kh99 is offline
 
Join Date: Aug 2009
Real name: Kevin
I haven't tested it, but looking at the code in admincp/cronadmin.php for running a scheduled task, I think this might work:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

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.

Last edited by kh99; 27 Apr 2015 at 13:25.
Reply With Quote
  #3  
Old 27 Apr 2015, 14:38
JamesAB JamesAB is offline
 
Join Date: Jan 2004
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:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Hoever, its producing this error now:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Any help would be appreciated.
__________________
Custom HTTP Error Pages
Reply With Quote
  #4  
Old 27 Apr 2015, 14:44
kh99 kh99 is offline
 
Join Date: Aug 2009
Real name: Kevin
Hmm...seems like that should be right. You could try

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


but I don't see why $this->registry wouldn't work.
Reply With Quote
  #5  
Old 27 Apr 2015, 15:00
JamesAB JamesAB is offline
 
Join Date: Jan 2004
Thank you very much

That change appears to make it work as intended. My working code is now:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

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
__________________
Custom HTTP Error Pages
Reply With Quote
  #6  
Old 27 Apr 2015, 15:04
kh99 kh99 is offline
 
Join Date: Aug 2009
Real name: Kevin
You can check for VB_AREA == 'AdminCP' and only echo if that's true.
Reply With Quote
  #7  
Old 27 Apr 2015, 15:13
JamesAB JamesAB is offline
 
Join Date: Jan 2004
That works perfectly.
Thanks for all your help.
__________________
Custom HTTP Error Pages
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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


New To Site? Need Help?

All times are GMT. The time now is 08:26.

Layout Options | Width: Wide Color: