Using CommandBox for background processing


I need to execute background tasks. For example, consume messages from different message queues (think ActiveMQ or RabbitMQ) and execute related tasks, which can be almost anything: sending emails, connecting to databases (even the “weird” ones, like MongoDB :wink: ), receiving files from remote systems and saving them to a local filesystem, interacting with the underlying operating system… you name it! If I was a Python guy, I’d probably be thinking about Celery. But I’m a CF guy and I want to leverage the power of CFML.

Can CommandBox be used in such manner? Can I schedule tasks in CB to run every “n” seconds/minutes/hours? Can it start with the system, run in the background (daemon, service), listen to different message queues (through a Java client jar), and when a message arrives, fire CF code asynchronously?

I’m sick and tired of scheduled tasks and using application server for processing background tasks. Event gateways in Lucee are an unsolved mystery. I’m just looking for the right tool, hoping that CB is the ultimate answer :slight_smile:

Yes you can.

Remember that box is a OS binary. You can execute it via cron or as a Deamon.

We have used it before this way. So there are no limitations.

Luis Majano
Ortus Solutions, Corp
P/F: 1-888-557-8057

Luis, this is brilliant, thanks a lot for your answer!

I’ve read the entire book and all the documentation I could find, but still can’t wrap my head around the best way of using CommandBox for multiple tasks processing, and not killing the server at the same time :slight_smile:

Let’s say we have 100+ tasks of a different nature. Some of them are transforming data (reading from one datasource and writing to another), other are listening to the message queues, other send emails, you know, all sorts of things. Each of task can have a different priority (how often needs to run) and can take different time to complete - some of them need to react ASAP (let’s say seconds), other need to act every 10 minutes or once a day. What would be the best way of using CommandBox for it?

I’ve found your example of “messaging polyglot” (cool stuff btw!), where you basically start a long running request which is querying the queue for new messages in an endless loop. Is this a good approach for spinning up 100 and more threads doing their job at the same time?
Or maybe a better approach would be to leverage one instance of Box per task by an external scheduler (and using Box’s commands or recipes)? I think it would mean having a lot of instances of Box in memory, loading and unloading - is it a recommended way of using Box? I’ve seen /cfml/system/modules/task-commands/commands/task/*, but it seems not yet implemented…

You also mention that you were using Box this way before - may I ask what is your current approach and tools you use?
I just want to avoid newbie errors, hoping to hear experts sharing their experiences.