Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
23 / 23 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| CacheTesterResultsJob | |
100.00% |
23 / 23 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
1 | |||
| run | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @file |
| 5 | * @ingroup Extensions |
| 6 | * @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt |
| 7 | * @license MIT |
| 8 | */ |
| 9 | |
| 10 | namespace MediaWiki\Extension\WikiLambda\Jobs; |
| 11 | |
| 12 | use MediaWiki\Extension\WikiLambda\WikiLambdaServices; |
| 13 | use MediaWiki\Extension\WikiLambda\ZObjectStore; |
| 14 | use MediaWiki\Extension\WikiLambda\ZObjectUtils; |
| 15 | use MediaWiki\JobQueue\GenericParameterJob; |
| 16 | use MediaWiki\JobQueue\Job; |
| 17 | use MediaWiki\Logger\LoggerFactory; |
| 18 | use Psr\Log\LoggerInterface; |
| 19 | |
| 20 | /** |
| 21 | * Asynchronous job to write out the results of a function tester run to the database, |
| 22 | * which allows us to avoid a database write on an API GET. |
| 23 | */ |
| 24 | class CacheTesterResultsJob extends Job implements GenericParameterJob { |
| 25 | use StoreTestResultTrait; |
| 26 | |
| 27 | private LoggerInterface $logger; |
| 28 | private ZObjectStore $zObjectStore; |
| 29 | |
| 30 | public function __construct( array $params ) { |
| 31 | parent::__construct( 'cacheTesterResults', $params ); |
| 32 | |
| 33 | $this->logger = LoggerFactory::getInstance( 'WikiLambda' ); |
| 34 | $this->zObjectStore = WikiLambdaServices::getZObjectStore(); |
| 35 | |
| 36 | $this->logger->debug( |
| 37 | __CLASS__ . ' created', |
| 38 | [ |
| 39 | 'functionZid' => $this->params['functionZid'], |
| 40 | 'functionRevision' => $this->params['functionRevision'] |
| 41 | ] |
| 42 | ); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * @inheritDoc |
| 47 | */ |
| 48 | public function run() { |
| 49 | $this->storeTestResult( |
| 50 | $this->logger, |
| 51 | $this->zObjectStore, |
| 52 | $this->params['functionZid'], |
| 53 | $this->params['functionRevision'], |
| 54 | $this->params['implementationZid'], |
| 55 | $this->params['implementationRevision'], |
| 56 | $this->params['testZid'], |
| 57 | $this->params['testRevision'], |
| 58 | $this->params['passed'], |
| 59 | // (T428954) Re-hydrate the stashed result to stdClass. JobQueue |
| 60 | // serialisation decodes it from JSON as an associative array, but |
| 61 | // storeTestResult() type-hints stdClass. See ZObjectUtils::objectify(). |
| 62 | ZObjectUtils::objectify( $this->params['stashedResult'] ) |
| 63 | ); |
| 64 | |
| 65 | return true; |
| 66 | } |
| 67 | } |