Console app for the web that runs all the time?

I’m working on a web app where there could be multiple users who need a recurring process - such as an email sent to them - and the customer’s data files will be in separate folders. The best way that I can see to handle this is to create a console app that is running all the time with a timer that will continually check to see if it is time to send the email. Since the data files are in separate client folders and they could each have different settings for the email, it would have to be a controller app that would periodically check each one and determine if the email should be sent.

Is a console web app that is running all the time the best way to handle this? Our plan is to deploy this app on xojocloud.

Before adding the complexity of a helper, you might try sending directly from the Web App first, using a timer.

Brandon, the issue I see if the web app needs to be running all the time with someone logged in.

I found some other info via AI, that describes the process like this:

  1. Create a console app compiled for Linux because Xojo cloud runs on a Linux server.

  2. Uploade the console app to your Xojo cloud using SFTP and your Xojo cloud credentials.

  3. Use an existing web app to start the console app. This is done with a shell command in your web app.

Xojo Web App is a console application

Xojo web apps are always running, even if nobody is using it. As @brian_franco said, Xojo Web apps are basically console apps anyway.

As already mentioned, you could just setup Timer in the App.Opening event that will be executed periodically.

As Timers will be executed on the Main Thread, any heavy operation could block processing new browser requests, so move anything that could be blocking them into a Thread. Also, when working with processes that aren’t tied to web sessions, you want to use a Timer instead of a WebTimer and a Thread instead of a WebThread.

Here is a sample project:
WebApplication-Timer.xojo_binary_project.zip (9.6 KB)

Alternatively, if you prefer the helper Console application, the Timer in the sample project would be calling a Shell that executes your helper process, instead of the Thread.

I add the email data into a host database then contact the WebApp with a HandleURL eg
https://www.MyCompany.com/SendAllEmails
which sends out all outstanding emails, then updates the database that the email has been sent (or any errors) so they aren’t sent again. No need for a Timer!

Ricardo - thank you for the sample app. That will be extremely helpful.

Follow up question.

If you are running on Xojo cloud and you have the medium server, since every application is running on each server, how do you prevent all three instances of the application from running the timer to check to see if emails should be sent?

I would take a different approach, a single helper app that sends the emails. You could set it up to run in a cronjob every 1m, 5m or whatever your duration is.

If you must do it from your web app, you could store a small data file in the user’s data folder with a timestamp of the most recent email sent. Then at the top of your “send email” routine you check for this file and see if an email has been sent recently, and if so, return.