diff options
30 files changed, 3 insertions, 658 deletions
diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/--github/ISSUE_TEMPLATE/bug_report.md index 448a1aa4..448a1aa4 100755 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/--github/ISSUE_TEMPLATE/bug_report.md diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/--github/ISSUE_TEMPLATE/feature_request.md index 470dd474..470dd474 100755 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/--github/ISSUE_TEMPLATE/feature_request.md diff --git a/.github/dependabot.yml b/--github/dependabot.yml index 2c561205..2c561205 100644 --- a/.github/dependabot.yml +++ b/--github/dependabot.yml diff --git a/.github/pull_request_template.md b/--github/pull_request_template.md index c3467850..c3467850 100644 --- a/.github/pull_request_template.md +++ b/--github/pull_request_template.md diff --git a/.github/workflows/codeql-analysis.yml b/--github/workflows/codeql-analysis.yml index dc4a2349..dc4a2349 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/--github/workflows/codeql-analysis.yml diff --git a/.github/workflows/linters.yml b/--github/workflows/linters.yml index cee7085c..cee7085c 100644 --- a/.github/workflows/linters.yml +++ b/--github/workflows/linters.yml diff --git a/.github/workflows/linux.yml b/--github/workflows/linux.yml index 62987771..62987771 100644 --- a/.github/workflows/linux.yml +++ b/--github/workflows/linux.yml diff --git a/.github/workflows/windows.yml b/--github/workflows/windows.yml index f23f9b5d..f23f9b5d 100644 --- a/.github/workflows/windows.yml +++ b/--github/workflows/windows.yml diff --git a/.dockerignore b/.dockerignore index bfa82a3d..c28921c4 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,9 +2,9 @@ .git .gitignore .editorconfig -.github +--github /src /tests /bin composer.json -vendor_php
\ No newline at end of file +vendor_php diff --git a/plugins/jobs/oooold/tests/.rr.yaml b/plugins/jobs/oooold/tests/.rr.yaml deleted file mode 100644 index 2fd323db..00000000 --- a/plugins/jobs/oooold/tests/.rr.yaml +++ /dev/null @@ -1,63 +0,0 @@ -jobs: - # worker pool configuration - workers: - command: "php consumer.php" - pool: - numWorkers: 4 - - # rabbitmq and similar servers - amqp: - addr: amqp://guest:guest@localhost:5672/ - - # beanstalk configuration - beanstalk: - addr: tcp://localhost:11300 - - # amazon sqs configuration - sqs: - key: api-key - secret: api-secret - region: us-west-1 - endpoint: http://localhost:9324 - - # job destinations and options - dispatch: - spiral-jobs-tests-amqp-*.pipeline: amqp - spiral-jobs-tests-local-*.pipeline: local - spiral-jobs-tests-beanstalk-*.pipeline: beanstalk - spiral-jobs-tests-sqs-*.pipeline: sqs - - # list of broker pipelines associated with endpoints - pipelines: - local: - broker: ephemeral - - amqp: - broker: amqp - queue: default - - beanstalk: - broker: beanstalk - tube: default - - sqs: - broker: sqs - queue: default - declare: - MessageRetentionPeriod: 86400 - - # list of pipelines to be consumed by the server, keep empty if you want to start consuming manually - consume: ["local", "amqp", "beanstalk", "sqs"] - -metrics: - address: localhost:2112 - -# monitors rr server(s) -limit: - interval: 1 - services: - jobs: - maxMemory: 100 - TTL: 0 - idleTTL: 0 - execTTL: 60
\ No newline at end of file diff --git a/plugins/jobs/oooold/tests/Jobs/Amqp/BrokerTest.php b/plugins/jobs/oooold/tests/Jobs/Amqp/BrokerTest.php deleted file mode 100644 index 637c14d6..00000000 --- a/plugins/jobs/oooold/tests/Jobs/Amqp/BrokerTest.php +++ /dev/null @@ -1,20 +0,0 @@ -<?php - -/** - * Spiral Framework. - * - * @license MIT - * @author Anton Titov (Wolfy-J) - */ - -declare(strict_types=1); - -namespace Spiral\Jobs\Tests\Amqp; - -use Spiral\Jobs\Tests\BaseTest; - -class BrokerTest extends BaseTest -{ - public const JOB = Job::class; - public const ERROR_JOB = ErrorJob::class; -} diff --git a/plugins/jobs/oooold/tests/Jobs/Amqp/ErrorJob.php b/plugins/jobs/oooold/tests/Jobs/Amqp/ErrorJob.php deleted file mode 100644 index 82b6e7e0..00000000 --- a/plugins/jobs/oooold/tests/Jobs/Amqp/ErrorJob.php +++ /dev/null @@ -1,22 +0,0 @@ -<?php - -/** - * Spiral Framework. - * - * @license MIT - * @author Anton Titov (Wolfy-J) - */ - -declare(strict_types=1); - -namespace Spiral\Jobs\Tests\Amqp; - -use Spiral\Jobs\JobHandler; - -class ErrorJob extends JobHandler -{ - public function invoke(string $id): void - { - throw new \Error('something is wrong'); - } -} diff --git a/plugins/jobs/oooold/tests/Jobs/Amqp/Job.php b/plugins/jobs/oooold/tests/Jobs/Amqp/Job.php deleted file mode 100644 index 2c6ad819..00000000 --- a/plugins/jobs/oooold/tests/Jobs/Amqp/Job.php +++ /dev/null @@ -1,26 +0,0 @@ -<?php - -/** - * Spiral Framework. - * - * @license MIT - * @author Anton Titov (Wolfy-J) - */ - -declare(strict_types=1); - -namespace Spiral\Jobs\Tests\Amqp; - -use Spiral\Jobs\JobHandler; - -class Job extends JobHandler -{ - public const JOB_FILE = __DIR__ . '/../../local.job'; - - public function invoke(string $id, array $payload): void - { - file_put_contents(self::JOB_FILE, json_encode( - $payload + compact('id') - )); - } -} diff --git a/plugins/jobs/oooold/tests/Jobs/BaseTest.php b/plugins/jobs/oooold/tests/Jobs/BaseTest.php deleted file mode 100644 index 67f280b5..00000000 --- a/plugins/jobs/oooold/tests/Jobs/BaseTest.php +++ /dev/null @@ -1,115 +0,0 @@ -<?php - -/** - * Spiral Framework. - * - * @license MIT - * @author Anton Titov (Wolfy-J) - */ - -declare(strict_types=1); - -namespace Spiral\Jobs\Tests; - -use PHPUnit\Framework\TestCase; -use Spiral\Core\Container; -use Spiral\Goridge\RPC; -use Spiral\Goridge\SocketRelay; -use Spiral\Jobs\Options; -use Spiral\Jobs\Queue; -use Spiral\Jobs\Registry\ContainerRegistry; - -abstract class BaseTest extends TestCase -{ - public const JOB = null; - public const ERROR_JOB = null; - - private $job; - private $errorJob; - - public function setUp(): void - { - $this->job = static::JOB; - $this->errorJob = static::ERROR_JOB; - } - - protected function tearDown(): void - { - if (file_exists((static::JOB)::JOB_FILE)) { - unlink((static::JOB)::JOB_FILE); - } - } - - public function testJob(): void - { - $jobs = $this->makeJobs(); - - $id = $jobs->push($this->job, ['data' => 100]); - - $this->assertNotEmpty($id); - - $this->waitForJob(); - $this->assertFileExists($this->job::JOB_FILE); - - $data = json_decode(file_get_contents($this->job::JOB_FILE), true); - $this->assertSame($id, $data['id']); - $this->assertSame(100, $data['data']); - } - - public function testErrorJob(): void - { - $jobs = $this->makeJobs(); - - $id = $jobs->push($this->errorJob, ['data' => 100]); - $this->assertNotEmpty($id); - } - - public function testDelayJob(): void - { - $jobs = $this->makeJobs(); - - $id = $jobs->push($this->job, ['data' => 100], Options::delayed(1)); - - $this->assertNotEmpty($id); - - $this->assertTrue($this->waitForJob() > 1); - $this->assertFileExists($this->job::JOB_FILE); - - $data = json_decode(file_get_contents($this->job::JOB_FILE), true); - $this->assertSame($id, $data['id']); - $this->assertSame(100, $data['data']); - } - - /** - * @expectedException \Spiral\Jobs\Exception\JobException - */ - public function testConnectionException(): void - { - $jobs = new Queue( - new RPC(new SocketRelay('localhost', 6002)), - new ContainerRegistry(new Container()) - ); - - $jobs->push($this->job, ['data' => 100]); - } - - public function makeJobs(): Queue - { - return new Queue( - new RPC(new SocketRelay('localhost', 6001)), - new ContainerRegistry(new Container()) - ); - } - - private function waitForJob(): float - { - $start = microtime(true); - $try = 0; - while (!file_exists($this->job::JOB_FILE) && $try < 10) { - usleep(250000); - $try++; - } - - return microtime(true) - $start; - } -} diff --git a/plugins/jobs/oooold/tests/Jobs/Beanstalk/BrokerTest.php b/plugins/jobs/oooold/tests/Jobs/Beanstalk/BrokerTest.php deleted file mode 100644 index d1ea4682..00000000 --- a/plugins/jobs/oooold/tests/Jobs/Beanstalk/BrokerTest.php +++ /dev/null @@ -1,20 +0,0 @@ -<?php - -/** - * Spiral Framework. - * - * @license MIT - * @author Anton Titov (Wolfy-J) - */ - -declare(strict_types=1); - -namespace Spiral\Jobs\Tests\Beanstalk; - -use Spiral\Jobs\Tests\BaseTest; - -class BrokerTest extends BaseTest -{ - public const JOB = Job::class; - public const ERROR_JOB = ErrorJob::class; -} diff --git a/plugins/jobs/oooold/tests/Jobs/Beanstalk/ErrorJob.php b/plugins/jobs/oooold/tests/Jobs/Beanstalk/ErrorJob.php deleted file mode 100644 index c4349871..00000000 --- a/plugins/jobs/oooold/tests/Jobs/Beanstalk/ErrorJob.php +++ /dev/null @@ -1,22 +0,0 @@ -<?php - -/** - * Spiral Framework. - * - * @license MIT - * @author Anton Titov (Wolfy-J) - */ - -declare(strict_types=1); - -namespace Spiral\Jobs\Tests\Beanstalk; - -use Spiral\Jobs\JobHandler; - -class ErrorJob extends JobHandler -{ - public function invoke(string $id): void - { - throw new \Error('something is wrong'); - } -} diff --git a/plugins/jobs/oooold/tests/Jobs/Beanstalk/Job.php b/plugins/jobs/oooold/tests/Jobs/Beanstalk/Job.php deleted file mode 100644 index f8bd541a..00000000 --- a/plugins/jobs/oooold/tests/Jobs/Beanstalk/Job.php +++ /dev/null @@ -1,26 +0,0 @@ -<?php - -/** - * Spiral Framework. - * - * @license MIT - * @author Anton Titov (Wolfy-J) - */ - -declare(strict_types=1); - -namespace Spiral\Jobs\Tests\Beanstalk; - -use Spiral\Jobs\JobHandler; - -class Job extends JobHandler -{ - public const JOB_FILE = __DIR__ . '/../../local.job'; - - public function invoke(string $id, array $payload): void - { - file_put_contents(self::JOB_FILE, json_encode( - $payload + compact('id') - )); - } -} diff --git a/plugins/jobs/oooold/tests/Jobs/Local/BrokerTest.php b/plugins/jobs/oooold/tests/Jobs/Local/BrokerTest.php deleted file mode 100644 index 9ba83de6..00000000 --- a/plugins/jobs/oooold/tests/Jobs/Local/BrokerTest.php +++ /dev/null @@ -1,20 +0,0 @@ -<?php - -/** - * Spiral Framework. - * - * @license MIT - * @author Anton Titov (Wolfy-J) - */ - -declare(strict_types=1); - -namespace Spiral\Jobs\Tests\Local; - -use Spiral\Jobs\Tests\BaseTest; - -class BrokerTest extends BaseTest -{ - public const JOB = Job::class; - public const ERROR_JOB = ErrorJob::class; -} diff --git a/plugins/jobs/oooold/tests/Jobs/Local/ErrorJob.php b/plugins/jobs/oooold/tests/Jobs/Local/ErrorJob.php deleted file mode 100644 index 70b1365b..00000000 --- a/plugins/jobs/oooold/tests/Jobs/Local/ErrorJob.php +++ /dev/null @@ -1,22 +0,0 @@ -<?php - -/** - * Spiral Framework. - * - * @license MIT - * @author Anton Titov (Wolfy-J) - */ - -declare(strict_types=1); - -namespace Spiral\Jobs\Tests\Local; - -use Spiral\Jobs\JobHandler; - -class ErrorJob extends JobHandler -{ - public function invoke(string $id): void - { - throw new \Error('something is wrong'); - } -} diff --git a/plugins/jobs/oooold/tests/Jobs/Local/Job.php b/plugins/jobs/oooold/tests/Jobs/Local/Job.php deleted file mode 100644 index 2f5803c8..00000000 --- a/plugins/jobs/oooold/tests/Jobs/Local/Job.php +++ /dev/null @@ -1,26 +0,0 @@ -<?php - -/** - * Spiral Framework. - * - * @license MIT - * @author Anton Titov (Wolfy-J) - */ - -declare(strict_types=1); - -namespace Spiral\Jobs\Tests\Local; - -use Spiral\Jobs\JobHandler; - -class Job extends JobHandler -{ - public const JOB_FILE = __DIR__ . '/../../local.job'; - - public function invoke(string $id, array $payload): void - { - file_put_contents(self::JOB_FILE, json_encode( - $payload + compact('id') - )); - } -} diff --git a/plugins/jobs/oooold/tests/Jobs/OptionsTest.php b/plugins/jobs/oooold/tests/Jobs/OptionsTest.php deleted file mode 100644 index 5d00794e..00000000 --- a/plugins/jobs/oooold/tests/Jobs/OptionsTest.php +++ /dev/null @@ -1,34 +0,0 @@ -<?php - -/** - * Spiral Framework. - * - * @license MIT - * @author Anton Titov (Wolfy-J) - */ - -declare(strict_types=1); - -namespace Spiral\Jobs\Tests; - -use PHPUnit\Framework\TestCase; -use Spiral\Jobs\Options; - -class OptionsTest extends TestCase -{ - public function testDelay(): void - { - $o = new Options(); - $this->assertNull($o->getDelay()); - $o = $o->withDelay(10); - $this->assertSame(10, $o->getDelay()); - } - - public function testPipeline(): void - { - $o = new Options(); - $this->assertNull($o->getPipeline()); - $o = $o->withPipeline('custom'); - $this->assertSame('custom', $o->getPipeline()); - } -} diff --git a/plugins/jobs/oooold/tests/Jobs/RegistryTest.php b/plugins/jobs/oooold/tests/Jobs/RegistryTest.php deleted file mode 100644 index 7abd75f7..00000000 --- a/plugins/jobs/oooold/tests/Jobs/RegistryTest.php +++ /dev/null @@ -1,43 +0,0 @@ -<?php - -/** - * Spiral Framework. - * - * @license MIT - * @author Anton Titov (Wolfy-J) - */ - -declare(strict_types=1); - -namespace Spiral\Jobs\Tests; - -use PHPUnit\Framework\TestCase; -use Spiral\Core\Container; -use Spiral\Jobs\Registry\ContainerRegistry; -use Spiral\Jobs\Tests\Local\Job; - -class RegistryTest extends TestCase -{ - public function testMakeJob(): void - { - $factory = new ContainerRegistry(new Container()); - - $j = $factory->getHandler('spiral.jobs.tests.local.job'); - $this->assertInstanceOf(Job::class, $j); - - $this->assertSame(json_encode(['data' => 200]), $j->serialize( - 'spiral.jobs.tests.local.job', - ['data' => 200] - )); - } - - /** - * @expectedException \Spiral\Jobs\Exception\JobException - */ - public function testMakeUndefined(): void - { - $factory = new ContainerRegistry(new Container()); - - $factory->getHandler('spiral.jobs.undefined'); - } -} diff --git a/plugins/jobs/oooold/tests/Jobs/ShortCircuitTest.php b/plugins/jobs/oooold/tests/Jobs/ShortCircuitTest.php deleted file mode 100644 index c3306385..00000000 --- a/plugins/jobs/oooold/tests/Jobs/ShortCircuitTest.php +++ /dev/null @@ -1,90 +0,0 @@ -<?php - -/** - * Spiral Framework. - * - * @license MIT - * @author Anton Titov (Wolfy-J) - */ - -declare(strict_types=1); - -namespace Spiral\Jobs\Tests; - -use PHPUnit\Framework\TestCase; -use Spiral\Core\Container; -use Spiral\Jobs\Options; -use Spiral\Jobs\Registry\ContainerRegistry; -use Spiral\Jobs\ShortCircuit; -use Spiral\Jobs\Tests\Local\ErrorJob; -use Spiral\Jobs\Tests\Local\Job; - -class ShortCircuitTest extends TestCase -{ - protected function tearDown(): void - { - if (file_exists(Job::JOB_FILE)) { - unlink(Job::JOB_FILE); - } - } - - public function testLocal(): void - { - $c = new ContainerRegistry(new Container()); - $jobs = new ShortCircuit($c, $c); - - $id = $jobs->push(Job::class, ['data' => 100]); - - $this->assertNotEmpty($id); - - $this->assertFileExists(Job::JOB_FILE); - - $data = json_decode(file_get_contents(Job::JOB_FILE), true); - $this->assertSame($id, $data['id']); - $this->assertSame(100, $data['data']); - } - - public function testLocalDelayed(): void - { - $c = new ContainerRegistry(new Container()); - $jobs = new ShortCircuit($c, $c); - - $t = microtime(true); - $id = $jobs->push(Job::class, ['data' => 100], Options::delayed(1)); - - $this->assertTrue(microtime(true) - $t >= 1); - - $this->assertNotEmpty($id); - - $this->assertFileExists(Job::JOB_FILE); - - $data = json_decode(file_get_contents(Job::JOB_FILE), true); - $this->assertSame($id, $data['id']); - $this->assertSame(100, $data['data']); - } - - /** - * @expectedException \Spiral\Jobs\Exception\JobException - */ - public function testError(): void - { - $c = new ContainerRegistry(new Container()); - $jobs = new ShortCircuit($c, $c); - $jobs->push(ErrorJob::class); - } - - public function testLocalDelay(): void - { - $c = new ContainerRegistry(new Container()); - $jobs = new ShortCircuit($c, $c); - - $id = $jobs->push(Job::class, ['data' => 100], Options::delayed(1)); - $this->assertNotEmpty($id); - - $this->assertFileExists(Job::JOB_FILE); - - $data = json_decode(file_get_contents(Job::JOB_FILE), true); - $this->assertSame($id, $data['id']); - $this->assertSame(100, $data['data']); - } -} diff --git a/plugins/jobs/oooold/tests/Jobs/Sqs/BrokerTest.php b/plugins/jobs/oooold/tests/Jobs/Sqs/BrokerTest.php deleted file mode 100644 index ccaa96de..00000000 --- a/plugins/jobs/oooold/tests/Jobs/Sqs/BrokerTest.php +++ /dev/null @@ -1,20 +0,0 @@ -<?php - -/** - * Spiral Framework. - * - * @license MIT - * @author Anton Titov (Wolfy-J) - */ - -declare(strict_types=1); - -namespace Spiral\Jobs\Tests\Sqs; - -use Spiral\Jobs\Tests\BaseTest; - -class BrokerTest extends BaseTest -{ - public const JOB = Job::class; - public const ERROR_JOB = ErrorJob::class; -} diff --git a/plugins/jobs/oooold/tests/Jobs/Sqs/ErrorJob.php b/plugins/jobs/oooold/tests/Jobs/Sqs/ErrorJob.php deleted file mode 100644 index 738b9f2b..00000000 --- a/plugins/jobs/oooold/tests/Jobs/Sqs/ErrorJob.php +++ /dev/null @@ -1,22 +0,0 @@ -<?php - -/** - * Spiral Framework. - * - * @license MIT - * @author Anton Titov (Wolfy-J) - */ - -declare(strict_types=1); - -namespace Spiral\Jobs\Tests\Sqs; - -use Spiral\Jobs\JobHandler; - -class ErrorJob extends JobHandler -{ - public function invoke(string $id): void - { - throw new \Error('something is wrong'); - } -} diff --git a/plugins/jobs/oooold/tests/Jobs/Sqs/Job.php b/plugins/jobs/oooold/tests/Jobs/Sqs/Job.php deleted file mode 100644 index e22483a8..00000000 --- a/plugins/jobs/oooold/tests/Jobs/Sqs/Job.php +++ /dev/null @@ -1,26 +0,0 @@ -<?php - -/** - * Spiral Framework. - * - * @license MIT - * @author Anton Titov (Wolfy-J) - */ - -declare(strict_types=1); - -namespace Spiral\Jobs\Tests\Sqs; - -use Spiral\Jobs\JobHandler; - -class Job extends JobHandler -{ - public const JOB_FILE = __DIR__ . '/../../local.job'; - - public function invoke(string $id, array $payload): void - { - file_put_contents(self::JOB_FILE, json_encode( - $payload + compact('id') - )); - } -} diff --git a/plugins/jobs/oooold/tests/bootstrap.php b/plugins/jobs/oooold/tests/bootstrap.php deleted file mode 100644 index b25fdc9d..00000000 --- a/plugins/jobs/oooold/tests/bootstrap.php +++ /dev/null @@ -1,16 +0,0 @@ -<?php - -/** - * Spiral Framework. - * - * @license MIT - * @author Anton Titov (Wolfy-J) - */ - -declare(strict_types=1); - -error_reporting(E_ALL | E_STRICT); -ini_set('display_errors', 'stderr'); - -//Composer -require dirname(__DIR__) . '/vendor_php/autoload.php'; diff --git a/plugins/jobs/oooold/tests/consumer.php b/plugins/jobs/oooold/tests/consumer.php deleted file mode 100644 index ed56edff..00000000 --- a/plugins/jobs/oooold/tests/consumer.php +++ /dev/null @@ -1,22 +0,0 @@ -<?php - -/** - * Spiral Framework. - * - * @license MIT - * @author Anton Titov (Wolfy-J) - */ - -declare(strict_types=1); - -use Spiral\Core\Container; -use Spiral\Goridge; -use Spiral\Jobs; -use Spiral\RoadRunner; - -require 'bootstrap.php'; - -$rr = new RoadRunner\Worker(new Goridge\StreamRelay(STDIN, STDOUT)); - -$consumer = new Jobs\Consumer(new Jobs\Registry\ContainerRegistry(new Container())); -$consumer->serve($rr); diff --git a/plugins/jobs/oooold/tests/docker-compose.yml b/tests/docker-compose-jobs.yml index 7b88c9cf..7b88c9cf 100644 --- a/plugins/jobs/oooold/tests/docker-compose.yml +++ b/tests/docker-compose-jobs.yml diff --git a/tests/psr-worker.php b/tests/psr-worker.php index db53eee2..de4befbc 100644 --- a/tests/psr-worker.php +++ b/tests/psr-worker.php @@ -20,7 +20,7 @@ while ($req = $psr7->waitRequest()) { try { $resp = new \Nyholm\Psr7\Response(); $resp->getBody()->write(str_repeat("hello world", 1000)); - + $psr7->respond($resp); } catch (\Throwable $e) { $psr7->getWorker()->error((string)$e); |