}
protected function supportedOrders() {
- return array( 'timestamp', 'fifo' );
+ return [ 'timestamp', 'fifo' ];
}
protected function optimalOrder() {
/**
* @see JobQueue::doBatchPush()
- * @param array $jobs
+ * @param IJobSpecification[] $jobs
* @param int $flags
* @return void
* @throws JobQueueError
*/
protected function doBatchPush( array $jobs, $flags ) {
// Convert the jobs into field maps (de-duplicated against each other)
- $items = array(); // (job ID => job fields map)
+ $items = []; // (job ID => job fields map)
foreach ( $jobs as $job ) {
$item = $this->getNewJobFields( $job );
if ( strlen( $item['sha1'] ) ) { // hash identifier => de-duplicate
try {
// Actually push the non-duplicate jobs into the queue...
if ( $flags & self::QOS_ATOMIC ) {
- $batches = array( $items ); // all or nothing
+ $batches = [ $items ]; // all or nothing
} else {
$batches = array_chunk( $items, 100 ); // avoid tying up the server
}
* @throws RedisException
*/
protected function pushBlobs( RedisConnRef $conn, array $items ) {
- $args = array( $this->encodeQueueName() );
+ $args = [ $this->encodeQueueName() ];
// Next args come in 4s ([id, sha1, rtime, blob [, id, sha1, rtime, blob ... ] ] )
foreach ( $items as $item ) {
$args[] = (string)$item['uuid'];
LUA;
return $conn->luaEval( $script,
array_merge(
- array(
+ [
$this->getQueueKey( 'l-unclaimed' ), # KEYS[1]
$this->getQueueKey( 'h-sha1ById' ), # KEYS[2]
$this->getQueueKey( 'h-idBySha1' ), # KEYS[3]
$this->getQueueKey( 'z-delayed' ), # KEYS[4]
$this->getQueueKey( 'h-data' ), # KEYS[5]
$this->getGlobalKey( 's-queuesWithJobs' ), # KEYS[6]
- ),
+ ],
$args
),
6 # number of first argument(s) that are keys
return redis.call('hGet',kData,id)
LUA;
return $conn->luaEval( $script,
- array(
+ [
$this->getQueueKey( 'l-unclaimed' ), # KEYS[1]
$this->getQueueKey( 'h-sha1ById' ), # KEYS[2]
$this->getQueueKey( 'h-idBySha1' ), # KEYS[3]
$this->getQueueKey( 'h-attempts' ), # KEYS[5]
$this->getQueueKey( 'h-data' ), # KEYS[6]
time(), # ARGV[1] (injected to be replication-safe)
- ),
+ ],
6 # number of first argument(s) that are keys
);
}
return redis.call('hDel',kData,uuid)
LUA;
$res = $conn->luaEval( $script,
- array(
+ [
$this->getQueueKey( 'z-claimed' ), # KEYS[1]
$this->getQueueKey( 'h-attempts' ), # KEYS[2]
$this->getQueueKey( 'h-data' ), # KEYS[3]
$uuid # ARGV[1]
- ),
+ ],
3 # number of first argument(s) that are keys
);
* @throws JobQueueError
*/
protected function doDelete() {
- static $props = array( 'l-unclaimed', 'z-claimed', 'z-abandoned',
- 'z-delayed', 'h-idBySha1', 'h-sha1ById', 'h-attempts', 'h-data' );
+ static $props = [ 'l-unclaimed', 'z-claimed', 'z-abandoned',
+ 'z-delayed', 'h-idBySha1', 'h-sha1ById', 'h-attempts', 'h-data' ];
$conn = $this->getConnection();
try {
- $keys = array();
+ $keys = [];
foreach ( $props as $prop ) {
$keys[] = $this->getQueueKey( $prop );
}
* @return MappedIterator
*/
protected function getJobIterator( RedisConnRef $conn, array $uids ) {
- $that = $this;
-
return new MappedIterator(
$uids,
- function ( $uid ) use ( $that, $conn ) {
- return $that->getJobFromUidInternal( $uid, $conn );
+ function ( $uid ) use ( $conn ) {
+ return $this->getJobFromUidInternal( $uid, $conn );
},
- array( 'accept' => function ( $job ) {
+ [ 'accept' => function ( $job ) {
return is_object( $job );
- } )
+ } ]
);
}
}
protected function doGetSiblingQueueSizes( array $types ) {
- $sizes = array(); // (type => size)
+ $sizes = []; // (type => size)
$types = array_values( $types ); // reindex
$conn = $this->getConnection();
try {
* @throws JobQueueError
*/
public function getServerQueuesWithJobs() {
- $queues = array();
+ $queues = [];
$conn = $this->getConnection();
try {
* @return array
*/
protected function getNewJobFields( IJobSpecification $job ) {
- return array(
+ return [
// Fields that describe the nature of the job
'type' => $job->getType(),
'namespace' => $job->getTitle()->getNamespace(),
? Wikimedia\base_convert( sha1( serialize( $job->getDeduplicationInfo() ) ), 16, 36, 31 )
: '',
'timestamp' => time() // UNIX timestamp
- );
+ ];
}
/**
&& strlen( $blob ) >= 1024
&& function_exists( 'gzdeflate' )
) {
- $object = (object)array( 'blob' => gzdeflate( $blob ), 'enc' => 'gzip' );
+ $object = (object)[ 'blob' => gzdeflate( $blob ), 'enc' => 'gzip' ];
$blobz = serialize( $object );
return ( strlen( $blobz ) < strlen( $blob ) ) ? $blobz : $blob;
* @return string JSON
*/
private function encodeQueueName() {
- return json_encode( array( $this->type, $this->wiki ) );
+ return json_encode( [ $this->type, $this->wiki ] );
}
/**
* @return string
*/
private function getGlobalKey( $name ) {
- $parts = array( 'global', 'jobqueue', $name );
+ $parts = [ 'global', 'jobqueue', $name ];
foreach ( $parts as $part ) {
if ( !preg_match( '/[a-zA-Z0-9_-]+/', $part ) ) {
throw new InvalidArgumentException( "Key part characters are out of range." );
list( $db, $prefix ) = wfSplitWikiID( $this->wiki );
$keyspace = $prefix ? "$db-$prefix" : $db;
- $parts = array( $keyspace, 'jobqueue', $type, $prop );
+ $parts = [ $keyspace, 'jobqueue', $type, $prop ];
// Parts are typically ASCII, but encode for sanity to escape ":"
return implode( ':', array_map( 'rawurlencode', $parts ) );