For fire and forget tasks, that i want to make sur...
# box-products
s
For fire and forget tasks, that i want to make sure get completed, is
runAsync
the correct solution? i basically want to fire off a SQL task that runs when a user makes a change, but they dont need to wait around for it to finish
b
fire and forget tasks, that i want to make sure get completed
Isn't that an oxymoron?
Either you don't care what happens or you do care, but it can't be both 🙂
s
i do care
but i can wait a few minutes
basically every time the user makes a change i need to re-crunch some data, that should hopefully be done before they choose to view the reports
b
But are you needing some sort of promise object you can store in memory and interrogate to ask "are you done yet? How about now?"
s
yes, i think that would be a good flow, that way if i need to notify the user to wait a few minutes I can
b
Where do you plan to store this once the HTTP request finishes?
In the session scope or something?
s
yeah im using the session already, so that would make the most sence
b
Then you can basically do this either with runasync or cbfutures
But this sort of flow only works for a single web server
s
well we are in luck then
b
If you are round robin load balancing across two server • that object isn't going to serialize in the session • subsequent requests that hit another web server will not be able to check the status of an in-memory thread on another server
s
yeah for now that shouldn’t be a problem, i think in the future i could probably handle it more diligently with cbq
b
Meh, even with a queue, you still need some sort of shared storage to create a semaphore
s
for that i can just have a db column that i could update with the status of the job
b
Yes, but then you have to account for what happens when the job errors and never finishes 🙂
s
do you have another suggestion for a better way to solve my problem? Im open to suggestions
b
Lol, I'd say you're pretty close. Any time I have a flag somewhere that is updated async by another process, I always make the flag be the date the process started. That way if the date is present, BUT it's 8 hours old, I can effectively "time out" give up on it.
Otherwise, if you just set an
isRunning:true
somewhere, you may sit around waiting forever if the actual process died
s
yeah, thats a good plan. Thanks