2017 © Pedro Peláez
 

yii2-extension yii2-async

Provides translucent api for moving large tasks out of request context

image

bazilio/yii2-async

Provides translucent api for moving large tasks out of request context

  • Friday, April 1, 2016
  • by bazilio91
  • Repository
  • 10 Watchers
  • 67 Stars
  • 9,770 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 15 Forks
  • 1 Open issues
  • 19 Versions
  • 5 % Grown

The README.md

yii2-async

Build Status Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

Provides translucent api for moving large tasks out of request response, (*2)

Install: php composer.phar require bazilio/yii2-async:dev-master, (*3)

Requirments:
Using with AMQP:

php composer.phar require pdezwart/php-amqp:dev-master, (*4)

main.php:, (*5)

'components' => [
    'async' => [
        'class' => 'bazilio\async\AsyncComponent',
        'transportClass' => 'bazilio\async\transports\AsyncAmqpTransport',
        'transportConfig' => [
            'host' => 'localhost',
            'login' => 'guest',
            'password' => 'guest',
            'vhost' => 'yii',
            'exchangeName' => 'yii'
        ]
    ]
]
Using with Redis:

php composer.phar require yiisoft/yii2-redis:*, (*6)

main.php:, (*7)

'components' => [
    'redis' => [
        'class' => 'yii\redis\Connection',
        'hostname' => 'localhost',
        'port' => 6379,
        'database' => 0,
        'dataTimeout' => -1, // important for daemon and blocking queries
    ],
    'async' => [
        'class' => 'bazilio\async\AsyncComponent',
        'transportClass' => 'bazilio\async\transports\AsyncRedisTransport',
        'transportConfig' => [
            'connection' => 'redis',
        ]
    ]
]
Using with MySQL (probably any sql, but tested only with mysql)

main.php:, (*8)

'components' => [
    'db' => [
        'class' => 'yii\db\Connection',
        'dsn' => 'mysql:host=localhost;dbname=yii2advenced',
        'username' => 'root',
        'password' => '',
        'charset' => 'utf8',
    ],
    'async' => [
        'class' => 'bazilio\async\AsyncComponent',
        'transportClass' => 'bazilio\async\transports\AsyncMysqlTransport',
        'transportConfig' => [
            'connection' => 'db',
        ]
    ]
]

Apply migrations:, (*9)

./yii migrate/up --migrationPath=@vendor/bazilio/yii2-async/migrations
Usage:

Create and send:

Test class example:, (*10)

class DownloadTask extends AsyncTask
{
    public $url;
    public $file;
    public static $queueName = 'downloads';

    public function execute()
    {
        return file_put_contents($this->file, file_get_contents($this->url));
    }
}

// create task
$task = new DownloadTask(['url' => 'http://localhost/', 'file' => '/tmp/localhost.html']);
\Yii::$app->async->sendTask($task);

Or call external method:, (*11)

$task = new AsyncExecuteTask([
    'class' => 'common\components\MyDownloaderComponent',
    'method' => 'download',
    'arguments' => ['url' => 'http://localhost/', 'file' => '/tmp/localhost.html']
]);


$task::$queueName = 'downloads';

if (YII_ENV !== 'prod') {
    $task->execute();
} else {
    Yii::$app->async->sendTask($task);
}

Execute:

Bash way:, (*12)

Fill console config:, (*13)

'controllerMap' => [
        'async-worker' => [
            'class' => 'bazilio\async\commands\AsyncWorkerCommand',
        ],
    ],

Run:, (*14)

# Process and exit on finish
./yii async-worker/execute downloads
# Process and wait for new tasks (only redis)
./yii async-worker/daemon downloads

Code way:, (*15)

while ($task = \Yii::$app->async->receiveTask('downloads')) {
    if ($task->execute()) {
        \Yii::$app->async->acknowledgeTask($task);
    }
}

For more code examples look into tests: - BaseTestClass, (*16)

Runing tests:
vendor/bin/codecept run

Or in Docker:, (*17)

./test.sh

The Versions

01/04 2016

dev-master

9999999-dev

Provides translucent api for moving large tasks out of request context

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vasily Ostanin

rabbitmq yii2 redis mysql async amqp tasks

01/04 2016

0.2.0

0.2.0.0

Provides translucent api for moving large tasks out of request context

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vasily Ostanin

rabbitmq yii2 redis async amqp tasks

28/01 2016

0.1.2

0.1.2.0

Provides translucent api for moving large tasks out of request context

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vasily Ostanin

rabbitmq yii2 redis async amqp tasks

12/12 2015

0.1.1

0.1.1.0

Provides translucent api for moving large tasks out of request context

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vasily Ostanin

rabbitmq yii2 redis async amqp tasks

18/11 2015

0.1.0.5

0.1.0.5

Provides translucent api for moving large tasks out of request context

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vasily Ostanin

rabbitmq yii2 redis async amqp tasks

18/11 2015

0.1.0.4

0.1.0.4

Provides translucent api for moving large tasks out of request context

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vasily Ostanin

rabbitmq yii2 redis async amqp tasks

15/11 2015

0.1.0.3

0.1.0.3

Provides translucent api for moving large tasks out of request context

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vasily Ostanin

rabbitmq yii2 redis async amqp tasks

15/11 2015

0.1.0.2

0.1.0.2

Provides translucent api for moving large tasks out of request context

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vasily Ostanin

rabbitmq yii2 redis async amqp tasks

02/09 2015

0.1.0.1

0.1.0.1

Provides translucent api for moving large tasks out of request context

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vasily Ostanin

rabbitmq yii2 redis async amqp tasks

02/09 2015

0.1.0

0.1.0.0

Provides translucent api for moving large tasks out of request context

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vasily Ostanin

rabbitmq yii2 redis async amqp tasks

27/07 2015

0.0.8

0.0.8.0

Provides translucent api for moving large tasks out of request context

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vasily Ostanin

rabbitmq yii2 redis async amqp tasks

15/05 2015

0.0.7

0.0.7.0

Provides translucent api for moving large tasks out of request context

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vasily Ostanin

rabbitmq yii2 redis async amqp tasks

15/05 2015

0.0.7.1

0.0.7.1

Provides translucent api for moving large tasks out of request context

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vasily Ostanin

rabbitmq yii2 redis async amqp tasks

07/05 2015

0.0.6

0.0.6.0

Provides translucent api for moving large tasks out of request context

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vasily Ostanin

rabbitmq yii2 redis async amqp tasks

29/04 2015

0.0.5

0.0.5.0

Provides translucent api for moving large tasks out of request context

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vasily Ostanin

rabbitmq yii2 redis async amqp tasks

23/04 2015

0.0.4

0.0.4.0

Provides translucent api for moving large tasks out of request context

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vasily Ostanin

rabbitmq yii2 redis async amqp tasks

10/03 2015

0.0.3

0.0.3.0

Provides translucent api for moving large tasks out of request context

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vasily Ostanin

rabbitmq yii2 redis async amqp tasks

05/03 2015

0.0.2

0.0.2.0

Provides translucent api for moving large tasks out of request context

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vasily Ostanin

rabbitmq yii2 redis async amqp tasks

09/07 2014

0.0.1

0.0.1.0

Provides translucent api for moving large tasks out of request context

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vasily Ostanin