X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (X-Cart 5) (https://forum.x-cart.com/forumdisplay.php?f=56)
-   -   Handling cron jobs / scheduled tasks (https://forum.x-cart.com/showthread.php?t=71851)

totaltec 04-15-2015 11:45 AM

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.

tony_sologubov 04-16-2015 01:19 AM

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

totaltec 04-16-2015 02:02 PM

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. :-)

tony_sologubov 04-17-2015 12:40 AM

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?


All times are GMT -8. The time now is 04:45 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.