Skip to content

Commit

Permalink
Update replication script to send message to slack
Browse files Browse the repository at this point in the history
  • Loading branch information
Rub21 committed Nov 8, 2024
1 parent 6ffb71d commit feeb6f1
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
3 changes: 2 additions & 1 deletion images/replication-job/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ RUN apt-get update && \
nginx \
python3-pip \
python3-venv \
procps && \
procps \
curl && \
rm -rf /var/lib/apt/lists/*

RUN python3 -m venv /opt/venv
Expand Down
30 changes: 30 additions & 0 deletions images/replication-job/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ else
echo JAVACMD_OPTIONS=\"-server -Xmx$memory\" >~/.osmosis
fi

slack_message_count=0
max_slack_messages=2

workingDirectory="/mnt/data"
mkdir -p $workingDirectory

Expand Down Expand Up @@ -74,6 +77,32 @@ function upload_file_cloud() {
fi
}

function send_slack_message() {
# Check if Slack messaging is enabled
if [ "${ENABLE_SEND_SLACK_MESSAGE}" != "true" ]; then
echo "Slack messaging is disabled. Set ENABLE_SEND_SLACK_MESSAGE to true to enable."
return
fi

# Check if the Slack webhook URL is set
if [ -z "${SLACK_WEBHOOK_URL}" ]; then
echo "SLACK_WEBHOOK_URL is not set. Unable to send message to Slack."
return 1
fi

# Limit Slack message count to 3
if [ "$slack_message_count" -ge "$max_slack_messages" ]; then
echo "Max Slack messages limit reached. No further messages will be sent."
return
fi

local message="$1"
curl -X POST -H 'Content-type: application/json' --data "{\"text\": \"$message\"}" "$SLACK_WEBHOOK_URL"
echo "Message sent to Slack: $message"
slack_message_count=$((slack_message_count + 1))
}


function monitor_minute_replication() {
# Function to handle continuous monitoring, minute replication, and sequential upload to cloud provider
# Directory to store a log of the last processed file
Expand Down Expand Up @@ -109,6 +138,7 @@ function monitor_minute_replication() {
echo "Stopping any existing Osmosis processes..."
pkill -f "osmosis.*--replicate-apidb"
echo "Regenerating $local_minute_file..."
send_slack_message "${ENVIROMENT}: Corrupted file $local_minute_file detected. Regenerating the file..."
generate_replication
fi
fi
Expand Down
2 changes: 1 addition & 1 deletion images/web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ RUN npm install -g svgo
RUN rm -rf $workdir/html

## Sep 2023
ENV OPENSTREETMAP_WEBSITE_GITSHA=d23763d6cdbf5ec11f0e83f8e6e8fb32ed973e6a
ENV OPENSTREETMAP_WEBSITE_GITSHA=1ad7f22a04465c32ce82ffaac3aaee0df119648b
RUN curl -L https://github.com/openstreetmap/openstreetmap-website/archive/$OPENSTREETMAP_WEBSITE_GITSHA.zip --output website.zip && unzip website.zip
RUN mv openstreetmap-website-$OPENSTREETMAP_WEBSITE_GITSHA/* $workdir/
WORKDIR $workdir
Expand Down
6 changes: 6 additions & 0 deletions osm-seed/templates/jobs/replication-job-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ spec:
- name: MEMORY_JAVACMD_OPTIONS
value: {{ .Values.replicationJob.resources.requests.memory | default "2Gi" | quote}}
{{- end }}
- name: ENABLE_SEND_SLACK_MESSAGE
value: {{ .Values.replicationJob.env.ENABLE_SEND_SLACK_MESSAGE | quote}}
- name: SLACK_WEBHOOK_URL
value: {{ .Values.replicationJob.env.SLACK_WEBHOOK_URL | quote}}
- name: ENVIROMENT
value: {{ .Values.environment | quote}}
{{- if .Values.replicationJob.nodeSelector.enabled }}
nodeSelector:
{{ .Values.replicationJob.nodeSelector.label_key }} : {{ .Values.replicationJob.nodeSelector.label_value }}
Expand Down
3 changes: 3 additions & 0 deletions osm-seed/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ replicationJob:
image:
name: ""
tag: ""
env:
ENABLE_SEND_SLACK_MESSAGE: "false"
SLACK_WEBHOOK_URL: "null"
resources:
enabled: false
requests:
Expand Down

0 comments on commit feeb6f1

Please sign in to comment.