use locking by mkdir
This commit is contained in:
parent
c1ee761a65
commit
56f1986cab
11
update
11
update
@ -4,6 +4,8 @@
|
|||||||
CSV_URL="https://www8.cao.go.jp/chosei/shukujitsu/syukujitsu.csv"
|
CSV_URL="https://www8.cao.go.jp/chosei/shukujitsu/syukujitsu.csv"
|
||||||
|
|
||||||
# Internal configuration settings
|
# Internal configuration settings
|
||||||
|
LOCK_DIR="lock"
|
||||||
|
|
||||||
TMP_CSV_FILE="holidays-jp-tmp.csv"
|
TMP_CSV_FILE="holidays-jp-tmp.csv"
|
||||||
RAW_CSV_FILE="holidays-jp-raw.csv"
|
RAW_CSV_FILE="holidays-jp-raw.csv"
|
||||||
CSV_FILE="holidays-jp.csv"
|
CSV_FILE="holidays-jp.csv"
|
||||||
@ -21,6 +23,12 @@ if ! command -v nkf >/dev/null; then
|
|||||||
exit $EXIT_FAILURE
|
exit $EXIT_FAILURE
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Acquire the lock or exit
|
||||||
|
if ! mkdir "$LOCK_DIR" 2>/dev/null; then
|
||||||
|
echo "Another process is holding the lock. Exiting."
|
||||||
|
exit $EXIT_FAILURE
|
||||||
|
fi
|
||||||
|
|
||||||
# Run
|
# Run
|
||||||
curl -sS -L -o $TMP_CSV_FILE $CSV_URL
|
curl -sS -L -o $TMP_CSV_FILE $CSV_URL
|
||||||
if ! diff -q $RAW_CSV_FILE $TMP_CSV_FILE >/dev/null 2>&1; then
|
if ! diff -q $RAW_CSV_FILE $TMP_CSV_FILE >/dev/null 2>&1; then
|
||||||
@ -30,5 +38,8 @@ else
|
|||||||
rm $TMP_CSV_FILE
|
rm $TMP_CSV_FILE
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Release the lock
|
||||||
|
rmdir "$LOCK_DIR"
|
||||||
|
|
||||||
# Exit
|
# Exit
|
||||||
exit $EXIT_SUCCESS
|
exit $EXIT_SUCCESS
|
||||||
|
Loading…
Reference in New Issue
Block a user