0

I have developed a module to synchronize certain data from some internal software to our Magento installation. This task typically takes a few minutes and must be initiated by the user on an as-needed basis i.e., scheduling it as a recurring job via configuration is not an option.

My first consideration which I think would be the quickest and easiest approach would be to "fake it" using sockets. That is to say, I have one controller action which is invoked via AJAX request which simply opens/closes a socket (i.e., does not wait for a response) to a another controller action which actually performs the task. The first controller action could respond back with a message like "The job has been queued". There are no important results of the long running task, but I could easily log them somewhere to be later viewed if need be.

While I think the socket approach would work just fine, given that Magento has a cron implementation it makes sense to leverage that, but I can't seem to figure out a way to schedule a job in the cron_schedule table programatically i.e., without some XML configuration.

So that leads me to the question: is there a way to "manually" schedule a task in Magento's cron system without it a) reoccurring or b) requiring the use of XML configuration? Or would I be best off implementing my own cron.php approach for my own jobs like this one?

John Hall
  • 1,346
  • 13
  • 27
  • Would copying cron.php and customizing it achieve the same result? Sounds like you need to have Mage loaded when you run cron so just use a standalone Magento script and add it to your cron scheduler: http://stackoverflow.com/questions/28954182/get-cart-content-outside-of-magento-but-on-same-domain/28954802#28954802 – Vladimir Ramik Mar 08 '16 at 02:50
  • @VladimirRamik yes, this would be the approach I would take if I went about implementing my own additional cron/queue system which I have done for various other applications. I was wondering if there was any possibility of leveraging Magento's built-in `cron_schedule` table and related mechanisms as I thought that would be the cleanest approach. Since I think having two separate yet very similar cron services in a single application is kind of confusing, if I can't leverage Magento's implementation I'll probably just go ahead with the socket approach. – John Hall Mar 08 '16 at 14:22

1 Answers1

0

My solution was to write my own cron/task scheduler (there are also libraries out there for this sort of thing) managed via my own database table.

John Hall
  • 1,346
  • 13
  • 27