Merge lp:~stolowski/unity-scope-home/monitor-networking into lp:unity-scope-home

Proposed by Paweł Stołowski
Status: Merged
Approved by: Michal Hruby
Approved revision: 94
Merged at revision: 92
Proposed branch: lp:~stolowski/unity-scope-home/monitor-networking
Merge into: lp:unity-scope-home
Diff against target: 91 lines (+51/-4)
1 file modified
src/scope.vala (+51/-4)
To merge this branch: bzr merge lp:~stolowski/unity-scope-home/monitor-networking
Reviewer Review Type Date Requested Status
Michal Hruby (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+159792@code.launchpad.net

Commit message

Monitor network availability on failures of remote-scopes query (on startup).

Description of the change

Monitor network availability on failures of remote-scopes query (on startup).
Set flush delay / category reorder time to 1,5s.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michal Hruby (mhr3) wrote :

8 +const int REMOTE_SCOPES_RETRY_INTERVAL_MAX_SECS = 60; //will retry after that many seconds tops

I think 600 would make more sense.

66 + request_remote_scopes_retry ();

Wouldn't it be better to start a tiny timer instead of trying right away?

94. By Paweł Stołowski

Increased max retry interval for remote-scopes query to 600 secs.
When network becomes avaiable, re-try the query after a small delay.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michal Hruby (mhr3) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/scope.vala'
--- src/scope.vala 2013-04-17 10:08:07 +0000
+++ src/scope.vala 2013-04-19 16:06:39 +0000
@@ -26,11 +26,12 @@
26const int METRICS_SEND_INTERVAL_SECS = 600;26const int METRICS_SEND_INTERVAL_SECS = 600;
27const int METRICS_MIN_NUM_EVENTS = 10;27const int METRICS_MIN_NUM_EVENTS = 10;
28const int REMOTE_SCOPES_INITIAL_RETRY_INTERVAL_SECS = 2; //initial one, it will get increased with each retry28const int REMOTE_SCOPES_INITIAL_RETRY_INTERVAL_SECS = 2; //initial one, it will get increased with each retry
29const int REMOTE_SCOPES_RETRY_INTERVAL_MAX_SECS = 600; //will retry after that many seconds tops
29const uint SMART_SCOPES_RECOMMENDATIONS_CUTOFF = 5; //how many of the recommended scopes should be taken into account30const uint SMART_SCOPES_RECOMMENDATIONS_CUTOFF = 5; //how many of the recommended scopes should be taken into account
30const int SMART_SCOPES_QUERY_MIN_DELAY_MS = 50;31const int SMART_SCOPES_QUERY_MIN_DELAY_MS = 50;
31const int SMART_SCOPES_QUERY_MAX_DELAY_MS = 100;32const int SMART_SCOPES_QUERY_MAX_DELAY_MS = 100;
32const int CATEGORY_REORDER_TIME_MS = 1000;33const int CATEGORY_REORDER_TIME_MS = 1500;
33const uint FLUSH_DELAY_MS = 500;34const uint FLUSH_DELAY_MS = 1500;
34const string[] ALWAYS_REORDER_SCOPE_IDS = {"applications.scope", "files.scope"};35const string[] ALWAYS_REORDER_SCOPE_IDS = {"applications.scope", "files.scope"};
3536
36public class HomeScope : Unity.AggregatorScope37public class HomeScope : Unity.AggregatorScope
@@ -49,6 +50,9 @@
49 private RemoteScopeRegistry remote_scope_registry;50 private RemoteScopeRegistry remote_scope_registry;
50 private uint category_reorder_time_ms = 0; // minimum time after which category reordering can happen (in milliseconds)51 private uint category_reorder_time_ms = 0; // minimum time after which category reordering can happen (in milliseconds)
51 private uint flush_delay_ms = 0; //minimum time after which results will be shown in the dash (in milliseconds)52 private uint flush_delay_ms = 0; //minimum time after which results will be shown in the dash (in milliseconds)
53 private NetworkMonitor? netmon = null;
54 private bool remote_scopes_request_running = false;
55 private ulong netmon_sig_id = 0;
5256
53 public HomeScope ()57 public HomeScope ()
54 {58 {
@@ -184,6 +188,11 @@
184188
185 internal async void request_remote_scopes ()189 internal async void request_remote_scopes ()
186 {190 {
191 if (remote_scopes_request_running || smart_scopes_ready)
192 return;
193
194 remote_scopes_request_running = true;
195
187 SmartScopes.RemoteScopeInfo[]? scopes = null;196 SmartScopes.RemoteScopeInfo[]? scopes = null;
188 // issue a request for remote_scopes list197 // issue a request for remote_scopes list
189 try198 try
@@ -215,11 +224,49 @@
215 {224 {
216 warning ("Failed to get list of remote scopes: %s", e.message);225 warning ("Failed to get list of remote scopes: %s", e.message);
217 }226 }
227 remote_scopes_request_running = false;
218228
219 if (!smart_scopes_ready)229 if (!smart_scopes_ready)
220 {230 {
221 // setup a retry callback231 bool network_available = GLib.NetworkMonitor.get_default ().network_available;
222 GLib.Timeout.add_seconds (REMOTE_SCOPES_INITIAL_RETRY_INTERVAL_SECS * ++remote_scopes_retry_count, request_remote_scopes_retry);232
233 // if network not available, monitor it and re-try when it becomes available
234 if (netmon == null && !network_available)
235 {
236 debug ("Network not available, creating netmon");
237
238 netmon = GLib.NetworkMonitor.get_default ();
239 netmon_sig_id = netmon.network_changed.connect ((available) =>
240 {
241 // note: we get network_changed notification multiple times,
242 // remote_scopes_request_running ensures we retry once at a time.
243 if (available && !smart_scopes_ready && !remote_scopes_request_running)
244 {
245 remote_scopes_retry_count = 0;
246 // just retry after small initial delay (don't multiply by num of failures)
247 GLib.Timeout.add_seconds (REMOTE_SCOPES_INITIAL_RETRY_INTERVAL_SECS, request_remote_scopes_retry);
248 }
249 });
250 }
251
252 // network considered available but for some reason remote-scopes query failed - setup a retry after timeout
253 if (network_available)
254 {
255 var retry_delay = int.min (REMOTE_SCOPES_INITIAL_RETRY_INTERVAL_SECS * ++remote_scopes_retry_count,
256 REMOTE_SCOPES_RETRY_INTERVAL_MAX_SECS);
257 debug ("Network is available, will retry in %d secs", retry_delay);
258 GLib.Timeout.add_seconds (retry_delay, request_remote_scopes_retry);
259 }
260 }
261 else
262 {
263 // once we got remote-scopes, disconnect and remove netmon
264 if (netmon != null)
265 {
266 SignalHandler.disconnect (netmon, netmon_sig_id);
267 netmon = null;
268 netmon_sig_id = 0;
269 }
223 }270 }
224 }271 }
225272

Subscribers

People subscribed via source and target branches

to all changes: