Skip to content

Intune Scheduled Syncs PR Review

Ed Mozley edited this page Nov 14, 2026 · 1 revision

Intune syncs on its own, as scheduled jobs - PR review

PR #344 by vsc55 Β· Closes #342 Β· Built on #340 and so #339 and #338 Β· Verdict: merge, with fixes Β· 5.3.0

Both Intune syncs ran only when somebody pressed Sync or Sync software on Assets β†’ Settings β†’ Intune - and Sync software reads one batch per press, so a large estate meant pressing it again and again. They are now two jobs of the built-in scheduler, each with its own schedule in Background jobs: Intune device sync (intune_sync, every 6 hours) runs the same device sync as the button - linking, types, primary users and the changes it follows - and Intune software sync (intune_app_sync, daily) reads batch after batch until every eligible device has been read once. User page: Assets. Internals: Background jobs - Developer Guide Β§9.

What was checked

Question Result
Is it the same sync as the button? Yes - cron/intune_sync.php calls intuneRunSync() and writes the same intune_sync_jobs row, so the settings tab shows a scheduled run like any other
Can the button and the schedule both start a device sync? Not after the merge - the claim is one step under a MySQL named lock (fix 1)
Can a dead sync block every later one? Not after the merge - dead rows are failed before the check, with times that cannot fail a live sync (fixes 1 and 3)
Is a run that did nothing recorded as one that worked? Not after the merge - turned away is skipped, some devices failing among others is partial (fixes 2 and 3)
Not set up, or Assets switched off? Not needed and not started; the scripts also record a skip and stop if run by hand
Does the software sync keep taking the same devices? Not after the merge - candidates are ordered by the last attempt, and a run never takes a device twice (fix 3)
How long can the software sync run? It starts batches for 45 minutes (INTUNE_APP_SYNC_BUDGET); a batch already started finishes; the next run carries on with the devices tried longest ago

On the test install: the new tests/intune-sync-jobs.php (14 checks, Graph never called - a stand-in writes what a real batch would); vsc55 also reported tests/job-scheduler.php 38/38 and tests/job-health.php 35/35, and ran both jobs for real with Intune not set up (both skipped) and with bad credentials (the device sync failed with Graph's refusal, the software sync counted each device as failed).

What was changed on merge

  1. The device sync claim (intuneClaimDeviceSyncJob(), shared by the button and the job) is one step under GET_LOCK: without it the button and the schedule, a moment apart, could both see nothing running and both start. A dead row is failed after 10 minutes with nothing processed (the PR said 2, which could fail a live sync still fetching its token and first page) or after 60 minutes whatever it processed.
  2. The scheduled device sync claims before it records a run. Turned away by a sync started from the tab, it records skipped; when some devices were written and some failed it records partial, and failed when none could be.
  3. The software sync. A dead batch is failed before the "one at a time" check (and any batch over 150 minutes old), so one stuck batch no longer turns every later run away. Candidates are ordered by the last attempt, not the last success, so devices with no apps, deleted in Intune or erroring no longer take every batch; a run never takes a device twice (new index ix_intune_app_sync_job_assets_asset). A batch already running makes the run skipped, a batch that fails as a whole makes it failed with the reason, some devices failing among others read makes it partial. The loop moved into intuneScheduledAppSync() so it can be tested; intuneRunSync() now returns its counts.
  4. Needed only once Intune is really set up - a tenant, a client id and a client secret (jobIntuneConfigured()), what intuneGetSettings() needs before it runs.
  5. The settings tab leaves skipped runs out of "last ran", and says the Sync buttons are not counted and the syncs run on their own once the scheduler is running.
  6. Code comments said #2896 (a changelog number taken since); they say #342.
  7. Tests: new tests/intune-sync-jobs.php, 14 checks.
  8. Changelog ids renumbered to #2933 (the feature) and #2934 (the merge fixes).
  9. Translations of the new strings into the eight maintained languages; this write-up, the user pages, the developer guide and vsc55's entry on the Contributors page.

Decided

  • Approved as designed on #342: two jobs, so each has its own schedule - devices are cheap, software is one Graph call per device (Ed, 2026-11-14).
  • The Intune tab says when each job last ran, and how it went - asked for on #342 and added by vsc55 before review (intuneJobsLastRun()) (Ed, 2026-11-14).

Worth knowing

  • Run Database Verification after upgrading. It adds the index ix_intune_app_sync_job_assets_asset (asset_id, job_id), which the software sync's candidate query uses to find each device's last attempt. Without it the query still works, only slower on a large estate.
  • Button syncs are not in the run history. Sync and Sync software on the tab write their own job rows (intune_sync_jobs, intune_app_sync_jobs) but not job_runs, so they do not count towards the jobs' health or the "last ran" line - only the schedule and Run now do.
  • On an upgraded install the jobs start once the scheduler sees them as needed. Nothing has to be added to cron: cron/run.php picks new registry jobs up by itself.
  • The software sync still skips devices whose software the inventory agent reports, as the button does.

FreeITSM

Getting Started

Modules

Multi-tenancy (planned)

Responses to feedback

Blue sky thinking

Bugs resolved

Pull requests

Links

Clone this wiki locally