jacksonargo / cloudburrito

A slack app to download burritos from the cloud.
https://cloudburrito.jacksonargo.com
MIT License
0 stars 1 forks source link

Not thread safe #2

Open jacksonargo opened 7 years ago

jacksonargo commented 7 years ago

Multiple threads of a unicorn means the same message is sent multiple times.

jacksonargo commented 7 years ago

This happens because the unsent message events finds all the unsent messages, and then tries to send them without checking if they have already been sent.

I might be able to get away with just checking if it has already been sent, but more generally, I guess I need to use a mutex.

I'm considering creating a Mutex model that is used by all events. Each event, like unsent messages and stale burritos, would try to create their mutex in the database. If the mutex already exists, then they wont be able to create it, and they skip working.

jacksonargo commented 7 years ago

Locks working and it is thread safe.

jacksonargo commented 7 years ago

Ok nvm. Definitely not thread safe. I apparently got 4 burritos by ordering one.