Improve algorithm for determining if a user sync is necessary; Apply salt state in foreground to avoid collisions with setup salt states.

This commit is contained in:
Jason Ertel
2021-06-21 12:38:02 -04:00
parent 5e042bf4b8
commit f36ef86ccc

View File

@@ -236,12 +236,12 @@ function syncElastic() {
}
function syncAll() {
if [[ -f "$databasePath" && -f "$elasticUsersFile" ]]; then
usersFileAgeSecs=$((echo $(date +%s) - $(date +%s -r "$elasticUsersFile")))
if [[ -z "$FORCE_SYNC" && -f "$databasePath" && -f "$elasticUsersFile" ]]; then
usersFileAgeSecs=$(echo $(($(date +%s) - $(date +%s -r "$elasticUsersFile"))))
staleCount=$(echo "select count(*) from identity_credentials where updated_at >= Datetime('now', '-${usersFileAgeSecs} seconds');" \
| sqlite3 "$databasePath")
if [[ "$staleCount" == "0" ]]; then
return 1
fail "Users are already in sync. Run 'FORCE_SYNC=1 $0 sync' to force a full sync anyway."
fi
fi
syncElastic