Process single/exclusive execution strategy in Xano : Dealing with processing errors.

Options
MattLaro
MattLaro Member ✭✭
edited July 2023 in ❓Other questions

Hi,

I'm trying to implement a outgoing REST calls processing queue.

The processing table queue is done.

The processing function is done and works.

My challenge now is to make sure that, at any given time, there's only a single execution of my processing function to prevent that an outgoing call is ran twice by two processes because the two processes read this outgoing call as waiting to be processed.

The idea I got is to make a table "state" where I have a single row having "REST_API_PROCESSING" as test and "is_active" as boolean.

Everytime the function to broadcast outgoing calls is called, it will make a very quick row edit to check "is_active" at the very beginning and the uncheck "is_active" at the end, so if another broadcast is called, this one will not be executed at the same time.

My challenge however, if an error happens while broadcasting, the "is_active" will stay checked and unless I notice it, all broadcasting events will totally stop from happening.

My questions

Is there a way I can uncheck the "is_active" by editing the row in case of error ?

OR

Do you have any suggestions as another way to implement a one-at-a-time execution strategy ?

Thank you for your input and ideas :).

Matt

Comments

  • MattLaro
    MattLaro Member ✭✭
    edited July 2023
    Options

    Well, I just had the most terrible yet terrific idea to how to implement this 😂.

    I would use the following :

    1. A function call to launch broadcasting
    2. An API call that does the processing
    3. A salt value stored in environment variables (let's call it "HANDSHAKE_SALT").
    4. A boolean cache value called "REST_API_PROCESSING".
    5. A cached UUID value called "PROCESSING_HANDSHAKE".

    Then, call the function to launch broadcasting that will do the following :

    1. Check if REST_API_PROCESSING = true. If false, proceed to 2.
    2. Create cache value REST_API_PROCESSING = true.
    3. Create a UUID.
    4. Store the UUID in PROCESSING_HANDSHAKE cache value.
    5. Encode the UUID with the salt using HANSHAKE_SALT → "SALTED_HANDSHAKE"
    6. Call the API endpoint with header "X-Salted-Handshake: <SALTED_HANDSHAKE>"
    7. Delete cache value "REST_API_PROCESSING".
    8. Delete cache value of "PROCESSING_HANDSHAKE".

    In the API Call

    1. Retrieve the header "X-Salted-Handshake" → "SALTED_HANDSHAKE"
    2. Check if "SALTED_HANDSHAKE" = "PROCESSING_HANDSHAKE" encoded with "HANDSHAKE_SALT". If true, continue to 3.
    3. Go through the processing queue and do the necessary processing.

    If the API Call has some kind of error at some point, it doesn't matter as it will proceed to remove REST_API_PROCESSING from the cache anyway. Plus, the API call is extra secured as the "X-Salted-Handshake" value is a very short lived one!


    I will try this out. If anyone has any better idea though, let me know.