NEW: Fixing queuedjob status and hiding report button when report is running

This commit is contained in:
Kirk Mayo 2014-08-04 10:10:59 +12:00
parent e9fe1a4707
commit 9e5a41f6c7
3 changed files with 23 additions and 8 deletions

View File

@ -25,7 +25,14 @@ class CheckExternalLinksJob extends AbstractQueuedJob implements QueuedJob {
*/
public function process() {
$task = new CheckExternalLinks();
$task->run();
$pages = Versioned::get_by_stage('SiteTree', 'Live');
// set the limit so each page is done individually
$task->limit = 1;
$this->totalSteps = $pages->count();
foreach ($pages as $page) {
$this->currentStep++;
$task->run();
}
$this->isComplete = true;
return;
}

View File

@ -1,7 +1,8 @@
<?php
class CheckExternalLinks extends BuildTask {
public static $pageToProcess;
public $limit = 10;
protected $title = 'Checking broken External links in the SiteTree';
protected $description = 'A task that records external broken links in the SiteTree';
@ -20,10 +21,10 @@ class CheckExternalLinks extends BuildTask {
->filter(array(
'TrackID' => $track->ID,
'Processed' => 0
))->limit(10)->column('PageID');
))->limit($this->limit)->column('PageID');
$pages = Versioned::get_by_stage('SiteTree', 'Live')
->filter('ID', $batch)
->limit(10);
->limit($this->limit);
$this->updateJobInfo('Fetching pages to check');
if ($track->CompletedPages == $track->TotalPages) {
$track->Status = 'Completed';
@ -50,7 +51,7 @@ class CheckExternalLinks extends BuildTask {
$batch = BrokenExternalPageTrack::get()
->filter(array(
'TrackID' => $track->ID
))->limit(10)->column('PageID');
))->limit($this->limit)->column('PageID');
$pages = Versioned::get_by_stage('SiteTree', 'Live')
->filter('ID', $batch);
@ -159,8 +160,13 @@ class CheckExternalLinks extends BuildTask {
$row->delete();
}
} else {
$this->updateJobInfo("Running next batch {$track->CompletedPages}/{$track->TotalPages}");
$this->run($request);
// if running via the queued job module return to the queued job after each iteration
if ($this->limit == 1) {
return;
} else {
$this->updateJobInfo("Running next batch {$track->CompletedPages}/{$track->TotalPages}");
$this->run($request);
}
}
// run this again if queued jobs exists and is a valid int

View File

@ -2,7 +2,6 @@
$('#externalLinksReport').entwine({
onclick: function() {
$(this).start();
$(this).poll();
},
onmatch: function() {
$(this).poll();
@ -12,11 +11,13 @@
$('#ReportHolder').empty();
$('#ReportHolder').text('Running report 0%');
$('#ReportHolder').append('<span class="ss-ui-loading-icon"></span>');
$('#externalLinksReport').hide();
$.ajax({url: "admin/externallinks/start", async: true, timeout: 3000 });
$(this).poll();
},
poll: function() {
// poll the current job and update the front end status
$('#externalLinksReport').hide();
$.ajax({
url: "admin/externallinks/getJobStatus",
async: true,
@ -30,6 +31,7 @@
var jobStatus = obj.Status ? obj.Status : 'Running';
if (jobStatus == 'Completed') {
$('#ReportHolder').text('Report Finished ' + completed + '/' + total);
$('#externalLinksReport').show();
} else {
setTimeout(function() { $('#externalLinksReport').poll(); }, 1000);
}