Using slugs won’t scale because every time you force Bubble to increment the slug ID (e.g.: slug-100, slug-101, slug-102), it consumes more WU.
However, I noticed that Bubble’s scheduler seems to use unique and incrementing integers.
Imagine a database with this single record:
Unique ID: 111x982
Scheduled Workflow ID: 482842
Sequence ID: 1000
Then you create two more records. On the record creation workflow, you add two steps:
- Schedule API workflow that will do something with this newly created record, maybe a second into the future
- Save the API workflow ID to the record
So if we do that twice, we get this database:
First record
Unique ID: 111x982
Scheduled Workflow ID: 482842
Sequence ID: 1000
Second record
Unique ID: 111x881
Scheduled Workflow ID: 485112
Sequence ID: null
Third record
Unique ID: 111x592
Scheduled Workflow ID: 485117
Sequence ID: null
Note that the Unique IDs are arbitrary and so are the scheduled workflow IDs. The only thing that matters is that the Scheduled Workflow IDs are sequential and unique.
Then the scheduled workflow does this:
- Search for the first record that has a Sequence ID of null, ordered by Scheduled Workflow ID ascending.
- Does that returned record have the same Scheduled Workflow ID as the record in the scheduled workflow?
- If so, then save the Sequence ID in the scheduled workflow record as +1 to the record found in step 1.
- If not, reschedule itself and save the new Scheduled Workflow ID to itself.
Using our sample database:
-
If record 2’s scheduled workflow runs before record 3’s, then the Sequence ID will be set to 1,001. When record 3’s scheduled workflow runs, it will set its Sequence ID to 1,002.
-
If record 3’s scheduled workflow runs before record 2, then it will reschedule itself until record 2’s scheduled workflow runs.
Assumptions:
- Bubble’s scheduler returns a unique and sequential integer.
- Bubble’s scheduled workflows are guaranteed to run.
Safeguards:
- In the case something goes wrong, you don’t want to infinitely have scheduled workflows rescheduling themselves every second. You could put a reschedule counter that auto-terminates itself and notifies you.
I haven’t tested this, but before I put in time, does anyone see why this wouldn’t work? I was up late last night watching hockey, so not totally sharp today.
Yes, I know this consumes WUs, but it should be consistent WUs and maybe worth it if having unique sequential IDs matters. E.g.: generating invoice numbers.
@mikeloc @georgecollier @lindsay_knowcode @chris.williamson1996 @and other smart bubblers I’ve forgotten