Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 42
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
CacheTesterResultsJob
0.00% covered (danger)
0.00%
0 / 42
0.00% covered (danger)
0.00%
0 / 2
12
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
2
 run
0.00% covered (danger)
0.00%
0 / 32
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3/**
4 * @file
5 * @ingroup Extensions
6 * @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
7 * @license MIT
8 */
9
10namespace MediaWiki\Extension\WikiLambda\Jobs;
11
12use GenericParameterJob;
13use Job;
14use MediaWiki\Extension\WikiLambda\WikiLambdaServices;
15use MediaWiki\Extension\WikiLambda\ZObjectStore;
16use MediaWiki\Logger\LoggerFactory;
17use Psr\Log\LoggerInterface;
18
19/**
20 * Asynchronous job to write out the results of a function tester run to the database,
21 * which allows us to avoid a database write on an API GET.
22 */
23class CacheTesterResultsJob extends Job implements GenericParameterJob {
24
25    private LoggerInterface $logger;
26    private ZObjectStore $zObjectStore;
27
28    /**
29     * @param array $params
30     */
31    public function __construct( array $params ) {
32        parent::__construct( 'cacheTesterResults', $params );
33        $this->logger = LoggerFactory::getInstance( 'WikiLambda' );
34
35        // TODO (T330030): Consider accessing the ZObjectStore as an injected service
36        $this->zObjectStore = WikiLambdaServices::getZObjectStore();
37
38        $this->logger->debug(
39            __CLASS__ . ' created',
40            [
41                'functionZid' => $this->params['functionZid'],
42                'functionRevision' => $this->params['functionRevision']
43            ]
44        );
45    }
46
47    /**
48     * @return bool
49     */
50    public function run() {
51        $success = $this->zObjectStore->insertZTesterResult(
52            $this->params['functionZid'],
53            $this->params['functionRevision'],
54            $this->params['implementationZid'],
55            $this->params['implementationRevision'],
56            $this->params['testerZid'],
57            $this->params['testerRevision'],
58            $this->params['passed'],
59            $this->params['stashedResult']
60        );
61
62        if ( $success ) {
63            $this->logger->debug(
64                __CLASS__ . ' Updated cache for tester result',
65                [
66                    'functionZid' => $this->params['functionZid'],
67                    'functionRevision' => $this->params['functionRevision']
68                ]
69            );
70        } else {
71            $this->logger->info(
72                __CLASS__ . ' Failed to update cache for tester result',
73                [
74                    'functionZid' => $this->params['functionZid'],
75                    'functionRevision' => $this->params['functionRevision'],
76                    'implementationZid' => $this->params['implementationZid'],
77                    'implementationRevision' => $this->params['implementationRevision'],
78                    'testerZid' => $this->params['testerZid'],
79                    'testerRevision' => $this->params['testerRevision'],
80                    'passed' => $this->params['passed'],
81                    'stashedResult' => $this->params['stashedResult']
82                ]
83            );
84
85        }
86
87        return true;
88    }
89}