Commit 9083228c authored by Alain Takoudjou's avatar Alain Takoudjou

slapos_monitoring: correctly manage jio_storage on sync, prevent start of two sync at same time

parent 5ef80d01
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
gadget_klass gadget_klass
.ready(function (g) { .ready(function (g) {
g.props = {}; g.props = {};
g.props.jio_storage_dict = {};
return g.getDeclaredGadget('jio_gadget') return g.getDeclaredGadget('jio_gadget')
.push(function (jio_gadget) { .push(function (jio_gadget) {
g.props.jio_gadget = jio_gadget; g.props.jio_gadget = jio_gadget;
...@@ -67,9 +68,36 @@ ...@@ -67,9 +68,36 @@
return error_message; return error_message;
} }
function getJioGadget(gadget, hash) {
return new RSVP.Queue()
.push(function () {
if (gadget.props.jio_storage_dict.hasOwnProperty(hash)) {
return gadget.props.jio_storage_dict[hash];
} else {
return gadget.declareGadget("gadget_monitoring_jio.html",
{
scope: hash
}
)
.push(function (jio_declared_gadget) {
gadget.props.jio_storage_dict[hash] = jio_declared_gadget;
return jio_declared_gadget;
});
}
});
}
function syncStorage(gadget, storage_dict, query) { function syncStorage(gadget, storage_dict, query) {
gadget.props.jio_gadget.createJio(storage_dict, true, query); var hash;
return gadget.props.jio_gadget.repair() //gadget.props.jio_gadget.createJio(storage_dict, true, query);
hash = rusha.digestFromString(storage_dict.title.replace(/\s*/g, "") +
'_' + storage_dict.sub_storage.type);
return getJioGadget(gadget, hash)
.push(function (jio_declared_gadget) {
jio_declared_gadget.createJio(storage_dict, true, query);
return jio_declared_gadget.repair();
})
.push(undefined, function (error) { .push(undefined, function (error) {
gadget.props.error_list.push({ gadget.props.error_list.push({
storage_dict: storage_dict, storage_dict: storage_dict,
...@@ -82,8 +110,12 @@ ...@@ -82,8 +110,12 @@
function updateStatus(gadget, storage_dict, status) { function updateStatus(gadget, storage_dict, status) {
var promise_list = [], var promise_list = [],
jio_gadget, jio_gadget,
hash,
i; i;
return gadget.declareGadget("gadget_monitoring_jio.html") hash = rusha.digestFromString(storage_dict.title.replace(/\s*/g, "") +
'_' + storage_dict.sub_storage.type);
return getJioGadget(gadget, hash)
.push(function (jio_declared_gadget) { .push(function (jio_declared_gadget) {
jio_gadget = jio_declared_gadget; jio_gadget = jio_declared_gadget;
jio_gadget.createJio(storage_dict); jio_gadget.createJio(storage_dict);
...@@ -210,9 +242,7 @@ ...@@ -210,9 +242,7 @@
last_sync_time; last_sync_time;
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
if (options.now) { return gadget.setSetting('sync_start_time', new Date().getTime());
return gadget.setSetting('manual_sync_time', new Date().getTime());
}
}) })
.push(function () { .push(function () {
$(".notifyjs-wrapper").remove(); $(".notifyjs-wrapper").remove();
...@@ -226,6 +256,7 @@ ...@@ -226,6 +256,7 @@
); );
}) })
.push(function () { .push(function () {
// Get all configured credentials
return gadget.props.login_gadget.getUrlDict(); return gadget.props.login_gadget.getUrlDict();
}) })
.push(undefined, function () { .push(undefined, function () {
...@@ -270,6 +301,10 @@ ...@@ -270,6 +301,10 @@
console.log("Sync monitoring data..."); console.log("Sync monitoring data...");
return RSVP.all(promise_list); return RSVP.all(promise_list);
}) })
.push(undefined, function (error) {
console.log(error);
return;
})
.push(function () { .push(function () {
// Check if there was errors and retry them if possible // Check if there was errors and retry them if possible
var error_size = gadget.props.error_list.length, var error_size = gadget.props.error_list.length,
...@@ -298,6 +333,10 @@ ...@@ -298,6 +333,10 @@
} }
return RSVP.all(promise_list); return RSVP.all(promise_list);
}) })
.push(undefined, function (error) {
console.log(error);
return;
})
.push(function () { .push(function () {
last_sync_time = new Date().getTime(); last_sync_time = new Date().getTime();
return gadget.setSetting('latest_sync_time', last_sync_time); return gadget.setSetting('latest_sync_time', last_sync_time);
...@@ -367,13 +406,13 @@ ...@@ -367,13 +406,13 @@
gadget.props.timer = setTimeout(function(){ gadget.props.timer = setTimeout(function(){
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return gadget.getSetting('manual_sync_time'); return gadget.getSetting('sync_start_time');
}) })
.push(function (manual_timestamp) { .push(function (start_timestamp) {
var current_time = new Date().getTime(); var current_time = new Date().getTime();
if (manual_timestamp !== undefined && if (start_timestamp !== undefined &&
current_time - gadget.props.timer_interval <= manual_timestamp) { current_time - gadget.props.timer_interval <= start_timestamp) {
// There was a manual sync don't start a new sync again! // There was a recent sync don't start a new sync before the time_interval!
return; return;
} }
return syncAllStorage(); return syncAllStorage();
......
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>952.63467.50835.57446</string> </value> <value> <string>953.32835.32275.40806</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -260,7 +260,7 @@ ...@@ -260,7 +260,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1470152500.12</float> <float>1472247230.79</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </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