Best Way to Run a CRON Job as a Workflow?

Hi,

With other types of development environments, you can have a process running in the back at certain times of day to say… go through the database and look for specific changes.

This is called a cron job, where “cron” is short for the greek word chronos, meaning time.

So in other environments you can set a process to run every second, every 3 hours, at midnight each night, once a week, etc.

How do I set a workflow to run like this, on the database in Bubble, without any user being logged in and not needing to be triggered by a user at all? It should just run every 3 hours or so.

Thanks!

WOW! Was not obvious when flipping through dropdowns in the workflow editor, but the “do every 5 seconds” option when creating a workflow is editable. There is the Bubble equivalent to a CRON job

I wouldn’t recommend this in most apps, it will run as a client side flow holding up other workflows and costing a ton of workload units depending on the flow.

You can schedule backend workflows with recurring workflows (I wouldn’t recommend that as often as every minute or so as again it’ll destroy your workload units). You can do these daily, weekly, etc.

Another alternative is you can run database triggers with bubble which watches for data changes at all times for example when data field is (is not) x then auto run workflow on data record.

If you give more details on the objective I can give you what I view as your best options.

3 Likes

Thank you!

This is what I was after. I was trying to find the most resource efficient way to do this. Another possibility was to use an external API trigger and have Bubble listen but… seems like it may be resource intensive and I’m not all that sure how to make bubble listen.

Objective:

In the database I have customer transactions with expiration dates. When the dates pass, I’m sending an email to the users to remind them to take care of the transaction.

24 hours after the reminder, the transaction needs to settle automatically.

Ultimately, I need to do this check every 3-6 hours.

I wouldn’t do this as a recurring check.

I’d probably create a field based on an option set on the transaction for “status”.

Options something like:
created
open
Past due
Canceled
Paid
Error?

When transaction is created schedule an API workflow for expire-transaction date & time = let’s say current date & time + 7 days

It only triggers if status is not paid
This workflow simply changes the status from open to past due and sends the email then schedules another api flow for date time + 24 hrs to settle it automatically or mark as canceled.

I’d also have a database trigger for any transaction that is older than 48 hrs past expiration date and still not canceled or paid that changes status to “error?” and you list those in the your admin panel. (Bc this situation should never occur you need to either error these to check logs or send it back to the beginning of the flow).

Running a cron style on a list of all transactions will require overwriting of privacy rules which isn’t ideal. Rather run them on scheduled per transaction basis with safety net checks like above.

1 Like

Wow. That’s definitely the Bubble way to do it and a genius solution to the problem. Thank you so much.

I follow this. So for each transaction created, schedule an API workflow.

It’s a marketplace, so the users are setting their own expiration date/times for each transaction. This is pretty easy because the API workflow can just be set to whatever date/time they set as the transaction is created.

I do have a lot of other things to check and keep track of such as if they have both agreed the service was rendered, etc. But this technique should work and should be adaptable to the whole thing.

I’ll do a Bubble docs search on database triggers also… always something new to learn with Bubble. A lot easier than traditional programming on the UI side, marginally on the back end. ha ha.

Thanks again. I didn’t know this type of approach to the situation. It sounds a lot less resource intensive

1 Like

fun little mistake to make

1 Like

Yea bubble support is interesting with how they handle overages too. I guess they have a per their discretion one time per app forgiveness policy on overages. Had a client get $1200 over and even though bubble admitted that it was on their side due to failure to send real time alerts (over a day late) and an issue with their WU calculation they still used my clients “one time forgiveness” but reverted the charges.

For those new to Backend Workflows on Bubble, here is the tutorial.