fix sync bug for scheduled work

This commit is contained in:
JesseMarkowitz
2026-08-18 10:31:28 -04:00
parent 999429f61e
commit b0aa05a2b1
2 changed files with 40 additions and 5 deletions
+11 -1
View File
@@ -50,9 +50,15 @@ if (-not (Test-Path $launcher)) {
# Task Scheduler runs multiple actions in order but reports only the last one's
# result, so a failure in an earlier provider would be invisible. The loop keeps
# going after a failure and propagates a non-zero exit code.
#
# /v:on and !RC! are required, not stylistic: cmd expands every %VAR% on a
# command line *before* running any of it, so "exit /b %RC%" would report the
# value RC had before the loop ever ran - i.e. always success. Delayed expansion
# reads it at the point of use.
$loop = ($Provider | ForEach-Object { "`"$launcher`" sync --provider $_ --joplin-optional || set RC=1" }) -join ' & '
$taskArgs = "/v:on /c set RC=0 & $loop & exit /b !RC!"
$actions = New-ScheduledTaskAction -Execute 'cmd.exe' `
-Argument "/c set RC=0 & $loop & exit /b %RC%" `
-Argument $taskArgs `
-WorkingDirectory $repo
$trigger = New-ScheduledTaskTrigger -Daily -At $Time
@@ -75,6 +81,10 @@ Register-ScheduledTask -TaskName $TaskName `
Write-Host "Registered '$TaskName' - daily at $Time for: $($Provider -join ', ')"
Write-Host ''
Write-Host 'Command the task will run:'
Write-Host " cmd.exe $taskArgs"
Write-Host " (working directory: $repo)"
Write-Host ''
Write-Host 'Next steps:'
Write-Host " * Run it once now: Start-ScheduledTask -TaskName $TaskName"
Write-Host " * Check the result: Get-ScheduledTaskInfo -TaskName $TaskName"