Skip to content

Commit 7e74cca

Browse files
committed
MySQL transport support. Closes #3
1 parent d12489d commit 7e74cca

14 files changed

+279
-28
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ matrix:
1919
services:
2020
- redis-server
2121
- rabbitmq
22+
- mysql
2223

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

3940
before_script:
41+
- mysql -e 'create database `async-test`;'
4042

4143
script:
4244
- vendor/bin/codecept run

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
0.2.0
2+
=====
3+
- Mysql transport support
4+
15
0.0.5
26
=====
37
- [Fix first message send in AMQP provider + travis ci](https://github.com/bazilio91/yii2-async/commit/961fc05bf4776509074c062f944124fe090e1b6f)

Dockerfile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
FROM php:cli
1+
FROM php:5.6-cli
22

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

98
ADD . /var/code

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Install: `php composer.phar require bazilio/yii2-async:dev-master`
1919
#####Using with AMQP:
2020
`php composer.phar require pdezwart/php-amqp:dev-master`
2121

22+
main.php:
2223
```php
2324
'components' => [
2425
'async' => [
@@ -39,6 +40,7 @@ Install: `php composer.phar require bazilio/yii2-async:dev-master`
3940
#####Using with Redis:
4041
`php composer.phar require yiisoft/yii2-redis:*`
4142

43+
main.php:
4244
```php
4345
'components' => [
4446
'redis' => [
@@ -58,7 +60,32 @@ Install: `php composer.phar require bazilio/yii2-async:dev-master`
5860
]
5961
```
6062

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

65+
main.php:
66+
```php
67+
'components' => [
68+
'db' => [
69+
'class' => 'yii\db\Connection',
70+
'dsn' => 'mysql:host=localhost;dbname=yii2advenced',
71+
'username' => 'root',
72+
'password' => '',
73+
'charset' => 'utf8',
74+
],
75+
'async' => [
76+
'class' => 'bazilio\async\AsyncComponent',
77+
'transportClass' => 'bazilio\async\transports\AsyncMysqlTransport',
78+
'transportConfig' => [
79+
'connection' => 'db',
80+
]
81+
]
82+
]
83+
```
84+
85+
Apply migrations:
86+
```php
87+
./yii migrate/up --migrationPath=@vendor/bazilio/yii2-async/migrations
88+
```
6289

6390
#####Usage:
6491

docker-compose.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
yii2-async:
2+
build: .
3+
links:
4+
- mysql
5+
- redis
6+
- rabbitmq
7+
8+
mysql:
9+
image: mysql
10+
environment:
11+
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
12+
MYSQL_DATABASE: "async-test"
13+
14+
redis:
15+
image: redis
16+
17+
rabbitmq:
18+
image: rabbitmq
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
use yii\db\Migration;
4+
5+
class m160401_090723_async extends Migration
6+
{
7+
public function up()
8+
{
9+
$this->createTable(
10+
'{{%async}}',
11+
[
12+
'id' => 'pk',
13+
'data' => 'longblob',
14+
'status' => 'int(1) UNSIGNED DEFAULT 0',
15+
'queue' => 'varchar(255) NOT NULL'
16+
]
17+
);
18+
19+
$this->createIndex('queue', '{{%async}}', 'queue');
20+
$this->createIndex('queue_status', '{{%async}}', ['queue', 'status']);
21+
}
22+
23+
public function down()
24+
{
25+
$this->dropIndex('queue', '{{%async}}');
26+
$this->dropIndex('queue_status', '{{%async}}');
27+
$this->dropTable('{{%async}}');
28+
}
29+
}

test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ set -x
33
#docker rmi yii2-async
44
set -e
55

6-
docker build -t yii2-async .
7-
docker run --rm yii2-async
6+
docker-compose build yii2-async
7+
docker-compose run --rm yii2-async

tests/docker-test.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ set -e
33
set -x
44
cd /var/code
55

6-
redis-server &
7-
rabbitmq-server &
8-
9-
sleep 5
10-
116
/composer.phar install
127

138
vendor/bin/codecept run

tests/unit/BaseTestClass.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ public function testSubscribe()
222222
}
223223

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

tests/unit/MysqlTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
namespace bazilio\async\tests\unit;
3+
4+
class MysqlTest extends BaseTestClass
5+
{
6+
public $appConfig = '@tests/unit/_config.mysql.php';
7+
8+
protected static $migrated = false;
9+
10+
public static function migrate()
11+
{
12+
if (self::$migrated) {
13+
return;
14+
}
15+
16+
$migrateController = new \yii\console\controllers\MigrateController('migrate', \Yii::$app);
17+
$migrateController->migrationPath = '@tests/../migrations';
18+
$migrateController->runAction('up', ['interactive' => 0]);
19+
20+
self::$migrated = true;
21+
}
22+
23+
public function loadFixtures($fixtures = null)
24+
{
25+
$this->migrate();
26+
parent::loadFixtures($fixtures);
27+
}
28+
}

0 commit comments

Comments
 (0)