Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/plugins/CoreJob/config/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"NesterJob",
"ProvisionerJob",
"SyncJob"
],
"meta": [
"SyncJobLastRuns"
]
},
"schema": {
Expand Down
22 changes: 16 additions & 6 deletions app/plugins/CoreJob/src/Lib/Jobs/SyncJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@

namespace CoreJob\Lib\Jobs;

use App\Model\Entity\Job;
use App\Model\Table\JobHistoryRecordsTable;
use App\Model\Table\JobsTable;
use Cake\ORM\TableRegistry;
use \App\Lib\Enum\JobStatusEnum;
use \App\Lib\Enum\SyncModeEnum;
use \App\Lib\Util\TableUtilities;
use Cake\I18n\DateTime;

class SyncJob {
use \App\Lib\Traits\LabeledLogTrait;
Expand Down Expand Up @@ -383,19 +386,22 @@ protected function postRunTasks(
$lastRun = $LastRunTable->find()
->where(['external_identity_source_id' => $this->runContext->eis->id])
->first();


$startTime = DateTime::createFromTimestamp($curStart);

if($lastRun) {
// Update the existing row
$lastRun->start_time = $curStart;
$lastRun->start_time = $startTime;
} else {
$lastRun = $LastRunTable->newEntity([
'external_identity_source_id' => $this->runContext->eis->id,
'job_id' => $this->runContext->job->id,
'start_time' => $curStart
'start_time' => $startTime
]);
}

$LastRunTable->save($lastRun);
// Save the last run
$LastRunTable->saveOrFail($lastRun);

// Call the plugin if it has anything it wants to do

Expand Down Expand Up @@ -592,7 +598,11 @@ protected function syncRecord(string $key, ?string $referenceId=null): bool {
} else {
// Maybe update % complete

$processed = $this->runContext->created + $this->runContext->unchanged + $this->runContext->updated + $this->runContext->errors;
$processed = $this->runContext->created
+ $this->runContext->unchanged
+ $this->runContext->updated
+ $this->runContext->errors;

$newPct = ($this->runContext->count > 0
? (int)round(($processed * 100) / $this->runContext->count)
: 0);
Expand Down
121 changes: 121 additions & 0 deletions app/plugins/CoreJob/src/Model/Table/SyncJobLastRunsTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?php
/**
* COmanage Registry Sync Job Last Runs Table
*
* Portions licensed to the University Corporation for Advanced Internet
* Development, Inc. ("UCAID") under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* UCAID licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link https://www.internet2.edu/comanage COmanage Project
* @package registry-plugins
* @since COmanage Registry v5.3.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

declare(strict_types=1);

namespace CoreJob\Model\Table;

use Cake\ORM\Table;
use Cake\Validation\Validator;

class SyncJobLastRunsTable extends Table {
use \App\Lib\Traits\CoLinkTrait;
use \App\Lib\Traits\PermissionsTrait;
use \App\Lib\Traits\PrimaryLinkTrait;
use \App\Lib\Traits\TableMetaTrait;
use \App\Lib\Traits\ValidationTrait;

/**
* Perform Cake Model initialization.
*
* @since COmanage Registry v5.3.0
* @param array $config Configuration options passed to constructor
*/

public function initialize(array $config): void {
parent::initialize($config);

$this->setTableType(\App\Lib\Enum\TableTypeEnum::Artifact);

// Define associations
$this->belongsTo('ExternalIdentitySources');
$this->belongsTo('Jobs');

$this->hasManyPlugins([
'ExternalIdentitySources' => [
[
'targetModel' => 'CoreJob.SyncJobLastRuns',
'config' => [
'dependent' => true,
'cascadeCallbacks' => true
]
]
],
'Jobs' => [
[
'targetModel' => 'CoreJob.SyncJobLastRuns',
'config' => [
'dependent' => true,
'cascadeCallbacks' => true
]
]
]
]);

$this->setPrimaryLink(['external_identity_source_id', 'job_id']);
$this->setRequiresCO(true);

$this->setPermissions([
'entity' => [
'delete' => false,
'edit' => false,
'view' => ['platformAdmin', 'coAdmin']
],
'table' => [
'add' => false,
'index' => ['platformAdmin', 'coAdmin']
]
]);
}

/**
* Set validation rules.
*
* @since COmanage Registry v5.3.0
* @param Validator $validator Validator
* @return Validator Validator
*/

public function validationDefault(Validator $validator): Validator {
$validator->add('external_identity_source_id', [
'content' => ['rule' => 'isInteger']
]);
$validator->notEmptyString('external_identity_source_id');

$validator->add('job_id', [
'content' => ['rule' => 'isInteger']
]);
$validator->allowEmptyString('job_id');

$validator->add('start_time', [
'content' => ['rule' => 'dateTime']
]);
$validator->allowEmptyString('start_time');

return $validator;
}
}
64 changes: 0 additions & 64 deletions app/plugins/CoreJob/src/Model/Table/SyncJobsTable.php

This file was deleted.

5 changes: 5 additions & 0 deletions app/src/Lib/Traits/PluggableModelTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ protected function bindPluggableRelations() {
$models = $Plugins->getActivePluginModels($this->getPluggableModelType());

foreach($models as $plugin) {
// Not all Entry Point Models are Tables (eg: Jobs), so make sure we don't get an Auto-Table.
if(!\Cake\Core\App::className($plugin, 'Model/Table', 'Table')) {
continue;
}

// Derive association alias from "Plugin.Model"
[$pluginName, $modelAlias] = explode('.', $plugin, 2);

Expand Down