Skip to content

Commit

Permalink
NEW: Fixing queuedjob status and hiding report button when report is …
Browse files Browse the repository at this point in the history
…running
  • Loading branch information
kmayo-ss committed Aug 3, 2014
1 parent e9fe1a4 commit 9e5a41f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
9 changes: 8 additions & 1 deletion code/jobs/CheckExternalLinksJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ public function getSignature() {
*/
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;
}
Expand Down
18 changes: 12 additions & 6 deletions code/tasks/CheckExternalLinks.php
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -20,10 +21,10 @@ function run($request) {
->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';
Expand All @@ -50,7 +51,7 @@ function run($request) {
$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);
Expand Down Expand Up @@ -159,8 +160,13 @@ function run($request) {
$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) {

This comment has been minimized.

Copy link
@tractorcow

tractorcow Aug 3, 2014

👍

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
Expand Down
4 changes: 3 additions & 1 deletion javascript/BrokenExternalLinksReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
$('#externalLinksReport').entwine({
onclick: function() {
$(this).start();
$(this).poll();
},
onmatch: function() {
$(this).poll();
Expand All @@ -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,
Expand All @@ -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);
}
Expand Down

0 comments on commit 9e5a41f

Please sign in to comment.