-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f62a2d7
commit c3a5e85
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/bin/bash | ||
|
||
# Debounce time in seconds | ||
DEBOUNCE_TIME=5 | ||
|
||
# Declare an associative array to track timers | ||
declare -A file_timers | ||
|
||
process_event() { | ||
local file="$1" | ||
# if just a regular file or folder edited -> scan it | ||
# if if it is a dbmeta.yml file -> scan the whole folder by stripping the .dbmeta.yml suffix | ||
if [[ "$file" == *".dbmeta.yml" ]]; then | ||
file="${file%.dbmeta.yml}" | ||
fi | ||
|
||
php /var/www/html/worker.php --scan "$file" | ||
} | ||
|
||
# watch mounted /var/www/html/public for changes | ||
inotifywait -q -m -r -e create,attrib,delete,modify,move --format '%w%f' /var/www/html/public | while read -r file; do | ||
|
||
# Cancel any existing debounce timer for this path | ||
if [[ -n "${file_timers[$file]}" ]]; then | ||
# echo "Cancel indexing for $file due to new event (inotify)" | ||
kill "${file_timers[$file]}" 2>/dev/null | ||
fi | ||
|
||
# echo "Queueing event for $file (inotify)" | ||
# Start a new debounce timer for this path | ||
( | ||
sleep "$DEBOUNCE_TIME" | ||
process_event "$file" | ||
) & | ||
|
||
# Record the PID of the background process | ||
file_timers["$file"]=$! | ||
done |