Skip to content

fix(schedule): run missed scheduled tasks when the machine becomes available - #98

Open
AsterZ99 wants to merge 1 commit into
ok-oldking:masterfrom
AsterZ99:fix/schedule-trigger-when-available
Open

AsterZ99 wants to merge 1 commit into
ok-oldking:masterfrom
AsterZ99:fix/schedule-trigger-when-available

Conversation

@AsterZ99

Copy link
Copy Markdown

Summary

Improves the reliability of scheduled tasks that are created via WindowsScheduleManager (used by OK-WW's "Task Schedule" tab).

When a scheduled task is set with StartWhenAvailable=false (the current default injected into the task XML), Windows skips the run entirely if the machine is asleep or powered off at the scheduled time. For daily tasks like "run the farm routine every morning", this is the main reason a task is silently missed the next day even though the schedule is registered and "ready".

This PR flips the generated XML setting to <StartWhenAvailable>true</StartWhenAvailable>, so a missed trigger (e.g., the PC was asleep at the trigger time) is executed once the machine becomes available again.

Why this is separate from the "manual refresh" symptom

Opening the Schedule tab already triggers a force_sync (ScheduleTaskTab.load_taskson_refreshquery_all_tasks(force_sync=True)) that re-reads the OS. The OS-level trigger is independent of that UI cache, so a registered and enabled task WILL still fire the next day — the refresh only affects what the UI displays. The real reliability gap is the power-state skip, which this PR addresses.

Test plan

  • Local python -m py_compile on ok/util/windows_schedule.py passes.
  • Manual: create a daily scheduled task, verify the generated \Task\Settings\StartWhenAvailable element is true (e.g. via schtasks /Query /XML).

@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant