Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
11 / 11 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
FlushUtterancesFromStoreByExpirationJob | |
100.00% |
11 / 11 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
run | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Wikispeech\Utterance; |
4 | |
5 | /** |
6 | * @file |
7 | * @ingroup Extensions |
8 | * @license GPL-2.0-or-later |
9 | */ |
10 | |
11 | use Job; |
12 | use MediaWiki\Logger\LoggerFactory; |
13 | use Psr\Log\LoggerInterface; |
14 | use Title; |
15 | |
16 | /** |
17 | * @see UtteranceStore::flushUtterancesByExpirationDate() |
18 | * @see FlushUtterancesFromStoreByExpirationJobQueue |
19 | * |
20 | * @since 0.1.7 |
21 | */ |
22 | class FlushUtterancesFromStoreByExpirationJob extends Job { |
23 | |
24 | /** @var LoggerInterface */ |
25 | private $logger; |
26 | |
27 | /** @var UtteranceStore */ |
28 | private $utteranceStore; |
29 | |
30 | /** |
31 | * @since 0.1.7 |
32 | * @param Title $title |
33 | * @param array|null $params Ignored |
34 | */ |
35 | public function __construct( $title, $params ) { |
36 | parent::__construct( 'flushUtterancesFromStoreByExpiration', $title, $params ); |
37 | $this->logger = LoggerFactory::getInstance( 'Wikispeech' ); |
38 | $this->utteranceStore = new UtteranceStore(); |
39 | } |
40 | |
41 | /** |
42 | * Executed by the job queue. |
43 | * |
44 | * @since 0.1.7 |
45 | * @return bool success |
46 | */ |
47 | public function run() { |
48 | $flushedUtterances = $this->utteranceStore->flushUtterancesByExpirationDate( |
49 | $this->utteranceStore->getWikispeechUtteranceExpirationTimestamp() |
50 | ); |
51 | $this->logger->info( __METHOD__ . ': ' . |
52 | "Flushed {flushedUtterances} expired utterances from store.", |
53 | [ 'flushedUtterances' => $flushedUtterances ] |
54 | ); |
55 | // @note consider flushing a configurable limited batch of utterances, |
56 | // and queue a new job immediately here in case we flushed exactly that |
57 | // amount of utterances. |
58 | // Also see https://phabricator.wikimedia.org/T255104 |
59 | return true; |
60 | } |
61 | |
62 | } |