complete job queue delete and kill running timers properly when reloading page

This commit is contained in:
Oliver Gorwits
2013-05-11 18:25:04 +01:00
parent dd6947f38d
commit 74bc0023df
7 changed files with 47 additions and 24 deletions

View File

@@ -4,10 +4,13 @@
* Finally we have a discover/refresh daemon job :)
* Also... a Scheduler which removes need for crontab installation
* The netdisco-do script can run any one-off job
* The netdisco-do script can queue any one-off job
* Select MAC Address display format on Node and Device Port search
* Helper script to import the Netdisco 1.x Topology file to the database
* Support for pseudo devices (useful for dummy device links)
* Manual Topology editing via the web
* Job Queue view and delete page
* Empty device table prompts initial discover on homepage
[ENHANCEMENTS]

View File

@@ -11,6 +11,16 @@ register_admin_task({
label => 'Job Queue',
});
ajax '/ajax/control/admin/jobqueue/del' => sub {
return unless var('user') and var('user')->admin;
return unless length param('job');
schema('netdisco')->txn_do(sub {
my $device = schema('netdisco')->resultset('Admin')
->search({job => param('job')})->delete;
});
};
ajax '/ajax/content/admin/jobqueue' => sub {
return unless var('user') and var('user')->admin;

View File

@@ -28,7 +28,7 @@ sub _sanity_ok {
return 1;
}
ajax '/ajax/content/admin/pseudodevice/add' => sub {
ajax '/ajax/control/admin/pseudodevice/add' => sub {
return unless _sanity_ok();
schema('netdisco')->txn_do(sub {
@@ -48,7 +48,7 @@ ajax '/ajax/content/admin/pseudodevice/add' => sub {
});
};
ajax '/ajax/content/admin/pseudodevice/del' => sub {
ajax '/ajax/control/admin/pseudodevice/del' => sub {
return unless _sanity_ok();
schema('netdisco')->txn_do(sub {
@@ -60,7 +60,7 @@ ajax '/ajax/content/admin/pseudodevice/del' => sub {
});
};
ajax '/ajax/content/admin/pseudodevice/update' => sub {
ajax '/ajax/control/admin/pseudodevice/update' => sub {
return unless _sanity_ok();
schema('netdisco')->txn_do(sub {

View File

@@ -27,7 +27,7 @@ sub _sanity_ok {
return 1;
}
ajax '/ajax/content/admin/topology/add' => sub {
ajax '/ajax/control/admin/topology/add' => sub {
return unless _sanity_ok();
my $device = schema('netdisco')->resultset('Topology')
@@ -39,7 +39,7 @@ ajax '/ajax/content/admin/topology/add' => sub {
});
};
ajax '/ajax/content/admin/topology/del' => sub {
ajax '/ajax/control/admin/topology/del' => sub {
return unless _sanity_ok();
schema('netdisco')->txn_do(sub {

View File

@@ -1,4 +1,4 @@
<table class="table table-bordered table-condensed">
<table class="table table-bordered table-condensed table-hover">
<thead>
<tr>
<th class="nd_center-cell">Entered</th>

View File

@@ -2,6 +2,9 @@
// ajax content is loaded
var path = 'admin';
// keep track of timers so we can kill them
var nd_timers = new Array();
// this is called by do_search to support local code
// which might need to act on the newly inserted content
// but which cannot use jQuery delegation via .on()
@@ -10,18 +13,23 @@
// reload this table every 10 seconds
if (tab == 'jobqueue') {
$('#nd_device-name').text('10');
setTimeout(function() { $('#nd_device-name').text('9') }, 1000 );
setTimeout(function() { $('#nd_device-name').text('8') }, 2000 );
setTimeout(function() { $('#nd_device-name').text('7') }, 3000 );
setTimeout(function() { $('#nd_device-name').text('6') }, 4000 );
setTimeout(function() { $('#nd_device-name').text('5') }, 5000 );
setTimeout(function() { $('#nd_device-name').text('4') }, 6000 );
setTimeout(function() { $('#nd_device-name').text('3') }, 7000 );
setTimeout(function() { $('#nd_device-name').text('2') }, 8000 );
setTimeout(function() { $('#nd_device-name').text('1') }, 9000 );
setTimeout(function() {
nd_timers.push(setTimeout(function() { $('#nd_device-name').text('9') }, 1000 ));
nd_timers.push(setTimeout(function() { $('#nd_device-name').text('8') }, 2000 ));
nd_timers.push(setTimeout(function() { $('#nd_device-name').text('7') }, 3000 ));
nd_timers.push(setTimeout(function() { $('#nd_device-name').text('6') }, 4000 ));
nd_timers.push(setTimeout(function() { $('#nd_device-name').text('5') }, 5000 ));
nd_timers.push(setTimeout(function() { $('#nd_device-name').text('4') }, 6000 ));
nd_timers.push(setTimeout(function() { $('#nd_device-name').text('3') }, 7000 ));
nd_timers.push(setTimeout(function() { $('#nd_device-name').text('2') }, 8000 ));
nd_timers.push(setTimeout(function() { $('#nd_device-name').text('1') }, 9000 ));
nd_timers.push(setTimeout(function() {
// clear any running timers
for (var i = 0; i < nd_timers.length; i++) {
clearTimeout(nd_timers[i]);
}
// reload the tab content
$('#' + tab + '_form').trigger('submit');
}, 10000);
}, 10000));
}
// activate typeahead on the topo boxes
@@ -79,16 +87,21 @@
// stop form from submitting normally
event.preventDefault();
// clear any running timers
for (var i = 0; i < nd_timers.length; i++) {
clearTimeout(nd_timers[i]);
}
// submit the query and put results into the tab pane
$.ajax({
type: 'POST'
,async: true
,dataType: 'html'
,url: uri_base + '/ajax/content/admin/' + tab + '/' + $(this).attr('name')
,url: uri_base + '/ajax/control/admin/' + tab + '/' + $(this).attr('name')
,data: $(this).serializeArray()
,beforeSend: function() {
$(target).html(
'<div class="span2 alert">Waiting for results...</div>'
'<div class="span2 alert">Request submitted...</div>'
);
}
,success: function(content) {
@@ -97,7 +110,7 @@
,error: function() {
$(target).html(
'<div class="span5 alert alert-error">' +
'Update failed! Please contact your site administrator.</div>'
'Request failed! Please contact your site administrator.</div>'
);
}
});

3
TODO
View File

@@ -1,7 +1,6 @@
FRONTEND
========
* view logs with colour
* moar reports
* (jeneric) device module tab
@@ -9,8 +8,6 @@ FRONTEND
BACKEND
=======
* Job Delete handler
DAEMON
======