Files
tm_back/upload.sh
T
Mazyar 582f8b5c02
continuous-integration/drone/push Build is passing
Enhance TED scraper and worker initialization with startup catch-up logic
- Introduced a mutex to ensure only one TED scraper run executes at a time, preventing concurrent executions during startup and scheduled runs.
- Implemented a mechanism to check if today's TED scrape has already been completed during startup, logging appropriate messages for both completed and new runs.
- Added startup catch-up logic for tender translations and unprocessed notices, ensuring that any missed tasks are executed without blocking the application startup.

This update improves the reliability and efficiency of the TED scraper and worker processes, ensuring that all necessary tasks are completed after a server restart.
2026-06-28 00:05:10 +03:30

70 lines
2.0 KiB
Bash

#!/bin/bash
set -euo pipefail
# Remote server configuration
REMOTE_USER="${REMOTE_USER:-root}"
REMOTE_HOST="${REMOTE_HOST:-}"
REMOTE_PATH="${REMOTE_PATH:-/opt/tm-back}"
SSH_KEY="${SSH_KEY:-}"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
usage() {
echo "Usage: $0 --host <remote-host> [--user <user>] [--path <remote-path>] [--key <ssh-key>]"
echo ""
echo "Options:"
echo " --host Remote server hostname or IP (required)"
echo " --user Remote user (default: root)"
echo " --path Remote destination path (default: /opt/tm-back)"
echo " --key Path to SSH private key (optional)"
echo ""
echo "Environment variables REMOTE_USER, REMOTE_HOST, REMOTE_PATH, SSH_KEY can also be used."
exit 1
}
while [[ $# -gt 0 ]]; do
case "$1" in
--host) REMOTE_HOST="$2"; shift 2 ;;
--user) REMOTE_USER="$2"; shift 2 ;;
--path) REMOTE_PATH="$2"; shift 2 ;;
--key) SSH_KEY="$2"; shift 2 ;;
-h|--help) usage ;;
*) echo "Unknown option: $1"; usage ;;
esac
done
if [[ -z "$REMOTE_HOST" ]]; then
echo "Error: --host is required"
usage
fi
SSH_CMD="ssh"
if [[ -n "$SSH_KEY" ]]; then
SSH_CMD="ssh -i $SSH_KEY"
fi
echo "==> Uploading source code to ${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_PATH}"
# Create remote directory
${SSH_CMD} "${REMOTE_USER}@${REMOTE_HOST}" "mkdir -p ${REMOTE_PATH}"
# Rsync source code, excluding non-essential files
rsync -avz --progress \
--exclude 'bin/' \
--exclude 'artifacts/' \
--exclude '.git/' \
--exclude '.idea/' \
--exclude '.vscode/' \
--exclude '*.exe' \
--exclude 'Dockerfile' \
--exclude 'upload.sh' \
${SSH_KEY:+-e "ssh -i $SSH_KEY"} \
"${SCRIPT_DIR}/" \
"${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_PATH}/"
echo ""
echo "==> Upload complete to ${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_PATH}"
echo ""
echo "To build and run on the remote server:"
echo " ${SSH_CMD} ${REMOTE_USER}@${REMOTE_HOST} 'cd ${REMOTE_PATH} && go build -o bin/web ./cmd/web'"