Skip to content

Commit

Permalink
fix(video uploader): upload pipe detection (#2352)
Browse files Browse the repository at this point in the history
  • Loading branch information
nandorpal authored Aug 12, 2024
1 parent 77bc19b commit 4752150
Showing 1 changed file with 42 additions and 6 deletions.
48 changes: 42 additions & 6 deletions Video/upload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,54 @@ function graceful_exit() {
}
trap graceful_exit SIGTERM SIGINT EXIT

while [ ! -p ${UPLOAD_PIPE_FILE} ];
do
echo "Waiting for ${UPLOAD_PIPE_FILE} to be created"
sleep 1
# Function to create the named pipe if it doesn't exist
function create_named_pipe() {
if [ ! -p "${UPLOAD_PIPE_FILE}" ];
then
if [ -e "${UPLOAD_PIPE_FILE}" ];
then
rm -f "${UPLOAD_PIPE_FILE}"
fi
mkfifo "${UPLOAD_PIPE_FILE}"
echo "Created named pipe ${UPLOAD_PIPE_FILE}"
fi
}

TIMEOUT=300 # Timeout in seconds (5 minutes)
START_TIME=$(date +%s)

while true; do
if [ -e "${UPLOAD_PIPE_FILE}" ];
then
if [ -p "${UPLOAD_PIPE_FILE}" ];
then
break
else
echo "${UPLOAD_PIPE_FILE} exists but is not a named pipe"
create_named_pipe
fi
else
create_named_pipe
fi

CURRENT_TIME=$(date +%s)
ELAPSED_TIME=$((CURRENT_TIME - START_TIME))
if [ ${ELAPSED_TIME} -ge ${TIMEOUT} ];
then
echo "Timeout waiting for ${UPLOAD_PIPE_FILE} to be created"
exit 1
fi

echo "Waiting for ${UPLOAD_PIPE_FILE} to be created"
sleep 1
done

echo "Waiting for video files put into pipe for proceeding to upload"

rename_rclone_env

list_rclone_pid=()
while read FILE DESTINATION < ${UPLOAD_PIPE_FILE}
while read FILE DESTINATION < ${UPLOAD_PIPE_FILE};
do
if [ "${FILE}" = "exit" ];
then
Expand All @@ -76,7 +112,7 @@ do
list_rclone_pid+=($!)
else
# Wait for a batch rclone processes to finish
if [ ${#list_rclone_pid[@]} -eq ${SE_VIDEO_UPLOAD_BATCH_CHECK} ]
if [ ${#list_rclone_pid[@]} -eq ${SE_VIDEO_UPLOAD_BATCH_CHECK} ];
then
for pid in "${list_rclone_pid[@]}";
do
Expand Down

0 comments on commit 4752150

Please sign in to comment.