Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Handling cron jobs / scheduled tasks

 
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 04-15-2015, 11:45 AM
  totaltec's Avatar 
totaltec totaltec is offline
 

X-Guru
  
Join Date: Jan 2007
Location: Louisville, KY USA
Posts: 5,823
 

Default Handling cron jobs / scheduled tasks

Hi guys and gals,

I am building an integration with an inventory management app and we need to run code based on a cron job or scheduled task.

I have found this article: http://kb.x-cart.com/pages/viewpage.action?pageId=7504112 and I now understand that the entry point for cron jobs is console.php

What I don't understand is the proper way to include my viewer or controller class in with the group that is run by console.php

I have found this class XLite\Controller\Console\AConsole.php and when I put error_log() in one of its methods the log is created. So I know that it is running when a request is made to console.php

My question is: How do I include my code in this cron job? Do I need to extend or decorate a certain class? Perhaps I add my class to a certain list?

Thanks in advance for any help.
__________________
Mike White - Now Accepting new clients and projects! Work with the best, get a US based development team for just $125 an hour. Call 1-502-773-6454, email mike at babymonkeystudios.com, or skype b8bym0nkey

XcartGuru
X-cart Tutorials | X-cart 5 Tutorials

Check out the responsive template for X-cart.
Reply With Quote
  #2  
Old 04-16-2015, 01:19 AM
  tony_sologubov's Avatar 
tony_sologubov tony_sologubov is offline
 

X-Cart team
  
Join Date: Jan 2009
Posts: 2,431
 

Default Re: Handling cron jobs / scheduled tasks

The example of registering cron tasks is XC/MultiCurrency module.

Its install.yaml contains the registration of cron task:
Code:
XLite\Model\Task: - owner: XLite\Module\XC\MultiCurrency\Core\Task\UpdateRates

and the task itself is described in the aforementioned class:
Code:
\XLite\Module\XC\MultiCurrency\Core\Task\UpdateRates

The routine that actually runs all cron tasks is doNoAction() method of the \XLite\Controller\Console\Cron class.

Please, let me know if this info helps. Of course, Mike, if there is any other question, just let me know.

Tony
__________________
Found a bug in X-Cart? Post it to our bug tracker!
Know how to make X-Cart better? Suggest an idea!
Reply With Quote

The following user thanks tony_sologubov for this useful post:
totaltec (04-16-2015)
  #3  
Old 04-16-2015, 02:02 PM
  totaltec's Avatar 
totaltec totaltec is offline
 

X-Guru
  
Join Date: Jan 2007
Location: Louisville, KY USA
Posts: 5,823
 

Default Re: Handling cron jobs / scheduled tasks

Very helpful Tony! I can't thank you enough.

I think the article I linked above would do well to include this information. I understand that this article is intended for a different audience than developers, but as you know we need dev docs for these things as well, and there could be a link to a full explanation.

Of course we are at least documenting this in the forum.

One tip I have is to make sure you are calling --target=cron. We forgot that part initially, and even after we understood that we needed to schedule the task via yaml it was still a problem.
__________________
Mike White - Now Accepting new clients and projects! Work with the best, get a US based development team for just $125 an hour. Call 1-502-773-6454, email mike at babymonkeystudios.com, or skype b8bym0nkey

XcartGuru
X-cart Tutorials | X-cart 5 Tutorials

Check out the responsive template for X-cart.
Reply With Quote

The following user thanks totaltec for this useful post:
tony_sologubov (04-17-2015)
  #4  
Old 04-17-2015, 12:40 AM
  tony_sologubov's Avatar 
tony_sologubov tony_sologubov is offline
 

X-Cart team
  
Join Date: Jan 2009
Posts: 2,431
 

Default Re: Handling cron jobs / scheduled tasks

Quote:
Originally Posted by totaltec
I think the article I linked above would do well to include this information. I understand that this article is intended for a different audience than developers, but as you know we need dev docs for these things as well, and there could be a link to a full explanation.

Totally agree, Mike. I planned it to my tasks.

Quote:
One tip I have is to make sure you are calling --target=cron. We forgot that part initially, and even after we understood that we needed to schedule the task via yaml it was still a problem.

I hope, now everything is set up correctly, right?
__________________
Found a bug in X-Cart? Post it to our bug tracker!
Know how to make X-Cart better? Suggest an idea!
Reply With Quote
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 12:12 PM.

   

 
X-Cart forums © 2001-2020