Make sure that process yields to queuedjobs after each page
Fix javascript errors starting the job
This commit is contained in:
parent
9e5a41f6c7
commit
363ecd4985
|
@ -21,20 +21,14 @@ class CheckExternalLinksJob extends AbstractQueuedJob implements QueuedJob {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check a individual page
|
* Check an individual page
|
||||||
*/
|
*/
|
||||||
public function process() {
|
public function process() {
|
||||||
$task = new CheckExternalLinks();
|
$task = new CheckExternalLinks();
|
||||||
$pages = Versioned::get_by_stage('SiteTree', 'Live');
|
$track = $task->runLinksCheck(1);
|
||||||
// set the limit so each page is done individually
|
$this->currentStep = $track->CompletedPages;
|
||||||
$task->limit = 1;
|
$this->totalSteps = $track->TotalPages;
|
||||||
$this->totalSteps = $pages->count();
|
$this->isComplete = $track->Status === 'Completed';
|
||||||
foreach ($pages as $page) {
|
|
||||||
$this->currentStep++;
|
|
||||||
$task->run();
|
|
||||||
}
|
|
||||||
$this->isComplete = true;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,16 @@ class CheckExternalLinks extends BuildTask {
|
||||||
private $totalPages;
|
private $totalPages;
|
||||||
|
|
||||||
function run($request) {
|
function run($request) {
|
||||||
|
$this->runLinksCheck($this->limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs the links checker and returns the track used
|
||||||
|
*
|
||||||
|
* @param int $limit Limit to number of pages to run
|
||||||
|
* @return BrokenExternalPageTrackStatus
|
||||||
|
*/
|
||||||
|
public function runLinksCheck($limit) {
|
||||||
$track = CheckExternalLinks::getLatestTrack();
|
$track = CheckExternalLinks::getLatestTrack();
|
||||||
|
|
||||||
// if the script has already been started
|
// if the script has already been started
|
||||||
|
@ -21,10 +31,10 @@ class CheckExternalLinks extends BuildTask {
|
||||||
->filter(array(
|
->filter(array(
|
||||||
'TrackID' => $track->ID,
|
'TrackID' => $track->ID,
|
||||||
'Processed' => 0
|
'Processed' => 0
|
||||||
))->limit($this->limit)->column('PageID');
|
))->limit($limit)->column('PageID');
|
||||||
$pages = Versioned::get_by_stage('SiteTree', 'Live')
|
$pages = Versioned::get_by_stage('SiteTree', 'Live')
|
||||||
->filter('ID', $batch)
|
->filter('ID', $batch)
|
||||||
->limit($this->limit);
|
->limit($limit);
|
||||||
$this->updateJobInfo('Fetching pages to check');
|
$this->updateJobInfo('Fetching pages to check');
|
||||||
if ($track->CompletedPages == $track->TotalPages) {
|
if ($track->CompletedPages == $track->TotalPages) {
|
||||||
$track->Status = 'Completed';
|
$track->Status = 'Completed';
|
||||||
|
@ -51,7 +61,7 @@ class CheckExternalLinks extends BuildTask {
|
||||||
$batch = BrokenExternalPageTrack::get()
|
$batch = BrokenExternalPageTrack::get()
|
||||||
->filter(array(
|
->filter(array(
|
||||||
'TrackID' => $track->ID
|
'TrackID' => $track->ID
|
||||||
))->limit($this->limit)->column('PageID');
|
))->limit($limit)->column('PageID');
|
||||||
|
|
||||||
$pages = Versioned::get_by_stage('SiteTree', 'Live')
|
$pages = Versioned::get_by_stage('SiteTree', 'Live')
|
||||||
->filter('ID', $batch);
|
->filter('ID', $batch);
|
||||||
|
@ -159,22 +169,15 @@ class CheckExternalLinks extends BuildTask {
|
||||||
foreach ($rows as $row) {
|
foreach ($rows as $row) {
|
||||||
$row->delete();
|
$row->delete();
|
||||||
}
|
}
|
||||||
} else {
|
return $track;
|
||||||
// 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
|
// if running via the queued job module return to the queued job after each iteration
|
||||||
$queuedJob = Config::inst()->get('CheckExternalLinks', 'Delay');
|
if ($limit == 1) {
|
||||||
if (isset($queuedJob) && is_int($queuedJob) && class_exists('QueuedJobService')) {
|
return $track;
|
||||||
$checkLinks = new CheckExternalLinksJob();
|
} else {
|
||||||
singleton('QueuedJobService')
|
$this->updateJobInfo("Running next batch {$track->CompletedPages}/{$track->TotalPages}");
|
||||||
->queueJob($checkLinks, date('Y-m-d H:i:s', time() + $queuedJob));
|
return $this->runLinksCheck($limit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
$(this).start();
|
$(this).start();
|
||||||
},
|
},
|
||||||
onmatch: function() {
|
onmatch: function() {
|
||||||
|
// poll the current job and update the front end status
|
||||||
|
$('#externalLinksReport').hide();
|
||||||
$(this).poll();
|
$(this).poll();
|
||||||
},
|
},
|
||||||
start: function() {
|
start: function() {
|
||||||
|
@ -16,15 +18,16 @@
|
||||||
$(this).poll();
|
$(this).poll();
|
||||||
},
|
},
|
||||||
poll: function() {
|
poll: function() {
|
||||||
// poll the current job and update the front end status
|
|
||||||
$('#externalLinksReport').hide();
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "admin/externallinks/getJobStatus",
|
url: "admin/externallinks/getJobStatus",
|
||||||
async: true,
|
async: true,
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
var obj = $.parseJSON(data);
|
var obj = $.parseJSON(data);
|
||||||
|
|
||||||
|
// No report, so let user create one
|
||||||
if (!obj) {
|
if (!obj) {
|
||||||
setTimeout(function() { $('#externalLinksReport').poll(); }, 1000);
|
$('#externalLinksReport').show();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
var completed = obj.Completed ? obj.Completed : 0;
|
var completed = obj.Completed ? obj.Completed : 0;
|
||||||
var total = obj.Total ? obj.Total : 0;
|
var total = obj.Total ? obj.Total : 0;
|
||||||
|
@ -46,7 +49,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: function(e) {
|
error: function(e) {
|
||||||
console.log(e);
|
if(typeof console !== 'undefined') console.log(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue