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 Mediawiki\Title\Title; |
| 14 | use Psr\Log\LoggerInterface; |
| 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.13 add service $utteranceStore to constructor |
| 32 | * @since 0.1.7 |
| 33 | * @param Title $title |
| 34 | * @param array|null $params Ignored |
| 35 | * @param UtteranceStore $utteranceStore |
| 36 | */ |
| 37 | public function __construct( $title, $params, $utteranceStore ) { |
| 38 | parent::__construct( 'flushUtterancesFromStoreByExpiration', $title, $params ); |
| 39 | $this->logger = LoggerFactory::getInstance( 'Wikispeech' ); |
| 40 | $this->utteranceStore = $utteranceStore; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Executed by the job queue. |
| 45 | * |
| 46 | * @since 0.1.7 |
| 47 | * @return bool success |
| 48 | */ |
| 49 | public function run() { |
| 50 | $flushedUtterances = $this->utteranceStore->flushUtterancesByExpirationDate( |
| 51 | $this->utteranceStore->getWikispeechUtteranceExpirationTimestamp() |
| 52 | ); |
| 53 | $this->logger->info( __METHOD__ . ': ' . |
| 54 | "Flushed {flushedUtterances} expired utterances from store.", |
| 55 | [ 'flushedUtterances' => $flushedUtterances ] |
| 56 | ); |
| 57 | // @note consider flushing a configurable limited batch of utterances, |
| 58 | // and queue a new job immediately here in case we flushed exactly that |
| 59 | // amount of utterances. |
| 60 | // Also see https://phabricator.wikimedia.org/T255104 |
| 61 | return true; |
| 62 | } |
| 63 | |
| 64 | } |