-
Notifications
You must be signed in to change notification settings - Fork 3
/
entrypoint.sh
52 lines (42 loc) · 1.45 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/sh
touch /app/data/last_poll_time
# Function to execute the command when a file is created
run_command() {
local input_path="$1"
local output_path=$(echo "$input_path" | sed 's/\/csvs\//\/fields\//')
local mode=""
local breakdown=""
if [ -n "$(echo $input_path | grep '/absolute/')" ]; then
mode="absolute"
elif [ -n "$(echo $input_path | grep '/differential/')" ]; then
mode="differential"
elif [ -n "$(echo $input_path | grep '/normalized/')" ]; then
mode="normalized"
fi
if [ -n "$(echo $input_path | grep '/daily/')" ]; then
breakdown="daily"
elif [ -n "$(echo $input_path | grep '/hourly/')" ]; then
breakdown="hourly"
elif [ -n "$(echo $input_path | grep '/weekly/')" ]; then
breakdown="weekly"
elif [ -n "$(echo $input_path | grep '/monthly/')" ]; then
breakdown="monthly"
fi
eval "cat $input_path | src/cli.js -b '$breakdown' -m '$mode' $output_path"
}
# Monitor the linked volume for file modifications using polling
echo "Watching for new CSVs..."
while true; do
# Check if there are any new files in the directory
new_files=$(find /app/data/csvs -type f -newer /app/data/last_poll_time)
if [ -n "$new_files" ]; then
for file in $new_files; do
echo "New CSV: $file"
run_command "$file"
done
# Update the last poll time
touch /app/data/last_poll_time
fi
# Sleep for a defined interval before polling again
sleep 10 # Poll every 10 seconds, adjust as needed
done