Revision ca6bb3d5

b/templates/poller.js
11 11
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 12
// License for the specific language governing permissions and limitations
13 13
// under the License.
14

  
14
var xhrlp = '';
15 15
$(document).ready(function() {
16 16
    if (!window.console) window.console = {};
17 17
    if (!window.console.log) window.console.log = function() {};
......
29 29
    $("#message").select();
30 30
    {% if user.is_authenticated %}
31 31
    updater.start();
32
    updater.poll();
32
    updater.keepalive();
33
    
33 34
    {% endif %}
34 35
});
35 36

  
37

  
38

  
36 39
function newMessage(form) {
37 40
    var message = form.formToDict();
38 41
    var disabled = form.find("input[type=submit]");
......
89 92
var updater = {
90 93
    errorSleepTime: 500,
91 94
    cursor: null,
95
    xhrlp: null,
96
    
97
    keepalive: function (){
98
	try {
99
		updater.xhrlp.abort();
100
	}
101
	catch (e) {	 
102
	}
103
	updater.poll();
104
	if (updater.errorSleepTime == 500){
105
		window.setTimeout(updater.keepalive, 180000);
106
	}
107
//	if (updater.errorSleepTime > 60000){
108
//		window.setTimeout('location.reload()', 3000);
109
//		}
110
	},
92 111
    
93 112
    start: function() {
94
    	$.ajax({url: "{% url fetch-existing %}", type: "POST", dataType: "text",
113
		$.ajax({url: "{% url fetch-existing %}", type: "POST", dataType: "text",
95 114
    		success: updater.onFetchExisting,
96 115
    		error: updater.onError});
97 116
        },
98 117
    
99 118
    poll: function() {
100
	{% if user.is_authenticated %}
101
	$.ajax({url: "{% url fetch-updates %}", type: "POST", dataType: "text",
102
		success: updater.onSuccess,
103
		error: updater.onError});
104
	{% endif %}
119
    	{% if user.is_authenticated %}
120
    	if (updater.errorSleepTime > 60000){
121
    		window.setTimeout('location.reload()', 1000);
122
    		}
123
    	updater.xhrlp=$.ajax({url: "{% url fetch-updates %}", type: "POST", dataType: "text",
124
    		success: updater.onSuccess,
125
    		error: updater.onError});
126
    	{% endif %}
105 127
    },
106

  
107 128
    onSuccess: function(response) {
108 129
	try {
109 130
	    updater.newMessages(eval("(" + response + ")"));
......
124 145
    	}
125 146
        },
126 147
     
127
    onError: function(response) {
128
	updater.errorSleepTime *= 2;
129
	console.log("Poll error; sleeping for", updater.errorSleepTime, "ms");
130
	window.setTimeout(updater.poll, updater.errorSleepTime);
148
    onError: function(response, text) {
149
        	if (text != 'abort'){
150
				updater.errorSleepTime *= 2;
151
				console.log("Poll error; sleeping for", updater.errorSleepTime, "ms");
152
				window.setTimeout(updater.keepalive, updater.errorSleepTime);
153
        	}
131 154
    },
132 155

  
133 156
    newMessages: function(response) {
b/utils/proxy.py
38 38
    
39 39
    def fetch_device(self):
40 40
        device = cache.get("device")
41
        logger.info("[CACHE] hit! got device")
41 42
        if device:
42 43
            return device
43 44
        else:
44 45
            device = self.proccess_xml()
45 46
            if device.routing_options:
46
                cache.set("device", device)
47
                cache.set("device", device, 3600)
48
                logger.info("[CACHE] miss, setting device")
47 49
                return device
48 50
            else:
49 51
                return False
......
188 190
                                    logger.info("Successfully committed @ %s" % self.device)
189 191
                                    newconfig = m.get_config(source='running', filter=('subtree',settings.ROUTES_FILTER)).data_xml
190 192
                                    retrieve = Retriever(xml=newconfig)
191
                                    cache.set("device", retrieve.proccess_xml())
193
                                    logger.info("[CACHE] caching device configuration")
194
                                    cache.set("device", retrieve.proccess_xml(), 3600)
192 195
                                    
193 196
                                    if not commit_is_successful:
194 197
                                        raise Exception()

Also available in: Unified diff