Skip to content

Commit

Permalink
Merge branch 'add_webhook_support' of https://github.com/Lyncredible/…
Browse files Browse the repository at this point in the history
…onedrive into pr/1626
  • Loading branch information
abraunegg committed Nov 16, 2021
2 parents ed7e87f + 47f2ca8 commit e323928
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions src/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -1111,28 +1111,31 @@ int main(string[] args)
}
}

// Create a subscription on the first run, or renew the subscription
// on subsequent runs when it is about to expire
// Check for notifications pushed from Microsoft to the webhook
bool notificationReceived = false;
if (webhookEnabled) {
// Create a subscription on the first run, or renew the subscription
// on subsequent runs when it is about to expire.
oneDrive.createOrRenewSubscription();
}

// Empirical evidence shows that Microsoft often sends multiple
// notifications for one single change, so we need a loop to exhaust
// all signals that were queued up by the webhook. The notifications
// do not contain any actual changes, and we will always rely do the
// delta endpoint to sync to latest. Therefore, only one sync run is
// good enough to catch up for multiple notifications.
bool notificationReceived = false;
for (int signalCount = 0;; signalCount++) {
const auto signalExists = receiveTimeout(dur!"seconds"(-1), (ulong _) => {});
if (signalExists) {
notificationReceived = true;
} else {
if (notificationReceived) {
log.log("Received ", signalCount," refresh signals from the webhook");
// Process incoming notifications if any.

// Empirical evidence shows that Microsoft often sends multiple
// notifications for one single change, so we need a loop to exhaust
// all signals that were queued up by the webhook. The notifications
// do not contain any actual changes, and we will always rely do the
// delta endpoint to sync to latest. Therefore, only one sync run is
// good enough to catch up for multiple notifications.
for (int signalCount = 0;; signalCount++) {
const auto signalExists = receiveTimeout(dur!"seconds"(-1), (ulong _) => {});
if (signalExists) {
notificationReceived = true;
} else {
if (notificationReceived) {
log.log("Received ", signalCount," refresh signals from the webhook");
}
break;
}
break;
}
}

Expand Down

0 comments on commit e323928

Please sign in to comment.