src/Model/Table/EmailQueueTable.php
public function getBatch($size = 10)
    {
        return $this->getConnection()->transactional(function () use ($size) {
            $emails = $this->find()
                ->where([
                    $this->aliasField('sent') => false,
                    $this->aliasField('send_tries') . ' <=' => 3,
                    $this->aliasField('send_at') . ' <=' => new FrozenTime('now'),
                    $this->aliasField('locked') => false,
                ])
                ->limit($size)
                ->order([$this->aliasField('created') => 'ASC']);

            $emails
                ->extract('id')
                ->through(function (\Cake\Collection\CollectionInterface $ids) {
                    if (!$ids->isEmpty()) {
                        $this->updateAll(['locked' => true], ['id IN' => $ids->toList()]);
                    }

                    return $ids;
                });

            return $emails->toList();
        });
    }
public function getBatch($size = 10)
    {
        return $this->getConnection()->transactional(function () use ($size) {
            $emails = $this->find()
                ->where([
                    $this->aliasField('sent') => false,
                    $this->aliasField('send_tries') . ' <=' => 3,
                    $this->aliasField('send_at') . ' <=' => new FrozenTime('now'),
                    $this->aliasField('locked') => false,
                ])
                ->limit($size)
                ->order([$this->aliasField('created') => 'ASC']);

            $emails
                ->extract('id')
                ->through(function (\Cake\Collection\CollectionInterface $ids) {
                    if (!$ids->isEmpty()) {
                        $this->updateAll(['locked' => true], ['id IN' => $ids->toList()]);
                    }

                    return $ids;
                });

            return $emails->toList();
        });
    }
public function getBatch ( $ size = 10 ) { return $ this -> getConnection ( ) -> transactional ( function ( ) use ( $ size ) { $ emails = $ this -> find ( ) -> where ( [ $ this -> aliasField ( 'sent' ) => false , $ this -> aliasField ( 'send_tries' ) . ' <=' => 3 , $ this -> aliasField ( 'send_at' ) . ' <=' => new FrozenTime ( 'now' ) , $ this -> aliasField ( 'locked' ) => false , ] ) -> limit ( $ size ) -> order ( [ $ this -> aliasField ( 'created' ) => 'ASC' ] ) ; $ emails -> extract ( 'id' ) -> through ( function ( \ Cake \ Collection \ CollectionInterface $ ids ) { if ( ! $ ids -> isEmpty ( ) ) { $ this -> updateAll ( [ 'locked' => true ] , [ 'id IN' => $ ids -> toList ( ) ] ) ; } return $ ids ; } ) ; return $ emails -> toList ( ) ; } ) ; }
Returns a list of queued emails that needs to be sent.

@param int $size number of unset emails to return
@throws \Exception any exception raised in transactional callback
@return array list of unsent emails
Returns a list of queued emails that needs to be sent .