41 lines
977 B
Bash
Executable file
41 lines
977 B
Bash
Executable file
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
ENV_FILE="${ROOT_DIR}/config/env.local"
|
|
if [[ ! -f "${ENV_FILE}" ]]; then
|
|
ENV_FILE="${ROOT_DIR}/config/env.example"
|
|
fi
|
|
# shellcheck source=/dev/null
|
|
source "${ENV_FILE}"
|
|
# shellcheck source=/dev/null
|
|
source "${ROOT_DIR}/src/client.sh"
|
|
|
|
limit="${SYNC_LIMIT:-200}"
|
|
wait_ms="${SYNC_WAIT_MS:-15000}"
|
|
cursor_file="${ROOT_DIR}/.cursor"
|
|
cursor=""
|
|
|
|
if [[ -f "${cursor_file}" ]]; then
|
|
cursor="$(cat "${cursor_file}")"
|
|
fi
|
|
|
|
while true; do
|
|
if [[ -n "${cursor}" ]]; then
|
|
path="/v2/graph/changes?since_cursor=${cursor}&limit=${limit}&wait_ms=${wait_ms}"
|
|
else
|
|
path="/v2/graph/changes?limit=${limit}&wait_ms=${wait_ms}"
|
|
fi
|
|
|
|
resp="$(api_get "${path}")"
|
|
echo "${resp}"
|
|
|
|
next="$(printf '%s\n' "${resp}" | sed -n 's/.*"next_cursor":"\([^"]*\)".*/\1/p')"
|
|
if [[ -n "${next}" ]]; then
|
|
cursor="${next}"
|
|
printf '%s' "${cursor}" > "${cursor_file}"
|
|
fi
|
|
|
|
sleep 1
|
|
done
|