Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: upload pipe detection #2352

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading