Skip to content

Commit

Permalink
MySQL transport support. Closes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
bazilio91 committed Apr 1, 2016
1 parent d12489d commit 7e74cca
Show file tree
Hide file tree
Showing 14 changed files with 279 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ matrix:
services:
- redis-server
- rabbitmq
- mysql

# faster builds on new travis setup not using sudo
sudo: false
Expand All @@ -37,6 +38,7 @@ install:
- travis_retry composer install --prefer-dist --no-interaction

before_script:
- mysql -e 'create database `async-test`;'

script:
- vendor/bin/codecept run
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.2.0
=====
- Mysql transport support

0.0.5
=====
- [Fix first message send in AMQP provider + travis ci](https://github.com/bazilio91/yii2-async/commit/961fc05bf4776509074c062f944124fe090e1b6f)
Expand Down
7 changes: 3 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
FROM php:cli
FROM php:5.6-cli

RUN apt-get update && apt-get install -y redis-server \
rabbitmq-server librabbitmq-dev
RUN apt-get update && apt-get install -y librabbitmq-dev
RUN php -r "readfile('https://getcomposer.org/installer');" | php
RUN docker-php-ext-install pcntl shmop mbstring
RUN docker-php-ext-install pcntl shmop mbstring pdo_mysql
RUN pecl install amqp && echo "extension=amqp.so" >> /usr/local/etc/php/conf.d/amqp.ini

ADD . /var/code
Expand Down
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Install: `php composer.phar require bazilio/yii2-async:dev-master`
#####Using with AMQP:
`php composer.phar require pdezwart/php-amqp:dev-master`

main.php:
```php
'components' => [
'async' => [
Expand All @@ -39,6 +40,7 @@ Install: `php composer.phar require bazilio/yii2-async:dev-master`
#####Using with Redis:
`php composer.phar require yiisoft/yii2-redis:*`

main.php:
```php
'components' => [
'redis' => [
Expand All @@ -58,7 +60,32 @@ Install: `php composer.phar require bazilio/yii2-async:dev-master`
]
```

#####Using with MySQL (probably any sql, but tested only with mysql)

main.php:
```php
'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:
```php
./yii migrate/up --migrationPath=@vendor/bazilio/yii2-async/migrations
```

#####Usage:

Expand Down
18 changes: 18 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
yii2-async:
build: .
links:
- mysql
- redis
- rabbitmq

mysql:
image: mysql
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
MYSQL_DATABASE: "async-test"

redis:
image: redis

rabbitmq:
image: rabbitmq
29 changes: 29 additions & 0 deletions migrations/m160401_090723_async.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

use yii\db\Migration;

class m160401_090723_async extends Migration
{
public function up()
{
$this->createTable(
'{{%async}}',
[
'id' => 'pk',
'data' => 'longblob',
'status' => 'int(1) UNSIGNED DEFAULT 0',
'queue' => 'varchar(255) NOT NULL'
]
);

$this->createIndex('queue', '{{%async}}', 'queue');
$this->createIndex('queue_status', '{{%async}}', ['queue', 'status']);
}

public function down()
{
$this->dropIndex('queue', '{{%async}}');
$this->dropIndex('queue_status', '{{%async}}');
$this->dropTable('{{%async}}');
}
}
4 changes: 2 additions & 2 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ set -x
#docker rmi yii2-async
set -e

docker build -t yii2-async .
docker run --rm yii2-async
docker-compose build yii2-async
docker-compose run --rm yii2-async
5 changes: 0 additions & 5 deletions tests/docker-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ set -e
set -x
cd /var/code

redis-server &
rabbitmq-server &

sleep 5

/composer.phar install

vendor/bin/codecept run
4 changes: 2 additions & 2 deletions tests/unit/BaseTestClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ public function testSubscribe()
}

public function testConsoleCommandDaemon() {
if (get_called_class() == 'bazilio\async\tests\unit\AmqpTest') {
$this->markTestSkipped('No support for AMQP yet');
if (get_called_class() !== 'bazilio\async\tests\unit\RedisTest') {
$this->markTestSkipped('No support for this transport yet');
return;
}

Expand Down
28 changes: 28 additions & 0 deletions tests/unit/MysqlTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
namespace bazilio\async\tests\unit;

class MysqlTest extends BaseTestClass
{
public $appConfig = '@tests/unit/_config.mysql.php';

protected static $migrated = false;

public static function migrate()
{
if (self::$migrated) {
return;
}

$migrateController = new \yii\console\controllers\MigrateController('migrate', \Yii::$app);
$migrateController->migrationPath = '@tests/../migrations';
$migrateController->runAction('up', ['interactive' => 0]);

self::$migrated = true;
}

public function loadFixtures($fixtures = null)
{
$this->migrate();
parent::loadFixtures($fixtures);
}
}
3 changes: 3 additions & 0 deletions tests/unit/_config.amqp.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<?php
$host = getenv('RABBITMQ_PORT_5672_TCP_ADDR') ? getenv('RABBITMQ_PORT_5672_TCP_ADDR') : 'localhost';

return [
'id' => 'test',
'basePath' => dirname(__DIR__),
'components' => [
'async' => [
'class' => 'bazilio\async\AsyncComponent',
'transportConfig' => [
'host' => $host,
'vhost' => '/',
'exchangeName' => 'test'
]
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/_config.mysql.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
$host = getenv('MYSQL_PORT_3306_TCP_ADDR') ? getenv('MYSQL_PORT_3306_TCP_ADDR') : 'localhost';

return [
'id' => 'test',
'basePath' => dirname(__DIR__),
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => "mysql:host=$host;dbname=async-test",
'username' => 'root',
'password' => '',
'charset' => 'utf8',
],
'async' => [
'class' => 'bazilio\async\AsyncComponent',
'transportClass' => 'bazilio\async\transports\AsyncMysqlTransport',
'transportConfig' => [
'connection' => 'db',
]
]
]

];
18 changes: 3 additions & 15 deletions tests/unit/_config.redis.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php
$host = getenv('REDIS_PORT_6379_TCP_ADDR') ? getenv('REDIS_PORT_6379_TCP_ADDR') : 'localhost';

return [
'id' => 'test',
'basePath' => dirname(__DIR__),
'components' => [
'redis' => [
'class' => 'yii\redis\Connection',
'hostname' => 'localhost',
'hostname' => $host,
'port' => 6379,
'database' => 5,
'connectionTimeout' => 1,
Expand All @@ -18,20 +20,6 @@
'connection' => 'redis',
]
],
// This components are for blocking receive testing
'redisFork' => [
'class' => 'yii\redis\Connection',
'hostname' => 'localhost',
'port' => 6379,
'database' => 5,
],
'asyncFork' => [
'class' => 'bazilio\async\AsyncComponent',
'transportClass' => 'bazilio\async\transports\AsyncRedisTransport',
'transportConfig' => [
'connection' => 'redisFork',
]
]
]

];
Loading

0 comments on commit 7e74cca

Please sign in to comment.