Skip to content

Commit

Permalink
try to more quickly check the state of a li task job before preparing…
Browse files Browse the repository at this point in the history
… from crawl
  • Loading branch information
Jon Cram committed Mar 20, 2015
1 parent 6de9eb7 commit 141537b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/SimplyTestable/ApiBundle/Controller/TaskController.php
Expand Up @@ -45,14 +45,14 @@ public function completeAction($canonical_url, $task_type, $parameter_hash) {
return $this->sendFailureResponse();
}

$taskType = $this->getTaskTypeService()->getByName($task_type);
$taskType = $this->getTaskTypeService()->getByName($task_type);

$tasks = $this->getTaskService()->getEquivalentTasks($canonical_url, $taskType, $parameter_hash, $this->getTaskService()->getIncompleteStates());

if (count($tasks) === 0) {
return $this->sendGoneResponse();
}

$endDateTime = new \DateTime($this->getArguments('completeByUrlAndTaskTypeAction')->get('end_date_time'));
$rawOutput = $this->getArguments('completeByUrlAndTaskTypeAction')->get('output');

Expand Down Expand Up @@ -89,20 +89,22 @@ public function completeAction($canonical_url, $task_type, $parameter_hash) {
$this->getJobService()->complete($task->getJob());
}

if ($task->getType()->equals($this->getTaskTypeService()->getByName('URL discovery'))) {
if ($task->getType()->equals($urlDiscoveryTaskType)) {
if ($this->getJobService()->isCompleted($task->getJob())) {
$crawlJobContainer = $this->getCrawlJobContainerService()->getForJob($task->getJob());
if ($this->getCrawlJobContainerService()->getEntityRepository()->doesCrawlTaskParentStateMatchState($task, $this->getJobService()->getFailedNoSitemapState())) {
$crawlJobContainer = $this->getCrawlJobContainerService()->getForJob($task->getJob());

foreach ($crawlJobContainer->getParentJob()->getRequestedTaskTypes() as $taskType) {
/* @var $taskType TaskType */
$taskTypeParameterDomainsToIgnoreKey = strtolower(str_replace(' ', '-', $taskType->getName())) . '-domains-to-ignore';
foreach ($crawlJobContainer->getParentJob()->getRequestedTaskTypes() as $taskType) {
/* @var $taskType TaskType */
$taskTypeParameterDomainsToIgnoreKey = strtolower(str_replace(' ', '-', $taskType->getName())) . '-domains-to-ignore';

if ($this->container->hasParameter($taskTypeParameterDomainsToIgnoreKey)) {
$this->getJobPreparationService()->setPredefinedDomainsToIgnore($taskType, $this->container->getParameter($taskTypeParameterDomainsToIgnoreKey));
if ($this->container->hasParameter($taskTypeParameterDomainsToIgnoreKey)) {
$this->getJobPreparationService()->setPredefinedDomainsToIgnore($taskType, $this->container->getParameter($taskTypeParameterDomainsToIgnoreKey));
}
}
}

$this->getJobPreparationService()->prepareFromCrawl($crawlJobContainer);
$this->getJobPreparationService()->prepareFromCrawl($crawlJobContainer);
}
}

$this->getResqueQueueService()->enqueue(
Expand Down
Expand Up @@ -3,10 +3,29 @@

use Doctrine\ORM\EntityRepository;
use SimplyTestable\ApiBundle\Entity\Job\Job;
use SimplyTestable\ApiBundle\Entity\State;
use SimplyTestable\ApiBundle\Entity\Task\Task;
use SimplyTestable\ApiBundle\Entity\User;

class CrawlJobContainerRepository extends EntityRepository
{

public function doesCrawlTaskParentStateMatchState(Task $task, State $state) {
$queryBuilder = $this->createQueryBuilder('CrawlJobContainer');
$queryBuilder->join('CrawlJobContainer.parentJob', 'ParentJob');
$queryBuilder->join('CrawlJobContainer.crawlJob', 'CrawlJob');
$queryBuilder->join('ParentJob.state', 'State');

$queryBuilder->select('State.name');

$queryBuilder->where('CrawlJob = :CrawlJob');
$queryBuilder->setParameter('CrawlJob', $task->getJob());
$queryBuilder->setMaxResults(1);

$result = $queryBuilder->getQuery()->getResult();
return (count($result) === 0) ? false : $result[0]['name'] == $state->getName();
}


/**
*
Expand Down

0 comments on commit 141537b

Please sign in to comment.