Skip to content

Commit

Permalink
Environment setup for the async data tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
programarivm committed Oct 5, 2024
1 parent 816632b commit 6e1cd12
Show file tree
Hide file tree
Showing 14 changed files with 91 additions and 77 deletions.
8 changes: 4 additions & 4 deletions src/Command/Data/AutocompleteBlackAsyncTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ class AutocompleteBlackAsyncTask extends Task
{
private array $params;

private array $conf;
private array $env;

private Db $db;

public function __construct(array $params, array $conf)
public function __construct(array $params, array $env)
{
$this->params = $params;
$this->conf = $conf;
$this->env = $env;
}

public function configure()
{
$this->db = new Db($this->conf);
$this->db = new Db($this->env['db']);
}

public function run()
Expand Down
16 changes: 9 additions & 7 deletions src/Command/Data/AutocompleteBlackCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ public function run(AbstractSocket $socket, array $argv, int $id)
{
$params = json_decode(stripslashes($argv[1]), true);

$conf = [
'driver' => $_ENV['DB_DRIVER'],
'host' => $_ENV['DB_HOST'],
'database' => $_ENV['DB_DATABASE'],
'username' => $_ENV['DB_USERNAME'],
'password' => $_ENV['DB_PASSWORD'],
$env = [
'db' => [
'driver' => $_ENV['DB_DRIVER'],
'host' => $_ENV['DB_HOST'],
'database' => $_ENV['DB_DATABASE'],
'username' => $_ENV['DB_USERNAME'],
'password' => $_ENV['DB_PASSWORD'],
],
];

$this->pool->add(new AutocompleteBlackAsyncTask($params, $conf))
$this->pool->add(new AutocompleteBlackAsyncTask($params, $env))
->then(function ($result) use ($socket, $id) {
return $socket->getClientStorage()->send([$id], [
$this->name => $result,
Expand Down
8 changes: 4 additions & 4 deletions src/Command/Data/AutocompleteEventAsyncTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ class AutocompleteEventAsyncTask extends Task
{
private array $params;

private array $conf;
private array $env;

private Db $db;

public function __construct(array $params, array $conf)
public function __construct(array $params, array $env)
{
$this->params = $params;
$this->conf = $conf;
$this->env = $env;
}

public function configure()
{
$this->db = new Db($this->conf);
$this->db = new Db($this->env['db']);
}

public function run()
Expand Down
16 changes: 9 additions & 7 deletions src/Command/Data/AutocompleteEventCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ public function run(AbstractSocket $socket, array $argv, int $id)
{
$params = json_decode(stripslashes($argv[1]), true);

$conf = [
'driver' => $_ENV['DB_DRIVER'],
'host' => $_ENV['DB_HOST'],
'database' => $_ENV['DB_DATABASE'],
'username' => $_ENV['DB_USERNAME'],
'password' => $_ENV['DB_PASSWORD'],
$env = [
'db' => [
'driver' => $_ENV['DB_DRIVER'],
'host' => $_ENV['DB_HOST'],
'database' => $_ENV['DB_DATABASE'],
'username' => $_ENV['DB_USERNAME'],
'password' => $_ENV['DB_PASSWORD'],
],
];

$this->pool->add(new AutocompleteEventAsyncTask($params, $conf))
$this->pool->add(new AutocompleteEventAsyncTask($params, $env))
->then(function ($result) use ($socket, $id) {
return $socket->getClientStorage()->send([$id], [
$this->name => $result,
Expand Down
8 changes: 4 additions & 4 deletions src/Command/Data/AutocompleteWhiteAsyncTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ class AutocompleteWhiteAsyncTask extends Task
{
private array $params;

private array $conf;
private array $env;

private Db $db;

public function __construct(array $params, array $conf)
public function __construct(array $params, array $env)
{
$this->params = $params;
$this->conf = $conf;
$this->env = $env;
}

public function configure()
{
$this->db = new Db($this->conf);
$this->db = new Db($this->env['db']);
}

public function run()
Expand Down
16 changes: 9 additions & 7 deletions src/Command/Data/AutocompleteWhiteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ public function run(AbstractSocket $socket, array $argv, int $id)
{
$params = json_decode(stripslashes($argv[1]), true);

$conf = [
'driver' => $_ENV['DB_DRIVER'],
'host' => $_ENV['DB_HOST'],
'database' => $_ENV['DB_DATABASE'],
'username' => $_ENV['DB_USERNAME'],
'password' => $_ENV['DB_PASSWORD'],
$env = [
'db' => [
'driver' => $_ENV['DB_DRIVER'],
'host' => $_ENV['DB_HOST'],
'database' => $_ENV['DB_DATABASE'],
'username' => $_ENV['DB_USERNAME'],
'password' => $_ENV['DB_PASSWORD'],
],
];

$this->pool->add(new AutocompleteWhiteAsyncTask($params, $conf))
$this->pool->add(new AutocompleteWhiteAsyncTask($params, $env))
->then(function ($result) use ($socket, $id) {
return $socket->getClientStorage()->send([$id], [
$this->name => $result,
Expand Down
8 changes: 4 additions & 4 deletions src/Command/Data/RankingAsyncTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@

class RankingAsyncTask extends Task
{
private array $conf;
private array $env;

private Db $db;

public function __construct(array $conf)
public function __construct(array $env)
{
$this->conf = $conf;
$this->env = $env;
}

public function configure()
{
$this->db = new Db($this->conf);
$this->db = new Db($this->env['db']);
}

public function run()
Expand Down
16 changes: 9 additions & 7 deletions src/Command/Data/RankingCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ public function validate(array $argv)

public function run(AbstractSocket $socket, array $argv, int $id)
{
$conf = [
'driver' => $_ENV['DB_DRIVER'],
'host' => $_ENV['DB_HOST'],
'database' => $_ENV['DB_DATABASE'],
'username' => $_ENV['DB_USERNAME'],
'password' => $_ENV['DB_PASSWORD'],
$env = [
'db' => [
'driver' => $_ENV['DB_DRIVER'],
'host' => $_ENV['DB_HOST'],
'database' => $_ENV['DB_DATABASE'],
'username' => $_ENV['DB_USERNAME'],
'password' => $_ENV['DB_PASSWORD'],
],
];

$this->pool->add(new RankingAsyncTask($conf))
$this->pool->add(new RankingAsyncTask($env))
->then(function ($result) use ($socket, $id) {
return $socket->getClientStorage()->send([$id], [
$this->name => $result,
Expand Down
8 changes: 4 additions & 4 deletions src/Command/Data/ResultEventAsyncTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ class ResultEventAsyncTask extends Task

private array $params;

private array $conf;
private array $env;

private Db $db;

public function __construct(array $params, array $conf)
public function __construct(array $params, array $env)
{
$this->params = $params;
$this->conf = $conf;
$this->env = $env;
}

public function configure()
{
$this->db = new Db($this->conf);
$this->db = new Db($this->env['db']);
}

public function run()
Expand Down
16 changes: 9 additions & 7 deletions src/Command/Data/ResultEventCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ public function run(AbstractSocket $socket, array $argv, int $id)
{
$params = json_decode(stripslashes($argv[1]), true);

$conf = [
'driver' => $_ENV['DB_DRIVER'],
'host' => $_ENV['DB_HOST'],
'database' => $_ENV['DB_DATABASE'],
'username' => $_ENV['DB_USERNAME'],
'password' => $_ENV['DB_PASSWORD'],
$env = [
'db' => [
'driver' => $_ENV['DB_DRIVER'],
'host' => $_ENV['DB_HOST'],
'database' => $_ENV['DB_DATABASE'],
'username' => $_ENV['DB_USERNAME'],
'password' => $_ENV['DB_PASSWORD'],
],
];

$this->pool->add(new ResultEventAsyncTask($params, $conf))
$this->pool->add(new ResultEventAsyncTask($params, $env))
->then(function ($result) use ($socket, $id) {
return $socket->getClientStorage()->send([$id], [
$this->name => $result,
Expand Down
8 changes: 4 additions & 4 deletions src/Command/Data/ResultPlayerAsyncTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ class ResultPlayerAsyncTask extends Task

private array $params;

private array $conf;
private array $env;

private Db $db;

public function __construct(array $params, array $conf)
public function __construct(array $params, array $env)
{
$this->params = $params;
$this->conf = $conf;
$this->env = $env;
}

public function configure()
{
$this->db = new Db($this->conf);
$this->db = new Db($this->env['db']);
}

public function run()
Expand Down
16 changes: 9 additions & 7 deletions src/Command/Data/ResultPlayerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ public function run(AbstractSocket $socket, array $argv, int $id)
{
$params = json_decode(stripslashes($argv[1]), true);

$conf = [
'driver' => $_ENV['DB_DRIVER'],
'host' => $_ENV['DB_HOST'],
'database' => $_ENV['DB_DATABASE'],
'username' => $_ENV['DB_USERNAME'],
'password' => $_ENV['DB_PASSWORD'],
$env = [
'db' => [
'driver' => $_ENV['DB_DRIVER'],
'host' => $_ENV['DB_HOST'],
'database' => $_ENV['DB_DATABASE'],
'username' => $_ENV['DB_USERNAME'],
'password' => $_ENV['DB_PASSWORD'],
],
];

$this->pool->add(new ResultPlayerAsyncTask($params, $conf))
$this->pool->add(new ResultPlayerAsyncTask($params, $env))
->then(function ($result) use ($socket, $id) {
return $socket->getClientStorage()->send([$id], [
$this->name => $result,
Expand Down
8 changes: 4 additions & 4 deletions src/Command/Data/SearchAsyncTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ class SearchAsyncTask extends Task

private array $params;

private array $conf;
private array $env;

private Db $db;

public function __construct(array $params, array $conf)
public function __construct(array $params, array $env)
{
$this->params = $params;
$this->conf = $conf;
$this->env = $env;
}

public function configure()
{
$this->db = new Db($this->conf);
$this->db = new Db($this->env['db']);
}

public function run()
Expand Down
16 changes: 9 additions & 7 deletions src/Command/Data/SearchCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ public function run(AbstractSocket $socket, array $argv, int $id)
{
$params = json_decode(stripslashes($argv[1]), true);

$conf = [
'driver' => $_ENV['DB_DRIVER'],
'host' => $_ENV['DB_HOST'],
'database' => $_ENV['DB_DATABASE'],
'username' => $_ENV['DB_USERNAME'],
'password' => $_ENV['DB_PASSWORD'],
$env = [
'db' => [
'driver' => $_ENV['DB_DRIVER'],
'host' => $_ENV['DB_HOST'],
'database' => $_ENV['DB_DATABASE'],
'username' => $_ENV['DB_USERNAME'],
'password' => $_ENV['DB_PASSWORD'],
],
];

$this->pool->add(new SearchAsyncTask($params, $conf), 81920)
$this->pool->add(new SearchAsyncTask($params, $env), 81920)
->then(function ($result) use ($socket, $id) {
return $socket->getClientStorage()->send([$id], [
$this->name => $result,
Expand Down

0 comments on commit 6e1cd12

Please sign in to comment.