You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a motion is detected, we want to send the picture where it was detected. We use mqtt to send the picture as bytearray because we cannot send the picture with a JSON. We could convert the image as base64 to be able to send it with JSON, but it would be very inefficient. Basically, we can't send the bytearray into a JSON, or at least I didn't find the solution.
The issue
Otherwise I send two messages, one to say "someone is here" and one to send the picture. It's fine, but the first one create a database entry and the second one modifies it to add the picture path. We can have race condition here... The order can't be guarantee.
I have decided to change the workflow. When a picture is coming, we are saving it on local drive (and another in the future maybe...) and we are saving this file path in database without any link to motion detected. To find pictures "associated" with a motion detection even, we can select pictures based on the date +- 10s for instance.
Otherwise, to link the picture with the event, we would have this kind of code in the task:
First, it's ugly, just look at the except! And secondly, it's not reliable, we could associate a picture with the wrong event in the case where two (or more) devices detect motion and send pictures.
The text was updated successfully, but these errors were encountered:
Limitation
When a motion is detected, we want to send the picture where it was detected. We use mqtt to send the picture as bytearray because we cannot send the picture with a JSON. We could convert the image as base64 to be able to send it with JSON, but it would be very inefficient. Basically, we can't send the bytearray into a JSON, or at least I didn't find the solution.
The issue
Otherwise I send two messages, one to say "someone is here" and one to send the picture. It's fine, but the first one create a database entry and the second one modifies it to add the picture path. We can have race condition here... The order can't be guarantee.
Or I can simply retry the second task if we don't found the database row. https://docs.celeryproject.org/en/stable/userguide/tasks.html#retrying
The solution
I have decided to change the workflow. When a picture is coming, we are saving it on local drive (and another in the future maybe...) and we are saving this file path in database without any link to motion detected. To find pictures "associated" with a motion detection even, we can select pictures based on the date +- 10s for instance.
Otherwise, to link the picture with the event, we would have this kind of code in the task:
First, it's ugly, just look at the except! And secondly, it's not reliable, we could associate a picture with the wrong event in the case where two (or more) devices detect motion and send pictures.
The text was updated successfully, but these errors were encountered: