NEW: Queue managing with DB2 ODBC connections

This commit is contained in:
Maxime Rault 2020-09-24 18:01:54 +02:00
parent 5c6bef7fa0
commit 8ee8a02237
16 changed files with 99 additions and 49 deletions

View File

@ -16,20 +16,20 @@
}
],
"require": {
"php": "^7.2.5",
"illuminate/database": "^7.0"
"php": "^7.2",
"illuminate/database": "^6.0"
},
"require-dev": {
},
"autoload": {
"psr-4": {
"Cooperl\\Database\\DB2\\": "src/"
"Cooperl\\DB2\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"Cooperl\\Database\\DB2\\DB2ServiceProvider"
"Cooperl\\DB2\\DB2ServiceProvider"
]
}
}

View File

@ -1,18 +1,21 @@
<?php
namespace Cooperl\Database\DB2;
namespace Cooperl\DB2;
use Illuminate\Foundation\Application as LaravelApplication;
use Laravel\Lumen\Application as LumenApplication;
use Cooperl\Database\DB2\Connectors\ODBCConnector;
use Cooperl\Database\DB2\Connectors\IBMConnector;
use Cooperl\Database\DB2\Connectors\ODBCZOSConnector;
use Cooperl\DB2\Database\DB2Connection;
use Cooperl\DB2\Database\Connectors\ODBCConnector;
use Cooperl\DB2\Database\Connectors\IBMConnector;
use Cooperl\DB2\Database\Connectors\ODBCZOSConnector;
use Cooperl\DB2\Queue\DB2Connector;
use Illuminate\Queue\QueueManager;
use Illuminate\Support\ServiceProvider;
/**
* Class DB2ServiceProvider
*
* @package Cooperl\Database\DB2
* @package Cooperl\DB2\Database
*/
class DB2ServiceProvider extends ServiceProvider
{
@ -84,6 +87,17 @@ class DB2ServiceProvider extends ServiceProvider
return new DB2Connection($db2Connection, $config["database"], $config["prefix"], $config);
});
}
$this->app->extend(
'queue',
function (QueueManager $queueManager) {
$queueManager->addConnector('db2_odbc', function () {
return new DB2Connector($this->app['db']);
});
return $queueManager;
}
);
}
/**

View File

@ -1,6 +1,6 @@
<?php
namespace Cooperl\Database\DB2\Connectors;
namespace Cooperl\DB2\Database\Connectors;
use Illuminate\Database\Connectors\Connector;
use Illuminate\Database\Connectors\ConnectorInterface;
@ -8,7 +8,7 @@ use Illuminate\Database\Connectors\ConnectorInterface;
/**
* Class IBMConnector
*
* @package Cooperl\Database\DB2\Connectors
* @package Cooperl\DB2\Database\Connectors
*/
class DB2Connector extends Connector implements ConnectorInterface
{

View File

@ -1,11 +1,11 @@
<?php
namespace Cooperl\Database\DB2\Connectors;
namespace Cooperl\DB2\Database\Connectors;
/**
* Class IBMConnector
*
* @package Cooperl\Database\DB2\Connectors
* @package Cooperl\DB2\Database\Connectors
*/
class IBMConnector extends DB2Connector
{

View File

@ -1,11 +1,11 @@
<?php
namespace Cooperl\Database\DB2\Connectors;
namespace Cooperl\DB2\Database\Connectors;
/**
* Class ODBCConnector
*
* @package Cooperl\Database\DB2\Connectors
* @package Cooperl\DB2\Database\Connectors
*/
class ODBCConnector extends DB2Connector
{

View File

@ -1,11 +1,11 @@
<?php
namespace Cooperl\Database\DB2\Connectors;
namespace Cooperl\DB2\Database\Connectors;
/**
* Class ODBCZOSConnector
*
* @package Cooperl\Database\DB2\Connectors
* @package Cooperl\DB2\Database\Connectors
*/
class ODBCZOSConnector extends ODBCConnector
{

View File

@ -1,22 +1,22 @@
<?php
namespace Cooperl\Database\DB2;
namespace Cooperl\DB2\Database;
use PDO;
use Illuminate\Database\Connection;
use Cooperl\Database\DB2\Schema\Builder;
use Cooperl\Database\DB2\Query\Processors\DB2Processor;
use Cooperl\Database\DB2\Query\Processors\DB2ZOSProcessor;
use Cooperl\Database\DB2\Query\Grammars\DB2Grammar as QueryGrammar;
use Cooperl\Database\DB2\Schema\Grammars\DB2Grammar as SchemaGrammar;
use Cooperl\Database\DB2\Schema\Grammars\DB2ExpressCGrammar;
use Cooperl\DB2\Database\Schema\Builder;
use Cooperl\DB2\Database\Query\Processors\DB2Processor;
use Cooperl\DB2\Database\Query\Processors\DB2ZOSProcessor;
use Cooperl\DB2\Database\Query\Grammars\DB2Grammar as QueryGrammar;
use Cooperl\DB2\Database\Schema\Grammars\DB2Grammar as SchemaGrammar;
use Cooperl\DB2\Database\Schema\Grammars\DB2ExpressCGrammar;
/**
* Class DB2Connection
*
* @package Cooperl\Database\DB2
* @package Cooperl\DB2\Database
*/
class DB2Connection extends Connection
{
@ -86,7 +86,7 @@ class DB2Connection extends Connection
/**
* Get a schema builder instance for the connection.
*
* @return \Cooperl\Database\DB2\Schema\Builder
* @return \Cooperl\DB2\Database\Schema\Builder
*/
public function getSchemaBuilder()
{
@ -133,7 +133,7 @@ class DB2Connection extends Connection
/**
* Get the default post processor instance.
*
* @return \Cooperl\Database\DB2\Query\Processors\DB2Processor|\Cooperl\Database\DB2\Query\Processors\DB2ZOSProcessor
* @return \Cooperl\DB2\Database\Query\Processors\DB2Processor|\Cooperl\DB2\Database\Query\Processors\DB2ZOSProcessor
*/
protected function getDefaultPostProcessor()
{

View File

@ -1,6 +1,6 @@
<?php
namespace Cooperl\Database\DB2\Query\Grammars;
namespace Cooperl\DB2\Database\Query\Grammars;
use Illuminate\Database\Query\Grammars\Grammar;
use Illuminate\Database\Query\Builder;
@ -8,7 +8,7 @@ use Illuminate\Database\Query\Builder;
/**
* Class DB2Grammar
*
* @package Cooperl\Database\DB2\Query\Grammars
* @package Cooperl\DB2\Database\Query\Grammars
*/
class DB2Grammar extends Grammar
{

View File

@ -1,15 +1,15 @@
<?php
namespace Cooperl\Database\DB2\Query\Processors;
namespace Cooperl\DB2\Database\Query\Processors;
use Illuminate\Database\Query\Builder;
use Illuminate\Database\Query\Processors\Processor;
use Cooperl\Database\DB2\Query\Grammars\DB2Grammar;
use Cooperl\DB2\Database\Query\Grammars\DB2Grammar;
/**
* Class DB2Processor
*
* @package Cooperl\Database\DB2\Query\Processors
* @package Cooperl\DB2\Database\Query\Processors
*/
class DB2Processor extends Processor
{

View File

@ -1,15 +1,15 @@
<?php
namespace Cooperl\Database\DB2\Query\Processors;
namespace Cooperl\DB2\Database\Query\Processors;
use Illuminate\Database\Query\Builder;
use Illuminate\Database\Query\Processors\Processor;
use Cooperl\Database\DB2\Query\Grammars\DB2Grammar;
use Cooperl\DB2\Database\Query\Grammars\DB2Grammar;
/**
* Class DB2ZOSProcessor
*
* @package Cooperl\Database\DB2\Query\Processors
* @package Cooperl\DB2\Database\Query\Processors
*/
class DB2ZOSProcessor extends Processor
{

View File

@ -1,6 +1,6 @@
<?php
namespace Cooperl\Database\DB2\Schema;
namespace Cooperl\DB2\Database\Schema;
use Illuminate\Database\Connection;
use Illuminate\Database\Schema\Grammars\Grammar;
@ -8,7 +8,7 @@ use Illuminate\Database\Schema\Grammars\Grammar;
/**
* Class Blueprint
*
* @package Cooperl\Database\DB2\Schema
* @package Cooperl\DB2\Database\Schema
*/
class Blueprint extends \Illuminate\Database\Schema\Blueprint
{

View File

@ -1,6 +1,6 @@
<?php
namespace Cooperl\Database\DB2\Schema;
namespace Cooperl\DB2\Database\Schema;
use Closure;
use Illuminate\Database\Schema\Blueprint;
@ -8,7 +8,7 @@ use Illuminate\Database\Schema\Blueprint;
/**
* Class Builder
*
* @package Cooperl\Database\DB2\Schema
* @package Cooperl\DB2\Database\Schema
*/
class Builder extends \Illuminate\Database\Schema\Builder
{
@ -76,7 +76,7 @@ class Builder extends \Illuminate\Database\Schema\Builder
* @param string $table
* @param \Closure $callback
*
* @return \Cooperl\Database\DB2\Schema\Blueprint
* @return \Cooperl\DB2\Database\Schema\Blueprint
*/
protected function createBlueprint($table, Closure $callback = null)
{
@ -84,6 +84,6 @@ class Builder extends \Illuminate\Database\Schema\Builder
return call_user_func($this->resolver, $table, $callback);
}
return new \Cooperl\Database\DB2\Schema\Blueprint($table, $callback);
return new \Cooperl\DB2\Database\Schema\Blueprint($table, $callback);
}
}

View File

@ -1,12 +1,6 @@
<?php
namespace Cooperl\Database\DB2\Schema\Grammars;
use Illuminate\Database\Query\Expression;
use Illuminate\Support\Fluent;
use Illuminate\Database\Connection;
use Illuminate\Database\Schema\Grammars\Grammar;
use Illuminate\Database\Schema\Blueprint;
namespace Cooperl\DB2\Database\Schema\Grammars;
class DB2ExpressCGrammar extends DB2Grammar
{

View File

@ -1,6 +1,6 @@
<?php
namespace Cooperl\Database\DB2\Schema\Grammars;
namespace Cooperl\DB2\Database\Schema\Grammars;
use Illuminate\Database\Query\Expression;
use Illuminate\Support\Fluent;

View File

@ -0,0 +1,24 @@
<?php
namespace Cooperl\DB2\Queue;
use Illuminate\Queue\Connectors\DatabaseConnector;
class DB2Connector extends DatabaseConnector
{
/**
* Establish a queue connection.
*
* @param array $config
* @return \Illuminate\Contracts\Queue\Queue
*/
public function connect(array $config)
{
return new DB2Queue(
$this->connections->connection($config['connection'] ?? null),
$config['table'],
$config['queue'],
$config['retry_after'] ?? 60
);
}
}

18
src/Queue/DB2Queue.php Normal file
View File

@ -0,0 +1,18 @@
<?php
namespace Cooperl\DB2\Queue;
use Illuminate\Queue\DatabaseQueue;
class DB2Queue extends DatabaseQueue
{
/**
* {@inheritdoc}
*/
public function getLockForPopping()
{
return true;
}
}