Skip to content

Commit 4752150

Browse files
authored
fix(video uploader): upload pipe detection (#2352)
1 parent 77bc19b commit 4752150

File tree

1 file changed

+42
-6
lines changed

1 file changed

+42
-6
lines changed

Video/upload.sh

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,54 @@ function graceful_exit() {
5353
}
5454
trap graceful_exit SIGTERM SIGINT EXIT
5555

56-
while [ ! -p ${UPLOAD_PIPE_FILE} ];
57-
do
58-
echo "Waiting for ${UPLOAD_PIPE_FILE} to be created"
59-
sleep 1
56+
# Function to create the named pipe if it doesn't exist
57+
function create_named_pipe() {
58+
if [ ! -p "${UPLOAD_PIPE_FILE}" ];
59+
then
60+
if [ -e "${UPLOAD_PIPE_FILE}" ];
61+
then
62+
rm -f "${UPLOAD_PIPE_FILE}"
63+
fi
64+
mkfifo "${UPLOAD_PIPE_FILE}"
65+
echo "Created named pipe ${UPLOAD_PIPE_FILE}"
66+
fi
67+
}
68+
69+
TIMEOUT=300 # Timeout in seconds (5 minutes)
70+
START_TIME=$(date +%s)
71+
72+
while true; do
73+
if [ -e "${UPLOAD_PIPE_FILE}" ];
74+
then
75+
if [ -p "${UPLOAD_PIPE_FILE}" ];
76+
then
77+
break
78+
else
79+
echo "${UPLOAD_PIPE_FILE} exists but is not a named pipe"
80+
create_named_pipe
81+
fi
82+
else
83+
create_named_pipe
84+
fi
85+
86+
CURRENT_TIME=$(date +%s)
87+
ELAPSED_TIME=$((CURRENT_TIME - START_TIME))
88+
if [ ${ELAPSED_TIME} -ge ${TIMEOUT} ];
89+
then
90+
echo "Timeout waiting for ${UPLOAD_PIPE_FILE} to be created"
91+
exit 1
92+
fi
93+
94+
echo "Waiting for ${UPLOAD_PIPE_FILE} to be created"
95+
sleep 1
6096
done
6197

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

64100
rename_rclone_env
65101

66102
list_rclone_pid=()
67-
while read FILE DESTINATION < ${UPLOAD_PIPE_FILE}
103+
while read FILE DESTINATION < ${UPLOAD_PIPE_FILE};
68104
do
69105
if [ "${FILE}" = "exit" ];
70106
then
@@ -76,7 +112,7 @@ do
76112
list_rclone_pid+=($!)
77113
else
78114
# Wait for a batch rclone processes to finish
79-
if [ ${#list_rclone_pid[@]} -eq ${SE_VIDEO_UPLOAD_BATCH_CHECK} ]
115+
if [ ${#list_rclone_pid[@]} -eq ${SE_VIDEO_UPLOAD_BATCH_CHECK} ];
80116
then
81117
for pid in "${list_rclone_pid[@]}";
82118
do

0 commit comments

Comments
 (0)