Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EdgeAgent: Change twin refresh timer logic to loop #799

Merged
merged 13 commits into from
Feb 13, 2019

Conversation

varunpuranik
Copy link
Contributor

The logic in Edge agent to refresh its twin periodically was based on a timer, and seemed to not work in some customer scenarios. So converting the logic to be loop based, with additional checks to make sure it works as expected at all times.

philipktlin
philipktlin previously approved these changes Feb 4, 2019
@@ -64,8 +64,7 @@ public class EdgeAgentConnection : IEdgeAgentConnection
this.reportedProperties = Option.None<TwinCollection>();
this.deviceClient = Option.None<IModuleClient>();
this.retryStrategy = Preconditions.CheckNotNull(retryStrategy, nameof(retryStrategy));
this.refreshTimer = new Timer(refreshConfigFrequency.TotalMilliseconds);
this.refreshTimer.Elapsed += (_, __) => this.RefreshTimerElapsed();
this.refreshTwinTask = new PeriodicTask(this.RefreshTwinAsync, refreshConfigFrequency, refreshConfigFrequency, Events.Log, "refresh twin config");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.RefreshTwinAsync can be called from this PeriodicTask, CreateAndInitDeviceClient, OnConnectionStatusChanged, and OnDesiredPropertiesUpdated. First periodic task doesn't call twinLock.LockAsync before calling RefreshTwinAsync; may move twinLock.LockAsync statement inside RefreshTwinAsync method.

Besides that I concern this may run too often in some cases, for example if it triggered by OnDesiredPropertiesUpdated, and then periodictask also trigger right after; I would suggest to reset timer inside periodictask after RefreshTwinAsync called.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, we had the reset logic earlier... but it is non-trivial to do it with a loop and I wanted to avoid the complexity that comes with it. This also makes it easier to track logs to see if the periodic task is working properly.

@varunpuranik varunpuranik merged commit cb7af40 into master Feb 13, 2019
@myagley myagley deleted the varunpuranik/eaLoop branch April 12, 2019 19:47
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.

3 participants