Commit 6ce6743c authored by Alain Takoudjou's avatar Alain Takoudjou

[erp5_web_monitoring] Fix concurence problem on destroy OPML while sync is...

[erp5_web_monitoring] Fix concurence problem on destroy OPML while sync is running or start just after

If Sync start in background and destroy OPML is launched, some data can be removed while sync is writing. So we prevent sync to run if destroy OPML is running and also, we refuse to destroy OPML if sync is running.
parent d8c5e5d2
......@@ -5,6 +5,8 @@
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>ERP5 Page Monitoring Settings Configurator</title>
<link href="gadget_officejs_monitoring_custom.css" rel="stylesheet" type="text/css"/>
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
......
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.8904.14589.19234</string> </value>
<value> <string>963.27666.8050.30907</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1509441500.96</float>
<float>1515055044.86</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -60,6 +60,8 @@
.onEvent('click', function (event) {
var gadget = this,
sync_start_time,
success = true,
element = gadget.element.querySelector("#destroyOPML");
function removeAllOPML(result) {
......@@ -96,23 +98,57 @@
return gadget.notifySubmitting()
.push(function () {
return gadget.getSetting('sync_start_time');
})
.push(function (start_time) {
sync_start_time = start_time;
return gadget.getSetting('latest_sync_time');
})
.push(function (finish_time) {
if (finish_time - sync_start_time < 0) {
// sync is running, cannot remove OPML now
success = false;
return RSVP.all([
gadget.notifySubmitted({
message: 'Cannot destroy now, please wait until background ' +
'sync is finished',
status: 'error'
})
]);
}
element.setAttribute("disabled", "disabled");
return gadget.jio_allDocs({
query: 'portal_type: "opml"',
select_list: ['title']
});
})
.push(function (result) {
return removeAllOPML(result);
return RSVP.all([
gadget.setSetting('sync_lock', true),
removeAllOPML(result)
]);
})
.push(function () {
return RSVP.all([
gadget.notifySubmitted({message: 'All OPML removed', status: 'success'})
gadget.setSetting('sync_lock', false),
gadget.notifySubmitted({
message: 'All OPML removed',
status: 'success'
})
]);
}, function () {
success = false;
return gadget.setSetting('sync_lock', false);
});
})
.push(function () {
element.textContent = element.textContent.slice(10, element.textContent.length);
element.textContent = element.textContent.slice(
10,
element.textContent.length
);
element.setAttribute('rel', '');
if (success) {
return gadget.redirect({"command": "reload"});
}
});
}
}, false, false)
......
......@@ -238,7 +238,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.21245.1149.59784</string> </value>
<value> <string>964.38401.39195.47086</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -256,7 +256,7 @@
</tuple>
<state>
<tuple>
<float>1510216637.34</float>
<float>1515059069.3</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -150,15 +150,28 @@
// There was another recent sync don't start a new sync before the time_interval!
return;
}
return gadget.getSetting('sync_lock')
.push(function (sync_lock) {
if (!sync_lock) {
gadget.props.sync_locked = false;
return syncAllStorageWithCheck();
}
gadget.props.sync_locked = true;
return gadget.notifySubmitted({
message: "Auto sync is currently locked by another task " +
"and will be restarted later...",
status: "error"
});
});
})
.push(function () {
return gadget.getSetting('sync_data_interval');
})
.push(function (timer_interval) {
if (gadget.props.offline === true) {
// Offline mode detected, next check will be in 3 minutes
timer_interval = 180000;
if (gadget.props.offline === true ||
gadget.props.sync_locked === true) {
// Offline mode detected or sync locked. Next run in 1 minute
timer_interval = 60000;
} else if (timer_interval === undefined) {
timer_interval = gadget.props.default_sync_interval;
}
......
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.29142.15969.45158</string> </value>
<value> <string>964.38426.36779.39065</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1510669949.87</float>
<float>1515058880.82</float>
<string>UTC</string>
</tuple>
</state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment