Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rsinger committed Dec 14, 2017
1 parent 6767c75 commit 4ca73cd
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 12 deletions.
12 changes: 7 additions & 5 deletions src/mongo/JobGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Tripod\Mongo;

use \MongoDB\BSON\ObjectId;

class JobGroup
{
private $id;
Expand All @@ -11,15 +13,15 @@ class JobGroup
/**
* Constructor method
* @param string $storeName Tripod store (database) name
* @param string|\MongoDB\BSON\ObjectId $groupId Optional tracking ID, will assign a new one if omitted
* @param string|ObjectId $groupId Optional tracking ID, will assign a new one if omitted
*/
public function __construct($storeName, $groupId = null)
{
$this->storeName = $storeName;
if (!$groupId) {
$groupId = new \MongoDB\BSON\ObjectId();
} elseif (!$groupId instanceof \MongoDB\BSON\ObjectId) {
$groupId = new \MongoDB\BSON\ObjectId($groupId);
$groupId = new ObjectId();
} elseif (!$groupId instanceof ObjectId) {
$groupId = new ObjectId($groupId);
}
$this->id = $groupId;
}
Expand Down Expand Up @@ -60,7 +62,7 @@ public function incrementJobCount($inc = 1)
}

/**
* @return \MongoDB\BSON\ObjectId
* @return ObjectId
*/
public function getId()
{
Expand Down
2 changes: 0 additions & 2 deletions src/mongo/MongoTripodConstants.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@
define('STAT_CLASS', 'tripod');
define('STAT_PIVOT_FIELD', 'group_by_db');

define('BATCH_TRACKING_GROUP', 'BATCH_TRACKING_GROUP');

//Audit types, statuses
define('AUDIT_TYPE_REMOVE_INERT_LOCKS', 'REMOVE_INERT_LOCKS');
define('AUDIT_STATUS_IN_PROGRESS', 'IN_PROGRESS');
Expand Down
2 changes: 1 addition & 1 deletion src/mongo/delegates/SearchDocuments.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function generateSearchDocumentBasedOnSpecId($specId, $resource, $context
$this->debugLog("Processing {$specId}");

// build the document
$generatedDocument = [\_CREATED_TS => \Tripod\Mongo\DateUtil::getMongoDate()];
$generatedDocument = [\_CREATED_TS => DateUtil::getMongoDate()];
$this->addIdToImpactIndex($_id, $generatedDocument);

$_id['type'] = $specId;
Expand Down
3 changes: 2 additions & 1 deletion src/mongo/delegates/SearchIndexer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ public function generateAndIndexSearchDocuments($resourceUri, $context, $podName
* @param string|null $resourceUri
* @param string|null $context
* @param string|null $queueName
* @return array|null Will return an array with a count and group id, if $queueName is sent and $resourceUri is null
*/
public function generateSearchDocuments($searchDocumentType, $resourceUri=null, $context=null, $queueName=null)
{
Expand Down Expand Up @@ -213,7 +214,7 @@ public function generateSearchDocuments($searchDocumentType, $resourceUri=null,
));

$jobOptions = [];
if ($queueName && !$resource) {
if ($queueName && !$resourceUri) {
$jobOptions['statsConfig'] = $this->getStatsConfig();
$jobGroup = new JobGroup($this->storeName);
$jobOptions[ApplyOperation::TRACKING_KEY] = $jobGroup->getId()->__toString();
Expand Down
6 changes: 6 additions & 0 deletions src/mongo/jobs/ApplyOperation.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ public function perform()
// stat time taken to perform operation for the given subject
$this->getStat()->timer(MONGO_QUEUE_APPLY_OPERATION.'.'.$subject['operation'], $opTimer->result());

/**
* ApplyOperation jobs can either apply to a single resource (e.g. 'create composite for the given
* resource uri) or for a specification id (i.e. regenerate all of the composites defined by the
* specification). For the latter, we need to keep track of how many jobs have run so we can clean
* up any stale composite documents when completed. The TRACKING_KEY value will be the JobGroup id.
*/
if (isset($this->args[self::TRACKING_KEY])) {
$jobGroup = $this->getJobGroup($subject['storeName'], $this->args[self::TRACKING_KEY]);
$jobCount = $jobGroup->incrementJobCount(-1);
Expand Down
2 changes: 1 addition & 1 deletion src/mongo/providers/MongoSearchProvider.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ public function getSearchCollectionName()
* If type id is not specified this method will throw an exception.
* @param string $typeId Search type id
* @param \MongoDB\BSON\UTCDateTime|null $timestamp Optional timestamp to delete all search docs that are older than
* @return integer The number of search documnts deleted
* @return integer The number of search documents deleted
* @throws \Tripod\Exceptions\Exception if there was an error performing the operation
*/
public function deleteSearchDocumentsByTypeId($typeId, $timestamp = null)
Expand Down
3 changes: 1 addition & 2 deletions test/unit/mongo/ApplyOperationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,7 @@ public function testApplyViewOperationCleanupIfAllGroupJobsComplete()
->method('createImpactedSubject')
->will($this->returnValue($subject));

// $applyOperation->expects($this->exactly(3))
$applyOperation->expects($this->any())
$applyOperation->expects($this->exactly(3))
->method('getStat')
->will($this->returnValue($statMock));

Expand Down

0 comments on commit 4ca73cd

Please sign in to comment.