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
Copy file name to clipboardExpand all lines: misc/run-command-shim
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -47,21 +47,20 @@ fi
47
47
48
48
### Retry logic to acquire lock and execute the command
49
49
set +e # disable exit on non-zero return code
50
-
localretry_attempts=0
50
+
retry_attempts=0
51
51
52
52
# Create lock file if it does not exist
53
53
if [ !-f"$LOCKFILE" ];then
54
54
touch "$LOCKFILE"
55
55
echo"Lock file $LOCKFILE has been created."
56
56
fi
57
57
58
+
set -x
58
59
while(( retry_attempts <10));do
59
-
set -x
60
60
# Acquire the exclusive (-x) and non-blocking (-n) lock on the lock file and execute $commandToExecute(side note: flock is part of util-linux package and is available by default on most Linux distros)
61
61
flock -x -n "$LOCKFILE" -c "$commandToExecute"
62
62
flock_status=$?# Capture the exit status of the flock command
63
-
set +x
64
-
63
+
65
64
if [ $flock_status-eq 1 ];then
66
65
echo"Lock already held by another process. Retrying..."
67
66
((++retry_attempts))
@@ -77,6 +76,7 @@ while (( retry_attempts < 10 )); do
77
76
break
78
77
fi
79
78
done
79
+
set +x
80
80
### End of retry logic
81
81
82
82
# Do not return error if lock not acquired even after retries expire, make a best effort attempt to start run-command-handler
0 commit comments