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
1=== modified file 'src/scope.vala'
2--- src/scope.vala 2013-04-17 10:08:07 +0000
3+++ src/scope.vala 2013-04-19 16:06:39 +0000
4@@ -26,11 +26,12 @@
5 const int METRICS_SEND_INTERVAL_SECS = 600;
6 const int METRICS_MIN_NUM_EVENTS = 10;
7 const int REMOTE_SCOPES_INITIAL_RETRY_INTERVAL_SECS = 2; //initial one, it will get increased with each retry
8+const int REMOTE_SCOPES_RETRY_INTERVAL_MAX_SECS = 600; //will retry after that many seconds tops
9 const uint SMART_SCOPES_RECOMMENDATIONS_CUTOFF = 5; //how many of the recommended scopes should be taken into account
10 const int SMART_SCOPES_QUERY_MIN_DELAY_MS = 50;
11 const int SMART_SCOPES_QUERY_MAX_DELAY_MS = 100;
12-const int CATEGORY_REORDER_TIME_MS = 1000;
13-const uint FLUSH_DELAY_MS = 500;
14+const int CATEGORY_REORDER_TIME_MS = 1500;
15+const uint FLUSH_DELAY_MS = 1500;
16 const string[] ALWAYS_REORDER_SCOPE_IDS = {"applications.scope", "files.scope"};
17
18 public class HomeScope : Unity.AggregatorScope
19@@ -49,6 +50,9 @@
20 private RemoteScopeRegistry remote_scope_registry;
21 private uint category_reorder_time_ms = 0; // minimum time after which category reordering can happen (in milliseconds)
22 private uint flush_delay_ms = 0; //minimum time after which results will be shown in the dash (in milliseconds)
23+ private NetworkMonitor? netmon = null;
24+ private bool remote_scopes_request_running = false;
25+ private ulong netmon_sig_id = 0;
26
27 public HomeScope ()
28 {
29@@ -184,6 +188,11 @@
30
31 internal async void request_remote_scopes ()
32 {
33+ if (remote_scopes_request_running || smart_scopes_ready)
34+ return;
35+
36+ remote_scopes_request_running = true;
37+
38 SmartScopes.RemoteScopeInfo[]? scopes = null;
39 // issue a request for remote_scopes list
40 try
41@@ -215,11 +224,49 @@
42 {
43 warning ("Failed to get list of remote scopes: %s", e.message);
44 }
45+ remote_scopes_request_running = false;
46
47 if (!smart_scopes_ready)
48 {
49- // setup a retry callback
50- GLib.Timeout.add_seconds (REMOTE_SCOPES_INITIAL_RETRY_INTERVAL_SECS * ++remote_scopes_retry_count, request_remote_scopes_retry);
51+ bool network_available = GLib.NetworkMonitor.get_default ().network_available;
52+
53+ // if network not available, monitor it and re-try when it becomes available
54+ if (netmon == null && !network_available)
55+ {
56+ debug ("Network not available, creating netmon");
57+
58+ netmon = GLib.NetworkMonitor.get_default ();
59+ netmon_sig_id = netmon.network_changed.connect ((available) =>
60+ {
61+ // note: we get network_changed notification multiple times,
62+ // remote_scopes_request_running ensures we retry once at a time.
63+ if (available && !smart_scopes_ready && !remote_scopes_request_running)
64+ {
65+ remote_scopes_retry_count = 0;
66+ // just retry after small initial delay (don't multiply by num of failures)
67+ GLib.Timeout.add_seconds (REMOTE_SCOPES_INITIAL_RETRY_INTERVAL_SECS, request_remote_scopes_retry);
68+ }
69+ });
70+ }
71+
72+ // network considered available but for some reason remote-scopes query failed - setup a retry after timeout
73+ if (network_available)
74+ {
75+ var retry_delay = int.min (REMOTE_SCOPES_INITIAL_RETRY_INTERVAL_SECS * ++remote_scopes_retry_count,
76+ REMOTE_SCOPES_RETRY_INTERVAL_MAX_SECS);
77+ debug ("Network is available, will retry in %d secs", retry_delay);
78+ GLib.Timeout.add_seconds (retry_delay, request_remote_scopes_retry);
79+ }
80+ }
81+ else
82+ {
83+ // once we got remote-scopes, disconnect and remove netmon
84+ if (netmon != null)
85+ {
86+ SignalHandler.disconnect (netmon, netmon_sig_id);
87+ netmon = null;
88+ netmon_sig_id = 0;
89+ }
90 }
91 }
92

Subscribers

People subscribed via source and target branches

to all changes: