From 089b0e580cee9f3fea8e8fd7af5c8dec5805a0f8 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 18 Apr 2024 18:11:20 +0200 Subject: [PATCH 01/26] Updated tests to not throw warnings --- composer.json | 13 +- composer.lock | 269 +++++++++++++++++++++------------- src/Queue/Job.php | 2 +- src/Queue/Server.php | 2 +- tests/Queue/servers/tests.php | 5 +- 5 files changed, 186 insertions(+), 105 deletions(-) diff --git a/composer.json b/composer.json index 3d2dcb3..b1571ff 100644 --- a/composer.json +++ b/composer.json @@ -25,8 +25,9 @@ }, "require": { "php": ">=8.0", - "utopia-php/cli": "0.15.*", - "utopia-php/framework": "0.*.*" + "utopia-php/cli": "0.17.*", + "utopia-php/framework": "0.*.*", + "utopia-php/di": "dev-main" }, "require-dev": { "swoole/ide-helper": "4.8.8", @@ -38,5 +39,11 @@ "suggest": { "ext-swoole": "Needed to support Swoole.", "workerman/workerman": "Needed to support Workerman." - } + }, + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/utopia-php/di" + } + ] } diff --git a/composer.lock b/composer.lock index 50cd1b6..107e250 100644 --- a/composer.lock +++ b/composer.lock @@ -4,25 +4,25 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f349a46dfa6a0938eb8f5ecea04a7eb7", + "content-hash": "21e2f04315452ede5b939075405fdc84", "packages": [ { "name": "utopia-php/cli", - "version": "0.15.0", + "version": "0.17.0", "source": { "type": "git", "url": "https://github.com/utopia-php/cli.git", - "reference": "ccb7c8125ffe0254fef8f25744bfa376eb7bd0ea" + "reference": "0829fd5215afe88f53f3091cedc808da801fd1bb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/cli/zipball/ccb7c8125ffe0254fef8f25744bfa376eb7bd0ea", - "reference": "ccb7c8125ffe0254fef8f25744bfa376eb7bd0ea", + "url": "https://api.github.com/repos/utopia-php/cli/zipball/0829fd5215afe88f53f3091cedc808da801fd1bb", + "reference": "0829fd5215afe88f53f3091cedc808da801fd1bb", "shasum": "" }, "require": { "php": ">=7.4", - "utopia-php/framework": "0.*.*" + "utopia-php/framework": "0.34.*" }, "require-dev": { "laravel/pint": "1.2.*", @@ -51,54 +51,119 @@ ], "support": { "issues": "https://github.com/utopia-php/cli/issues", - "source": "https://github.com/utopia-php/cli/tree/0.15.0" + "source": "https://github.com/utopia-php/cli/tree/0.17.0" }, - "time": "2023-03-01T05:55:14+00:00" + "time": "2024-01-24T11:37:29+00:00" + }, + { + "name": "utopia-php/di", + "version": "dev-main", + "source": { + "type": "git", + "url": "https://github.com/utopia-php/di.git", + "reference": "0bb7af5693bc131f4d2ce34d3f732d41e6637679" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/utopia-php/di/zipball/0bb7af5693bc131f4d2ce34d3f732d41e6637679", + "reference": "0bb7af5693bc131f4d2ce34d3f732d41e6637679", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "laravel/pint": "^1.2", + "phpbench/phpbench": "^1.2", + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^9.5.25", + "swoole/ide-helper": "4.8.3" + }, + "default-branch": true, + "type": "library", + "autoload": { + "psr-4": { + "Utopia\\": "src/", + "Tests\\E2E\\": "tests/e2e" + } + }, + "scripts": { + "lint": [ + "vendor/bin/pint --test" + ], + "format": [ + "vendor/bin/pint" + ], + "check": [ + "vendor/bin/phpstan analyse -c phpstan.neon" + ], + "test": [ + "vendor/bin/phpunit --configuration phpunit.xml" + ] + }, + "license": [ + "MIT" + ], + "description": "A simple and lite library for managing dependency injections", + "keywords": [ + "framework", + "http", + "php", + "upf" + ], + "support": { + "source": "https://github.com/utopia-php/di/tree/main", + "issues": "https://github.com/utopia-php/di/issues" + }, + "time": "2024-04-08T22:41:41+00:00" }, { "name": "utopia-php/framework", - "version": "0.32.0", + "version": "0.34.2", "source": { "type": "git", - "url": "https://github.com/utopia-php/framework.git", - "reference": "ad6f7e6d6b38cf5bed4e3af9a1394c59d4bb9225" + "url": "https://github.com/utopia-php/http.git", + "reference": "fd126c02b78cc80678c9638f7b335dfb4a841b78" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/framework/zipball/ad6f7e6d6b38cf5bed4e3af9a1394c59d4bb9225", - "reference": "ad6f7e6d6b38cf5bed4e3af9a1394c59d4bb9225", + "url": "https://api.github.com/repos/utopia-php/http/zipball/fd126c02b78cc80678c9638f7b335dfb4a841b78", + "reference": "fd126c02b78cc80678c9638f7b335dfb4a841b78", "shasum": "" }, "require": { + "ext-swoole": "*", "php": ">=8.0" }, "require-dev": { "laravel/pint": "^1.2", "phpbench/phpbench": "^1.2", "phpstan/phpstan": "^1.10", - "phpunit/phpunit": "^9.5.25" + "phpunit/phpunit": "^9.5.25", + "swoole/ide-helper": "4.8.3" }, "type": "library", "autoload": { "psr-4": { - "Utopia\\": "src/" + "Utopia\\Http\\": "src/Http" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], - "description": "A simple, light and advanced PHP framework", + "description": "A simple, light and advanced PHP HTTP framework", "keywords": [ "framework", + "http", "php", "upf" ], "support": { - "issues": "https://github.com/utopia-php/framework/issues", - "source": "https://github.com/utopia-php/framework/tree/0.32.0" + "issues": "https://github.com/utopia-php/http/issues", + "source": "https://github.com/utopia-php/http/tree/0.34.2" }, - "time": "2023-12-26T14:18:36+00:00" + "time": "2024-02-20T11:36:56+00:00" } ], "packages-dev": [ @@ -299,25 +364,27 @@ }, { "name": "nikic/php-parser", - "version": "v4.18.0", + "version": "v5.0.2", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "1bcbb2179f97633e98bbbc87044ee2611c7d7999" + "reference": "139676794dc1e9231bf7bcd123cfc0c99182cb13" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/1bcbb2179f97633e98bbbc87044ee2611c7d7999", - "reference": "1bcbb2179f97633e98bbbc87044ee2611c7d7999", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/139676794dc1e9231bf7bcd123cfc0c99182cb13", + "reference": "139676794dc1e9231bf7bcd123cfc0c99182cb13", "shasum": "" }, "require": { + "ext-ctype": "*", + "ext-json": "*", "ext-tokenizer": "*", - "php": ">=7.0" + "php": ">=7.4" }, "require-dev": { "ircmaxell/php-yacc": "^0.0.7", - "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0" + "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0" }, "bin": [ "bin/php-parse" @@ -325,7 +392,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.9-dev" + "dev-master": "5.0-dev" } }, "autoload": { @@ -349,26 +416,27 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.18.0" + "source": "https://github.com/nikic/PHP-Parser/tree/v5.0.2" }, - "time": "2023-12-10T21:03:43+00:00" + "time": "2024-03-05T20:51:40+00:00" }, { "name": "phar-io/manifest", - "version": "2.0.3", + "version": "2.0.4", "source": { "type": "git", "url": "https://github.com/phar-io/manifest.git", - "reference": "97803eca37d319dfa7826cc2437fc020857acb53" + "reference": "54750ef60c58e43759730615a392c31c80e23176" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phar-io/manifest/zipball/97803eca37d319dfa7826cc2437fc020857acb53", - "reference": "97803eca37d319dfa7826cc2437fc020857acb53", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/54750ef60c58e43759730615a392c31c80e23176", + "reference": "54750ef60c58e43759730615a392c31c80e23176", "shasum": "" }, "require": { "ext-dom": "*", + "ext-libxml": "*", "ext-phar": "*", "ext-xmlwriter": "*", "phar-io/version": "^3.0.1", @@ -409,9 +477,15 @@ "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", "support": { "issues": "https://github.com/phar-io/manifest/issues", - "source": "https://github.com/phar-io/manifest/tree/2.0.3" + "source": "https://github.com/phar-io/manifest/tree/2.0.4" }, - "time": "2021-07-20T11:28:43+00:00" + "funding": [ + { + "url": "https://github.com/theseer", + "type": "github" + } + ], + "time": "2024-03-03T12:33:53+00:00" }, { "name": "phar-io/version", @@ -466,16 +540,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.10.50", + "version": "1.10.67", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "06a98513ac72c03e8366b5a0cb00750b487032e4" + "reference": "16ddbe776f10da6a95ebd25de7c1dbed397dc493" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/06a98513ac72c03e8366b5a0cb00750b487032e4", - "reference": "06a98513ac72c03e8366b5a0cb00750b487032e4", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/16ddbe776f10da6a95ebd25de7c1dbed397dc493", + "reference": "16ddbe776f10da6a95ebd25de7c1dbed397dc493", "shasum": "" }, "require": { @@ -518,26 +592,22 @@ { "url": "https://github.com/phpstan", "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", - "type": "tidelift" } ], - "time": "2023-12-13T10:59:42+00:00" + "time": "2024-04-16T07:22:02+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "9.2.30", + "version": "9.2.31", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "ca2bd87d2f9215904682a9cb9bb37dda98e76089" + "reference": "48c34b5d8d983006bd2adc2d0de92963b9155965" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/ca2bd87d2f9215904682a9cb9bb37dda98e76089", - "reference": "ca2bd87d2f9215904682a9cb9bb37dda98e76089", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/48c34b5d8d983006bd2adc2d0de92963b9155965", + "reference": "48c34b5d8d983006bd2adc2d0de92963b9155965", "shasum": "" }, "require": { @@ -594,7 +664,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.30" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.31" }, "funding": [ { @@ -602,7 +672,7 @@ "type": "github" } ], - "time": "2023-12-22T06:47:57+00:00" + "time": "2024-03-02T06:37:42+00:00" }, { "name": "phpunit/php-file-iterator", @@ -847,16 +917,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.6.15", + "version": "9.6.19", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "05017b80304e0eb3f31d90194a563fd53a6021f1" + "reference": "a1a54a473501ef4cdeaae4e06891674114d79db8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/05017b80304e0eb3f31d90194a563fd53a6021f1", - "reference": "05017b80304e0eb3f31d90194a563fd53a6021f1", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a1a54a473501ef4cdeaae4e06891674114d79db8", + "reference": "a1a54a473501ef4cdeaae4e06891674114d79db8", "shasum": "" }, "require": { @@ -930,7 +1000,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.15" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.19" }, "funding": [ { @@ -946,20 +1016,20 @@ "type": "tidelift" } ], - "time": "2023-12-01T16:55:19+00:00" + "time": "2024-04-05T04:35:58+00:00" }, { "name": "sebastian/cli-parser", - "version": "1.0.1", + "version": "1.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/cli-parser.git", - "reference": "442e7c7e687e42adc03470c7b668bc4b2402c0b2" + "reference": "2b56bea83a09de3ac06bb18b92f068e60cc6f50b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/442e7c7e687e42adc03470c7b668bc4b2402c0b2", - "reference": "442e7c7e687e42adc03470c7b668bc4b2402c0b2", + "url": "https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/2b56bea83a09de3ac06bb18b92f068e60cc6f50b", + "reference": "2b56bea83a09de3ac06bb18b92f068e60cc6f50b", "shasum": "" }, "require": { @@ -994,7 +1064,7 @@ "homepage": "https://github.com/sebastianbergmann/cli-parser", "support": { "issues": "https://github.com/sebastianbergmann/cli-parser/issues", - "source": "https://github.com/sebastianbergmann/cli-parser/tree/1.0.1" + "source": "https://github.com/sebastianbergmann/cli-parser/tree/1.0.2" }, "funding": [ { @@ -1002,7 +1072,7 @@ "type": "github" } ], - "time": "2020-09-28T06:08:49+00:00" + "time": "2024-03-02T06:27:43+00:00" }, { "name": "sebastian/code-unit", @@ -1248,16 +1318,16 @@ }, { "name": "sebastian/diff", - "version": "4.0.5", + "version": "4.0.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "74be17022044ebaaecfdf0c5cd504fc9cd5a7131" + "reference": "ba01945089c3a293b01ba9badc29ad55b106b0bc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/74be17022044ebaaecfdf0c5cd504fc9cd5a7131", - "reference": "74be17022044ebaaecfdf0c5cd504fc9cd5a7131", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/ba01945089c3a293b01ba9badc29ad55b106b0bc", + "reference": "ba01945089c3a293b01ba9badc29ad55b106b0bc", "shasum": "" }, "require": { @@ -1302,7 +1372,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/diff/issues", - "source": "https://github.com/sebastianbergmann/diff/tree/4.0.5" + "source": "https://github.com/sebastianbergmann/diff/tree/4.0.6" }, "funding": [ { @@ -1310,7 +1380,7 @@ "type": "github" } ], - "time": "2023-05-07T05:35:17+00:00" + "time": "2024-03-02T06:30:58+00:00" }, { "name": "sebastian/environment", @@ -1377,16 +1447,16 @@ }, { "name": "sebastian/exporter", - "version": "4.0.5", + "version": "4.0.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "ac230ed27f0f98f597c8a2b6eb7ac563af5e5b9d" + "reference": "78c00df8f170e02473b682df15bfcdacc3d32d72" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/ac230ed27f0f98f597c8a2b6eb7ac563af5e5b9d", - "reference": "ac230ed27f0f98f597c8a2b6eb7ac563af5e5b9d", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/78c00df8f170e02473b682df15bfcdacc3d32d72", + "reference": "78c00df8f170e02473b682df15bfcdacc3d32d72", "shasum": "" }, "require": { @@ -1442,7 +1512,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/exporter/issues", - "source": "https://github.com/sebastianbergmann/exporter/tree/4.0.5" + "source": "https://github.com/sebastianbergmann/exporter/tree/4.0.6" }, "funding": [ { @@ -1450,20 +1520,20 @@ "type": "github" } ], - "time": "2022-09-14T06:03:37+00:00" + "time": "2024-03-02T06:33:00+00:00" }, { "name": "sebastian/global-state", - "version": "5.0.6", + "version": "5.0.7", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "bde739e7565280bda77be70044ac1047bc007e34" + "reference": "bca7df1f32ee6fe93b4d4a9abbf69e13a4ada2c9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bde739e7565280bda77be70044ac1047bc007e34", - "reference": "bde739e7565280bda77be70044ac1047bc007e34", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bca7df1f32ee6fe93b4d4a9abbf69e13a4ada2c9", + "reference": "bca7df1f32ee6fe93b4d4a9abbf69e13a4ada2c9", "shasum": "" }, "require": { @@ -1506,7 +1576,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/global-state/issues", - "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.6" + "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.7" }, "funding": [ { @@ -1514,7 +1584,7 @@ "type": "github" } ], - "time": "2023-08-02T09:26:13+00:00" + "time": "2024-03-02T06:35:11+00:00" }, { "name": "sebastian/lines-of-code", @@ -1750,16 +1820,16 @@ }, { "name": "sebastian/resource-operations", - "version": "3.0.3", + "version": "3.0.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/resource-operations.git", - "reference": "0f4443cb3a1d92ce809899753bc0d5d5a8dd19a8" + "reference": "05d5692a7993ecccd56a03e40cd7e5b09b1d404e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/0f4443cb3a1d92ce809899753bc0d5d5a8dd19a8", - "reference": "0f4443cb3a1d92ce809899753bc0d5d5a8dd19a8", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/05d5692a7993ecccd56a03e40cd7e5b09b1d404e", + "reference": "05d5692a7993ecccd56a03e40cd7e5b09b1d404e", "shasum": "" }, "require": { @@ -1771,7 +1841,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-main": "3.0-dev" } }, "autoload": { @@ -1792,8 +1862,7 @@ "description": "Provides a list of PHP built-in functions that operate on resources", "homepage": "https://www.github.com/sebastianbergmann/resource-operations", "support": { - "issues": "https://github.com/sebastianbergmann/resource-operations/issues", - "source": "https://github.com/sebastianbergmann/resource-operations/tree/3.0.3" + "source": "https://github.com/sebastianbergmann/resource-operations/tree/3.0.4" }, "funding": [ { @@ -1801,7 +1870,7 @@ "type": "github" } ], - "time": "2020-09-28T06:45:17+00:00" + "time": "2024-03-14T16:00:52+00:00" }, { "name": "sebastian/type", @@ -1956,16 +2025,16 @@ }, { "name": "theseer/tokenizer", - "version": "1.2.2", + "version": "1.2.3", "source": { "type": "git", "url": "https://github.com/theseer/tokenizer.git", - "reference": "b2ad5003ca10d4ee50a12da31de12a5774ba6b96" + "reference": "737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/theseer/tokenizer/zipball/b2ad5003ca10d4ee50a12da31de12a5774ba6b96", - "reference": "b2ad5003ca10d4ee50a12da31de12a5774ba6b96", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2", + "reference": "737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2", "shasum": "" }, "require": { @@ -1994,7 +2063,7 @@ "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", "support": { "issues": "https://github.com/theseer/tokenizer/issues", - "source": "https://github.com/theseer/tokenizer/tree/1.2.2" + "source": "https://github.com/theseer/tokenizer/tree/1.2.3" }, "funding": [ { @@ -2002,20 +2071,20 @@ "type": "github" } ], - "time": "2023-11-20T00:12:19+00:00" + "time": "2024-03-03T12:36:25+00:00" }, { "name": "workerman/workerman", - "version": "v4.1.14", + "version": "v4.1.15", "source": { "type": "git", "url": "https://github.com/walkor/workerman.git", - "reference": "f7c9667c7b5387c01fa9e50ee79ed931e93ee76e" + "reference": "afc8242fc769ab7cf22eb4ac22b97cb59d465e4e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/walkor/workerman/zipball/f7c9667c7b5387c01fa9e50ee79ed931e93ee76e", - "reference": "f7c9667c7b5387c01fa9e50ee79ed931e93ee76e", + "url": "https://api.github.com/repos/walkor/workerman/zipball/afc8242fc769ab7cf22eb4ac22b97cb59d465e4e", + "reference": "afc8242fc769ab7cf22eb4ac22b97cb59d465e4e", "shasum": "" }, "require": { @@ -2065,12 +2134,14 @@ "type": "patreon" } ], - "time": "2023-08-09T03:37:45+00:00" + "time": "2024-02-19T02:10:39+00:00" } ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "utopia-php/di": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { diff --git a/src/Queue/Job.php b/src/Queue/Job.php index 591d867..b3b2dc2 100644 --- a/src/Queue/Job.php +++ b/src/Queue/Job.php @@ -2,7 +2,7 @@ namespace Utopia\Queue; -use Utopia\Hook; +use Utopia\Http\Hook; class Job extends Hook { diff --git a/src/Queue/Server.php b/src/Queue/Server.php index f43d6a5..3bfe0c9 100644 --- a/src/Queue/Server.php +++ b/src/Queue/Server.php @@ -5,7 +5,7 @@ use Throwable; use Utopia\CLI\Console; use Exception; -use Utopia\Hook; +use Utopia\Http\Hook; use Utopia\Validator; class Server diff --git a/tests/Queue/servers/tests.php b/tests/Queue/servers/tests.php index 8380cdb..4ca45a9 100644 --- a/tests/Queue/servers/tests.php +++ b/tests/Queue/servers/tests.php @@ -4,7 +4,10 @@ function handleRequest(Queue\Message $job): void { - ['type' => $type, 'value' => $value] = $job->getPayload(); + $payload = $job->getPayload() ?? []; + + $type = $payload['type'] ?? null; + $value = $payload['value'] ?? null; if (empty($job->getTimestamp())) { throw new Exception(); From 551a0016afb0bee3f01d818f4751a8afa90470bd Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Fri, 19 Apr 2024 13:21:40 +0200 Subject: [PATCH 02/26] Init --- composer.json | 6 +- composer.lock | 82 +++++++- docker-compose.yml | 4 +- src/Queue/Job.php | 32 +-- src/Queue/Server.php | 276 +++++++++----------------- tests/Queue/servers/Swoole/worker.php | 80 +++++++- 6 files changed, 260 insertions(+), 220 deletions(-) diff --git a/composer.json b/composer.json index b1571ff..1054ad2 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "require": { "php": ">=8.0", "utopia-php/cli": "0.17.*", - "utopia-php/framework": "0.*.*", + "utopia-php/servers": "dev-dev", "utopia-php/di": "dev-main" }, "require-dev": { @@ -41,6 +41,10 @@ "workerman/workerman": "Needed to support Workerman." }, "repositories": [ + { + "type": "vcs", + "url": "https://github.com/utopia-php/servers" + }, { "type": "vcs", "url": "https://github.com/utopia-php/di" diff --git a/composer.lock b/composer.lock index 107e250..21ea5af 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "21e2f04315452ede5b939075405fdc84", + "content-hash": "7ae591bf6380d4469179b803c24cdae8", "packages": [ { "name": "utopia-php/cli", @@ -61,12 +61,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/di.git", - "reference": "0bb7af5693bc131f4d2ce34d3f732d41e6637679" + "reference": "fb3c45b268018b87dcbbf87ad943ced9eea3bbe2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/di/zipball/0bb7af5693bc131f4d2ce34d3f732d41e6637679", - "reference": "0bb7af5693bc131f4d2ce34d3f732d41e6637679", + "url": "https://api.github.com/repos/utopia-php/di/zipball/fb3c45b268018b87dcbbf87ad943ced9eea3bbe2", + "reference": "fb3c45b268018b87dcbbf87ad943ced9eea3bbe2", "shasum": "" }, "require": { @@ -115,7 +115,7 @@ "source": "https://github.com/utopia-php/di/tree/main", "issues": "https://github.com/utopia-php/di/issues" }, - "time": "2024-04-08T22:41:41+00:00" + "time": "2024-04-18T20:06:02+00:00" }, { "name": "utopia-php/framework", @@ -164,6 +164,77 @@ "source": "https://github.com/utopia-php/http/tree/0.34.2" }, "time": "2024-02-20T11:36:56+00:00" + }, + { + "name": "utopia-php/servers", + "version": "dev-dev", + "source": { + "type": "git", + "url": "https://github.com/utopia-php/servers.git", + "reference": "43881ed83f97cb31af7f940db74c520c70b914ab" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/utopia-php/servers/zipball/43881ed83f97cb31af7f940db74c520c70b914ab", + "reference": "43881ed83f97cb31af7f940db74c520c70b914ab", + "shasum": "" + }, + "require": { + "php": ">=8.0", + "utopia-php/di": "dev-main" + }, + "require-dev": { + "laravel/pint": "^0.2.3", + "phpstan/phpstan": "^1.8", + "phpunit/phpunit": "^9.5.5" + }, + "type": "library", + "autoload": { + "psr-4": { + "Utopia\\Servers\\": "src/Servers" + } + }, + "autoload-dev": { + "psr-4": { + "Tests\\E2E\\": "tests/Servers/Unit" + } + }, + "scripts": { + "test": [ + "phpunit" + ], + "analyse": [ + "vendor/bin/phpstan analyse" + ], + "format": [ + "vendor/bin/pint" + ], + "lint": [ + "vendor/bin/pint --test" + ] + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Team Appwrite", + "email": "team@appwrite.io" + } + ], + "description": "A base library for building Utopia style servers.", + "keywords": [ + "framework", + "php", + "servers", + "upf", + "utopia" + ], + "support": { + "source": "https://github.com/utopia-php/servers/tree/dev", + "issues": "https://github.com/utopia-php/servers/issues" + }, + "time": "2024-04-18T20:51:43+00:00" } ], "packages-dev": [ @@ -2140,6 +2211,7 @@ "aliases": [], "minimum-stability": "stable", "stability-flags": { + "utopia-php/servers": 20, "utopia-php/di": 20 }, "prefer-stable": false, diff --git a/docker-compose.yml b/docker-compose.yml index 9cf1a6d..8add0d9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,3 @@ -version: '3.1' - services: tests: container_name: tests @@ -36,4 +34,4 @@ services: container_name: redis image: "redis:alpine" ports: - - "6379:6379" \ No newline at end of file + - "9303:6379" \ No newline at end of file diff --git a/src/Queue/Job.php b/src/Queue/Job.php index b3b2dc2..78a213e 100644 --- a/src/Queue/Job.php +++ b/src/Queue/Job.php @@ -2,39 +2,9 @@ namespace Utopia\Queue; -use Utopia\Http\Hook; +use Utopia\Servers\Hook; class Job extends Hook { - /** - * Whether to use hook - * - * @var bool - */ - protected bool $hook = true; - /** - * Set hook status - * When set false, hooks for this route will be skipped. - * - * @param boolean $hook - * - * @return static - */ - public function hook(bool $hook = true): static - { - $this->hook = $hook; - - return $this; - } - - /** - * Get hook status - * - * @return bool - */ - public function getHook(): bool - { - return $this->hook; - } } diff --git a/src/Queue/Server.php b/src/Queue/Server.php index 3bfe0c9..b58b740 100644 --- a/src/Queue/Server.php +++ b/src/Queue/Server.php @@ -3,12 +3,13 @@ namespace Utopia\Queue; use Throwable; -use Utopia\CLI\Console; use Exception; -use Utopia\Http\Hook; -use Utopia\Validator; +use Utopia\CLI\Console; +use Utopia\DI\Dependency; +use Utopia\Servers\Base; +use Utopia\Servers\Hook; -class Server +class Server extends Base { /** * Queue Adapter @@ -22,28 +23,7 @@ class Server * * @var Job */ - protected Job $job; - - /** - * Hooks that will run when error occur - * - * @var array - */ - protected array $errorHooks = []; - - /** - * Hooks that will run before running job - * - * @var array - */ - protected array $initHooks = []; - - /** - * Hooks that will run after running job - * - * @var array - */ - protected array $shutdownHooks = []; + protected static Job $job; /** * Hook that is called when worker starts @@ -73,10 +53,13 @@ public function __construct(Adapter $adapter) $this->adapter = $adapter; } - public function job(): Job + /** + * Add a job hook + */ + public static function job(): Job { - $this->job = new Job(); - return $this->job; + self::$job = new Job(); + return self::$job; } /** @@ -138,18 +121,6 @@ public static function setResource(string $name, callable $callback, array $inje self::$resourcesCallbacks[$name] = ['callback' => $callback, 'injections' => $injections, 'reset' => true]; } - /** - * Shutdown Hooks - * @return Hook - */ - public function shutdown(): Hook - { - $hook = new Hook(); - $hook->groups(['*']); - $this->shutdownHooks[] = $hook; - return $hook; - } - /** * Stops the Queue server. * @return self @@ -167,19 +138,6 @@ public function stop(): self return $this; } - /** - * Init Hooks - * - * @return Hook - */ - public function init(): Hook - { - $hook = new Hook(); - $hook->groups(['*']); - $this->initHooks[] = $hook; - return $hook; - } - /** * Starts the Queue Server * @return self @@ -189,9 +147,11 @@ public function start(): self try { $this->adapter->workerStart(function (string $workerId) { Console::success("[Worker] Worker {$workerId} is ready!"); - if (!is_null($this->workerStartHook)) { - call_user_func_array($this->workerStartHook->getAction(), $this->getArguments($this->workerStartHook)); - } + + // if (!is_null($this->workerStartHook)) { + // call_user_func_array($this->workerStartHook->getAction(), $this->getArguments($this->workerStartHook)); + // } + while (true) { /** * Waiting for next Job. @@ -204,9 +164,17 @@ public function start(): self $nextMessage['timestamp'] = (int)$nextMessage['timestamp']; + $context = clone $this->container; + $job = clone self::$job; + $groups = $job->getGroups(); $message = new Message($nextMessage); - self::setResource('message', fn () => $message); + $dependency = new Dependency(); + $context->set( + $dependency + ->setName('message') + ->setCallback(fn () => $message) + ); Console::info("[Job] Received Job ({$message->getPid()})."); @@ -227,25 +195,21 @@ public function start(): self */ $this->adapter->connection->increment("{$this->adapter->namespace}.stats.{$this->adapter->queue}.processing"); - if ($this->job->getHook()) { - foreach ($this->initHooks as $hook) { // Global init hooks - if (in_array('*', $hook->getGroups())) { - $arguments = $this->getArguments($hook, $message->getPayload()); - \call_user_func_array($hook->getAction(), $arguments); - } + foreach (self::$init as $hook) { // Global init hooks + if (in_array('*', $hook->getGroups())) { + $this->prepare($context, $hook, [], $message->getPayload())->inject($hook, true); } } - foreach ($this->job->getGroups() as $group) { - foreach ($this->initHooks as $hook) { // Group init hooks + foreach ($groups as $group) { + foreach (self::$init as $hook) { // Group init hooks if (in_array($group, $hook->getGroups())) { - $arguments = $this->getArguments($hook, $message->getPayload()); - \call_user_func_array($hook->getAction(), $arguments); + $this->prepare($context, $hook, [], $message->getPayload())->inject($hook, true); } } } - \call_user_func_array($this->job->getAction(), $this->getArguments($this->job, $message->getPayload())); + $this->prepare($context, $job, [], $message->getPayload())->inject($job, true); /** * Remove Jobs if successful. @@ -257,21 +221,17 @@ public function start(): self */ $this->adapter->connection->increment("{$this->adapter->namespace}.stats.{$this->adapter->queue}.success"); - if ($this->job->getHook()) { - foreach ($this->shutdownHooks as $hook) { // Global init hooks - if (in_array('*', $hook->getGroups())) { - $arguments = $this->getArguments($hook, $message->getPayload()); - \call_user_func_array($hook->getAction(), $arguments); + foreach ($groups as $group) { + foreach (self::$shutdown as $hook) { // Group shutdown hooks + if (in_array($group, $hook->getGroups())) { + $this->prepare($context, $hook, [], $message->getPayload())->inject($hook, true); } } } - - foreach ($this->job->getGroups() as $group) { - foreach ($this->shutdownHooks as $hook) { // Group init hooks - if (in_array($group, $hook->getGroups())) { - $arguments = $this->getArguments($hook, $message->getPayload()); - \call_user_func_array($hook->getAction(), $arguments); - } + + foreach (self::$shutdown as $hook) { // Global shutdown hooks + if (in_array('*', $hook->getGroups())) { + $this->prepare($context, $hook, [], $message->getPayload())->inject($hook, true); } } @@ -290,9 +250,34 @@ public function start(): self Console::error("[Job] ({$message->getPid()}) failed to run."); Console::error("[Job] ({$message->getPid()}) {$th->getMessage()}"); - self::setResource('error', fn () => $th); - foreach ($this->errorHooks as $hook) { - call_user_func_array($hook->getAction(), $this->getArguments($hook)); + $dependency = new Dependency(); + $context->set( + $dependency + ->setName('error') + ->setCallback(fn () => $th) + ) + ; + + foreach ($groups as $group) { + foreach (self::$errors as $error) { // Group error hooks + if (in_array($group, $error->getGroups())) { + try { + $this->prepare($context, $error, [], $message->getPayload())->inject($error, true); + } catch (\Throwable $e) { + throw new Exception('Group error handler had an error: ' . $e->getMessage(). ' on: ' . $e->getFile().':'.$e->getLine(), 500, $e); + } + } + } + } + + foreach (self::$errors as $error) { // Global error hooks + if (in_array('*', $error->getGroups())) { + try { + $this->prepare($context, $error, [], $message->getPayload())->inject($error, true); + } catch (\Throwable $e) { + throw new Exception('Global error handler had an error: ' . $e->getMessage(). ' on: ' . $e->getFile().':'.$e->getLine(), 500, $e); + } + } } } finally { /** @@ -313,9 +298,9 @@ public function start(): self $this->adapter->start(); } catch (Throwable $error) { self::setResource('error', fn () => $error); - foreach ($this->errorHooks as $hook) { - call_user_func_array($hook->getAction(), $this->getArguments($hook)); - } + // foreach ($this->errorHooks as $hook) { + // call_user_func_array($hook->getAction(), $this->getArguments($hook)); + // } } return $this; } @@ -346,94 +331,31 @@ public function getWorkerStart(): Hook * @param callable $callback * @return self */ - public function workerStop(callable $callback = null): self - { - try { - $this->adapter->workerStop(function (string $workerId) use ($callback) { - Console::success("[Worker] Worker {$workerId} is ready!"); - if (!is_null($callback)) { - call_user_func($callback); - } - }); - } catch (Throwable $error) { - self::setResource('error', fn () => $error); - foreach ($this->errorHooks as $hook) { - call_user_func_array($hook->getAction(), $this->getArguments($hook)); - } - } - - return $this; - } - - /** - * Get Arguments - * - * @param Hook $hook - * @param array $payload - * @return array - */ - protected function getArguments(Hook $hook, array $payload = []): array - { - $arguments = []; - foreach ($hook->getParams() as $key => $param) { // Get value from route or request object - $value = $payload[$key] ?? $param['default']; - $value = ($value === '' || is_null($value)) ? $param['default'] : $value; - - $this->validate($key, $param, $value); - $hook->setParamValue($key, $value); - $arguments[$param['order']] = $value; - } - - foreach ($hook->getInjections() as $key => $injection) { - $arguments[$injection['order']] = $this->getResource($injection['name']); - } - - return $arguments; - } - - /** - * Validate Param - * - * Creates an validator instance and validate given value with given rules. - * - * @param string $key - * @param array $param - * @param mixed $value - * - * @throws Exception - * - * @return void - */ - protected function validate(string $key, array $param, mixed $value): void - { - if ('' !== $value && !is_null($value)) { - $validator = $param['validator']; // checking whether the class exists - - if (\is_callable($validator)) { - $validator = \call_user_func_array($validator, $this->getResources($param['injections'])); - } - - if (!$validator instanceof Validator) { // is the validator object an instance of the Validator class - throw new Exception('Validator object is not an instance of the Validator class', 500); - } - - if (!$validator->isValid($value)) { - throw new Exception('Invalid ' .$key . ': ' . $validator->getDescription(), 400); - } - } elseif (!$param['optional']) { - throw new Exception('Param "' . $key . '" is not optional.', 400); - } - } - - /** - * Register hook. Will be executed when error occurs. - * @return Hook - */ - public function error(): Hook - { - $hook = new Hook(); - $hook->groups(['*']); - $this->errorHooks[] = $hook; - return $hook; - } + // public function workerStop(callable $callback = null): self + // { + // $container = clone $this->container; + + // try { + // $this->adapter->workerStop(function (string $workerId) use ($this, $container, $callback) { + // Console::success("[Worker] Worker {$workerId} is ready!"); + // if (!is_null($callback)) { + // call_user_func($callback); + // $this->prepare($container, $hook, [], [])->inject($hook, true); + // } + // }); + // } catch (Throwable $error) { + // self::setResource('error', fn () => $error); + // foreach (self::$errors as $error) { // Global error hooks + // if (in_array('*', $error->getGroups())) { + // try { + // $this->prepare($container, $error, [], [])->inject($error, true); + // } catch (\Throwable $e) { + // throw new Exception('Error handler had an error: ' . $e->getMessage(). ' on: ' . $e->getFile().':'.$e->getLine(), 500, $e); + // } + // } + // } + // } + + // return $this; + // } } diff --git a/tests/Queue/servers/Swoole/worker.php b/tests/Queue/servers/Swoole/worker.php index 972aba9..f95747e 100644 --- a/tests/Queue/servers/Swoole/worker.php +++ b/tests/Queue/servers/Swoole/worker.php @@ -3,21 +3,95 @@ require_once __DIR__ . '/../../../../vendor/autoload.php'; require_once __DIR__ . '/../tests.php'; +use Utopia\DI\Container; use Utopia\Queue; use Utopia\Queue\Message; +use Utopia\Queue\Server; +use Utopia\Servers\Validator; +class Text extends Validator +{ + /** + * Get Description + * + * Returns validator description + * + * @return string + */ + public function getDescription(): string + { + return 'Value must be a valid number'; + } + + /** + * Is array + * + * Function will return true if object is array. + * + * @return bool + */ + public function isArray(): bool + { + return false; + } + + /** + * Get Type + * + * Returns validator type. + * + * @return string + */ + public function getType(): string + { + return ''; + } + + /** + * Is valid + * + * Validation will pass when $value is numeric. + * + * @param mixed $value + * @return bool + */ + public function isValid(mixed $value): bool + { + return true; + } +} + +$container = new Container(); $connection = new Queue\Connection\Redis('redis'); $adapter = new Queue\Adapter\Swoole($connection, 12, 'swoole'); $server = new Queue\Server($adapter); +$server->setContainer($container); -$server->job() +// Server::init() +// ->param('id', 'default', new Text(), 'Message ID', true) +// ->inject('message') +// ->action(function ($id, $message) { +// var_dump($id); +// var_dump($message); +// echo "Job init" . PHP_EOL; +// }); + +// Server::job() +// ->param('id', 'default', new Text(), 'Message ID', true) +// ->inject('message') +// ->action(function ($id, $message) { +// var_dump($id); +// var_dump($message); +// echo "Job start" . PHP_EOL; +// }); + +Server::job() ->inject('message') ->action(function (Message $message) { handleRequest($message); }); -$server - ->error() +Server::error() ->inject('error') ->action(function ($th) { echo $th->getMessage() . PHP_EOL; From 5d096e104c932d31b67ef75de91b1673c7351437 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Fri, 19 Apr 2024 13:26:51 +0200 Subject: [PATCH 03/26] Fixed format --- src/Queue/Job.php | 1 - src/Queue/Server.php | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Queue/Job.php b/src/Queue/Job.php index 78a213e..2c8a0f2 100644 --- a/src/Queue/Job.php +++ b/src/Queue/Job.php @@ -6,5 +6,4 @@ class Job extends Hook { - } diff --git a/src/Queue/Server.php b/src/Queue/Server.php index b58b740..a433f06 100644 --- a/src/Queue/Server.php +++ b/src/Queue/Server.php @@ -228,7 +228,7 @@ public function start(): self } } } - + foreach (self::$shutdown as $hook) { // Global shutdown hooks if (in_array('*', $hook->getGroups())) { $this->prepare($context, $hook, [], $message->getPayload())->inject($hook, true); @@ -334,7 +334,7 @@ public function getWorkerStart(): Hook // public function workerStop(callable $callback = null): self // { // $container = clone $this->container; - + // try { // $this->adapter->workerStop(function (string $workerId) use ($this, $container, $callback) { // Console::success("[Worker] Worker {$workerId} is ready!"); From bc5f2eac7d18be4647050d59a593c059b8ffa849 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Fri, 19 Apr 2024 13:30:04 +0200 Subject: [PATCH 04/26] Fixed error handler for stop action --- src/Queue/Server.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Queue/Server.php b/src/Queue/Server.php index a433f06..ecfdf5f 100644 --- a/src/Queue/Server.php +++ b/src/Queue/Server.php @@ -129,10 +129,20 @@ public function stop(): self { try { $this->adapter->stop(); - } catch (Throwable $error) { - self::setResource('error', fn () => $error); - foreach ($this->errorHooks as $hook) { - call_user_func_array($hook->getAction(), $this->getArguments($hook)); + } catch (Throwable $th) { + $context = clone $this->container; + + $dependency = new Dependency(); + $context->set( + $dependency + ->setName('error') + ->setCallback(fn () => $th) + ); + + foreach (self::$shutdown as $hook) { // Global shutdown hooks + if (in_array('*', $hook->getGroups())) { + $this->prepare($context, $hook, [], [])->inject($hook, true); + } } } return $this; From 476a1c81671ee3ce4afa484cdfda2e8555389163 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Fri, 19 Apr 2024 13:45:01 +0200 Subject: [PATCH 05/26] Fixed workerman tests --- src/Queue/Server.php | 79 +++++------------------- tests/Queue/servers/Workerman/worker.php | 21 ++++--- 2 files changed, 27 insertions(+), 73 deletions(-) diff --git a/src/Queue/Server.php b/src/Queue/Server.php index ecfdf5f..1d5d94e 100644 --- a/src/Queue/Server.php +++ b/src/Queue/Server.php @@ -62,65 +62,6 @@ public static function job(): Job return self::$job; } - /** - * If a resource has been created return it, otherwise create it and then return it - * - * @param string $name - * @param bool $fresh - * @return mixed - * @throws Exception - */ - public function getResource(string $name, bool $fresh = false): mixed - { - if (!\array_key_exists($name, $this->resources) || $fresh || self::$resourcesCallbacks[$name]['reset']) { - if (!\array_key_exists($name, self::$resourcesCallbacks)) { - throw new Exception('Failed to find resource: "' . $name . '"'); - } - - $this->resources[$name] = \call_user_func_array( - self::$resourcesCallbacks[$name]['callback'], - $this->getResources(self::$resourcesCallbacks[$name]['injections']) - ); - } - - self::$resourcesCallbacks[$name]['reset'] = false; - - return $this->resources[$name]; - } - - /** - * Get Resources By List - * - * @param array $list - * @return array - */ - public function getResources(array $list): array - { - $resources = []; - - foreach ($list as $name) { - $resources[$name] = $this->getResource($name); - } - - return $resources; - } - - /** - * Set a new resource callback - * - * @param string $name - * @param callable $callback - * @param array $injections - * - * @throws Exception - * - * @return void - */ - public static function setResource(string $name, callable $callback, array $injections = []): void - { - self::$resourcesCallbacks[$name] = ['callback' => $callback, 'injections' => $injections, 'reset' => true]; - } - /** * Stops the Queue server. * @return self @@ -306,11 +247,21 @@ public function start(): self }); $this->adapter->start(); - } catch (Throwable $error) { - self::setResource('error', fn () => $error); - // foreach ($this->errorHooks as $hook) { - // call_user_func_array($hook->getAction(), $this->getArguments($hook)); - // } + } catch (Throwable $th) { + $context = clone $this->container; + + $dependency = new Dependency(); + $context->set( + $dependency + ->setName('error') + ->setCallback(fn () => $th) + ); + + foreach (self::$shutdown as $hook) { // Global shutdown hooks + if (in_array('*', $hook->getGroups())) { + $this->prepare($context, $hook, [], [])->inject($hook, true); + } + } } return $this; } diff --git a/tests/Queue/servers/Workerman/worker.php b/tests/Queue/servers/Workerman/worker.php index ffc667e..f600033 100644 --- a/tests/Queue/servers/Workerman/worker.php +++ b/tests/Queue/servers/Workerman/worker.php @@ -3,29 +3,32 @@ require_once __DIR__ . '/../../../../vendor/autoload.php'; require_once __DIR__ . '/../tests.php'; +use Utopia\DI\Container; use Utopia\Queue; use Utopia\Queue\Message; +use Utopia\Queue\Server; +$container = new Container(); $connection = new Queue\Connection\Redis('redis'); $adapter = new Queue\Adapter\Workerman($connection, 12, 'workerman'); -$server = new Queue\Server($adapter); -$server->job() +$server = new Server($adapter); +$server->setContainer($container); + +Server::job() ->inject('message') ->action(function (Message $message) { handleRequest($message); }); -$server - ->error() +Server::error() ->inject('error') ->action(function ($th) { echo $th->getMessage() . PHP_EOL; }); -$server - ->workerStart() - ->action(function () { - echo "Worker Started" . PHP_EOL; - }); +// Server::workerStart() +// ->action(function () { +// echo "Worker Started" . PHP_EOL; +// }); $server->start(); From 653b5dd2a39a9b707119fe670fc66ef603c9b3ff Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Fri, 19 Apr 2024 16:36:10 +0200 Subject: [PATCH 06/26] Leftovers --- tests/Queue/servers/Swoole/worker.php | 6 ------ tests/Queue/servers/Workerman/worker.php | 5 ----- 2 files changed, 11 deletions(-) diff --git a/tests/Queue/servers/Swoole/worker.php b/tests/Queue/servers/Swoole/worker.php index f95747e..063eff7 100644 --- a/tests/Queue/servers/Swoole/worker.php +++ b/tests/Queue/servers/Swoole/worker.php @@ -97,10 +97,4 @@ public function isValid(mixed $value): bool echo $th->getMessage() . PHP_EOL; }); -$server - ->workerStart() - ->action(function () { - echo "Worker Started" . PHP_EOL; - }); - $server->start(); diff --git a/tests/Queue/servers/Workerman/worker.php b/tests/Queue/servers/Workerman/worker.php index f600033..97703c5 100644 --- a/tests/Queue/servers/Workerman/worker.php +++ b/tests/Queue/servers/Workerman/worker.php @@ -26,9 +26,4 @@ echo $th->getMessage() . PHP_EOL; }); -// Server::workerStart() -// ->action(function () { -// echo "Worker Started" . PHP_EOL; -// }); - $server->start(); From 8d63cd69e3175008f7f75491713f07a184ac4704 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Fri, 19 Apr 2024 18:01:37 +0200 Subject: [PATCH 07/26] Updated queue --- composer.json | 1 + src/Queue/Adapter.php | 11 +- .../Adapter/{Swoole.php => Swoole/Server.php} | 20 +- .../{Workerman.php => Workerman/Server.php} | 15 +- src/Queue/Server.php | 315 +++++++----------- tests/Queue/servers/Swoole/worker.php | 2 +- tests/Queue/servers/Workerman/worker.php | 2 +- 7 files changed, 163 insertions(+), 203 deletions(-) rename src/Queue/Adapter/{Swoole.php => Swoole/Server.php} (70%) rename src/Queue/Adapter/{Workerman.php => Workerman/Server.php} (77%) diff --git a/composer.json b/composer.json index 1054ad2..ad8dddd 100644 --- a/composer.json +++ b/composer.json @@ -37,6 +37,7 @@ "phpstan/phpstan": "^1.8" }, "suggest": { + "ext-redis": "Needed to support Redis connections", "ext-swoole": "Needed to support Swoole.", "workerman/workerman": "Needed to support Workerman." }, diff --git a/src/Queue/Adapter.php b/src/Queue/Adapter.php index 756e67a..196a715 100644 --- a/src/Queue/Adapter.php +++ b/src/Queue/Adapter.php @@ -33,14 +33,21 @@ abstract public function stop(): self; * @param callable $callback * @return self */ - abstract public function workerStart(callable $callback): self; + abstract public function onWorkerStart(callable $callback): self; /** * Is called when a Worker stops. * @param callable $callback * @return self */ - abstract public function workerStop(callable $callback): self; + abstract public function onWorkerStop(callable $callback): self; + + /** + * Is called when a job is processed. + * @param callable $callback + * @return self + */ + abstract public function onJob(callable $callback): self; /** * Returns the native server object from the Adapter. diff --git a/src/Queue/Adapter/Swoole.php b/src/Queue/Adapter/Swoole/Server.php similarity index 70% rename from src/Queue/Adapter/Swoole.php rename to src/Queue/Adapter/Swoole/Server.php index 522e73a..d6281c9 100644 --- a/src/Queue/Adapter/Swoole.php +++ b/src/Queue/Adapter/Swoole/Server.php @@ -1,12 +1,13 @@ pool->set(['enable_coroutine' => true]); $this->pool->start(); return $this; @@ -31,7 +33,7 @@ public function stop(): self return $this; } - public function workerStart(callable $callback): self + public function onWorkerStart(callable $callback): self { $this->pool->on('WorkerStart', function (Pool $pool, string $workerId) use ($callback) { call_user_func($callback, $workerId); @@ -40,7 +42,7 @@ public function workerStart(callable $callback): self return $this; } - public function workerStop(callable $callback): self + public function onWorkerStop(callable $callback): self { $this->pool->on('WorkerStart', function (Pool $pool, string $workerId) use ($callback) { call_user_func($callback, $workerId); @@ -49,6 +51,16 @@ public function workerStop(callable $callback): self return $this; } + public function onJob(callable $callback): self + { + call_user_func($callback); + // go(function () use ($callback) { + // call_user_func($callback); + // }); + + return $this; + } + public function getNative(): Pool { return $this->pool; diff --git a/src/Queue/Adapter/Workerman.php b/src/Queue/Adapter/Workerman/Server.php similarity index 77% rename from src/Queue/Adapter/Workerman.php rename to src/Queue/Adapter/Workerman/Server.php index bd6255d..98b424f 100644 --- a/src/Queue/Adapter/Workerman.php +++ b/src/Queue/Adapter/Workerman/Server.php @@ -1,12 +1,12 @@ worker->onWorkerStart = function ($worker) use ($callback) { call_user_func($callback, $worker->workerId); @@ -39,7 +39,7 @@ public function workerStart(callable $callback): self return $this; } - public function workerStop(callable $callback): self + public function onWorkerStop(callable $callback): self { $this->worker->onWorkerStop = function ($worker) use ($callback) { call_user_func($callback, $worker->workerId); @@ -48,6 +48,13 @@ public function workerStop(callable $callback): self return $this; } + public function onJob(callable $callback): self + { + call_user_func($callback); + + return $this; + } + public function getNative(): Worker { return $this->worker; diff --git a/src/Queue/Server.php b/src/Queue/Server.php index 1d5d94e..d3ccecd 100644 --- a/src/Queue/Server.php +++ b/src/Queue/Server.php @@ -5,9 +5,9 @@ use Throwable; use Exception; use Utopia\CLI\Console; +use Utopia\DI\Container; use Utopia\DI\Dependency; use Utopia\Servers\Base; -use Utopia\Servers\Hook; class Server extends Base { @@ -25,25 +25,6 @@ class Server extends Base */ protected static Job $job; - /** - * Hook that is called when worker starts - * - * @var Hook - */ - protected Hook $workerStartHook; - - /** - * @var array - */ - protected array $resources = [ - 'error' => null, - ]; - - /** - * @var array - */ - protected static array $resourcesCallbacks = []; - /** * Creates an instance of a Queue server. * @param Adapter $adapter @@ -96,13 +77,9 @@ public function stop(): self public function start(): self { try { - $this->adapter->workerStart(function (string $workerId) { + $this->adapter->onWorkerStart(function (string $workerId) { Console::success("[Worker] Worker {$workerId} is ready!"); - // if (!is_null($this->workerStartHook)) { - // call_user_func_array($this->workerStartHook->getAction(), $this->getArguments($this->workerStartHook)); - // } - while (true) { /** * Waiting for next Job. @@ -117,7 +94,6 @@ public function start(): self $context = clone $this->container; $job = clone self::$job; - $groups = $job->getGroups(); $message = new Message($nextMessage); $dependency = new Dependency(); @@ -127,196 +103,153 @@ public function start(): self ->setCallback(fn () => $message) ); - Console::info("[Job] Received Job ({$message->getPid()})."); + $this->adapter->onJob(function () use ($job, $message, $nextMessage, $context) { + $this->lifecycle($job, $message, $nextMessage, $context); + }); + } + }); - /** - * Move Job to Jobs and it's PID to the processing list. - */ - $this->adapter->connection->setArray("{$this->adapter->namespace}.jobs.{$this->adapter->queue}.{$message->getPid()}", $nextMessage); - $this->adapter->connection->leftPush("{$this->adapter->namespace}.processing.{$this->adapter->queue}", $message->getPid()); + $this->adapter->start(); + } catch (Throwable $th) { + $context = clone $this->container; - /** - * Increment Total Jobs Received from Stats. - */ - $this->adapter->connection->increment("{$this->adapter->namespace}.stats.{$this->adapter->queue}.total"); + $dependency = new Dependency(); + $context->set( + $dependency + ->setName('error') + ->setCallback(fn () => $th) + ); - try { - /** - * Increment Processing Jobs from Stats. - */ - $this->adapter->connection->increment("{$this->adapter->namespace}.stats.{$this->adapter->queue}.processing"); - - foreach (self::$init as $hook) { // Global init hooks - if (in_array('*', $hook->getGroups())) { - $this->prepare($context, $hook, [], $message->getPayload())->inject($hook, true); - } - } + foreach (self::$shutdown as $hook) { // Global shutdown hooks + if (in_array('*', $hook->getGroups())) { + $this->prepare($context, $hook, [], [])->inject($hook, true); + } + } + } + return $this; + } - foreach ($groups as $group) { - foreach (self::$init as $hook) { // Group init hooks - if (in_array($group, $hook->getGroups())) { - $this->prepare($context, $hook, [], $message->getPayload())->inject($hook, true); - } - } - } + protected function lifecycle(Job $job, Message $message, array $nextMessage, Container $context): static + { + Console::info("[Job] Received Job ({$message->getPid()})."); + + $groups = $job->getGroups(); + + /** + * Move Job to Jobs and it's PID to the processing list. + */ + $this->adapter->connection->setArray("{$this->adapter->namespace}.jobs.{$this->adapter->queue}.{$message->getPid()}", $nextMessage); + $this->adapter->connection->leftPush("{$this->adapter->namespace}.processing.{$this->adapter->queue}", $message->getPid()); + + /** + * Increment Total Jobs Received from Stats. + */ + $this->adapter->connection->increment("{$this->adapter->namespace}.stats.{$this->adapter->queue}.total"); + + /** + * Increment Processing Jobs from Stats. + */ + $this->adapter->connection->increment("{$this->adapter->namespace}.stats.{$this->adapter->queue}.processing"); + + try { - $this->prepare($context, $job, [], $message->getPayload())->inject($job, true); + foreach (self::$init as $hook) { // Global init hooks + if (in_array('*', $hook->getGroups())) { + $this->prepare($context, $hook, [], $message->getPayload())->inject($hook, true); + } + } - /** - * Remove Jobs if successful. - */ - $this->adapter->connection->remove("{$this->adapter->namespace}.jobs.{$this->adapter->queue}.{$message->getPid()}"); + foreach ($groups as $group) { + foreach (self::$init as $hook) { // Group init hooks + if (in_array($group, $hook->getGroups())) { + $this->prepare($context, $hook, [], $message->getPayload())->inject($hook, true); + } + } + } - /** - * Increment Successful Jobs from Stats. - */ - $this->adapter->connection->increment("{$this->adapter->namespace}.stats.{$this->adapter->queue}.success"); + $this->prepare($context, $job, [], $message->getPayload())->inject($job, true); - foreach ($groups as $group) { - foreach (self::$shutdown as $hook) { // Group shutdown hooks - if (in_array($group, $hook->getGroups())) { - $this->prepare($context, $hook, [], $message->getPayload())->inject($hook, true); - } - } - } + /** + * Remove Jobs if successful. + */ + $this->adapter->connection->remove("{$this->adapter->namespace}.jobs.{$this->adapter->queue}.{$message->getPid()}"); - foreach (self::$shutdown as $hook) { // Global shutdown hooks - if (in_array('*', $hook->getGroups())) { - $this->prepare($context, $hook, [], $message->getPayload())->inject($hook, true); - } - } + /** + * Increment Successful Jobs from Stats. + */ + $this->adapter->connection->increment("{$this->adapter->namespace}.stats.{$this->adapter->queue}.success"); - Console::success("[Job] ({$message->getPid()}) successfully run."); - } catch (\Throwable $th) { - /** - * Move failed Job to Failed list. - */ - $this->adapter->connection->leftPush("{$this->adapter->namespace}.failed.{$this->adapter->queue}", $message->getPid()); - - /** - * Increment Failed Jobs from Stats. - */ - $this->adapter->connection->increment("{$this->adapter->namespace}.stats.{$this->adapter->queue}.failed"); - - Console::error("[Job] ({$message->getPid()}) failed to run."); - Console::error("[Job] ({$message->getPid()}) {$th->getMessage()}"); - - $dependency = new Dependency(); - $context->set( - $dependency - ->setName('error') - ->setCallback(fn () => $th) - ) - ; - - foreach ($groups as $group) { - foreach (self::$errors as $error) { // Group error hooks - if (in_array($group, $error->getGroups())) { - try { - $this->prepare($context, $error, [], $message->getPayload())->inject($error, true); - } catch (\Throwable $e) { - throw new Exception('Group error handler had an error: ' . $e->getMessage(). ' on: ' . $e->getFile().':'.$e->getLine(), 500, $e); - } - } - } - } - foreach (self::$errors as $error) { // Global error hooks - if (in_array('*', $error->getGroups())) { - try { - $this->prepare($context, $error, [], $message->getPayload())->inject($error, true); - } catch (\Throwable $e) { - throw new Exception('Global error handler had an error: ' . $e->getMessage(). ' on: ' . $e->getFile().':'.$e->getLine(), 500, $e); - } - } - } - } finally { - /** - * Remove Job from Processing. - */ - $this->adapter->connection->listRemove("{$this->adapter->namespace}.processing.{$this->adapter->queue}", $message->getPid()); - - /** - * Decrease Processing Jobs from Stats. - */ - $this->adapter->connection->decrement("{$this->adapter->namespace}.stats.{$this->adapter->queue}.processing"); + foreach ($groups as $group) { + foreach (self::$shutdown as $hook) { // Group shutdown hooks + if (in_array($group, $hook->getGroups())) { + $this->prepare($context, $hook, [], $message->getPayload())->inject($hook, true); } + } + } - $this->resources = []; + foreach (self::$shutdown as $hook) { // Global shutdown hooks + if (in_array('*', $hook->getGroups())) { + $this->prepare($context, $hook, [], $message->getPayload())->inject($hook, true); } - }); + } - $this->adapter->start(); - } catch (Throwable $th) { - $context = clone $this->container; + Console::success("[Job] ({$message->getPid()}) successfully run."); + } catch (\Throwable $th) { + /** + * Move failed Job to Failed list. + */ + $this->adapter->connection->leftPush("{$this->adapter->namespace}.failed.{$this->adapter->queue}", $message->getPid()); + + /** + * Increment Failed Jobs from Stats. + */ + $this->adapter->connection->increment("{$this->adapter->namespace}.stats.{$this->adapter->queue}.failed"); + + Console::error("[Job] ({$message->getPid()}) failed to run."); + Console::error("[Job] ({$message->getPid()}) {$th->getMessage()}"); $dependency = new Dependency(); $context->set( $dependency ->setName('error') ->setCallback(fn () => $th) - ); + ) + ; + + foreach ($groups as $group) { + foreach (self::$errors as $error) { // Group error hooks + if (in_array($group, $error->getGroups())) { + try { + $this->prepare($context, $error, [], $message->getPayload())->inject($error, true); + } catch (\Throwable $e) { + throw new Exception('Group error handler had an error: ' . $e->getMessage(). ' on: ' . $e->getFile().':'.$e->getLine(), 500, $e); + } + } + } + } - foreach (self::$shutdown as $hook) { // Global shutdown hooks - if (in_array('*', $hook->getGroups())) { - $this->prepare($context, $hook, [], [])->inject($hook, true); + foreach (self::$errors as $error) { // Global error hooks + if (in_array('*', $error->getGroups())) { + try { + $this->prepare($context, $error, [], $message->getPayload())->inject($error, true); + } catch (\Throwable $e) { + throw new Exception('Global error handler had an error: ' . $e->getMessage(). ' on: ' . $e->getFile().':'.$e->getLine(), 500, $e); + } } } + } finally { + /** + * Remove Job from Processing. + */ + $this->adapter->connection->listRemove("{$this->adapter->namespace}.processing.{$this->adapter->queue}", $message->getPid()); + + /** + * Decrease Processing Jobs from Stats. + */ + $this->adapter->connection->decrement("{$this->adapter->namespace}.stats.{$this->adapter->queue}.processing"); } - return $this; - } - /** - * Is called when a Worker starts. - * @return Hook - */ - public function workerStart(): Hook - { - $hook = new Hook(); - $hook->groups(['*']); - $this->workerStartHook = $hook; - return $hook; - } - - /** - * Returns Worker starts hook. - * @return Hook - */ - public function getWorkerStart(): Hook - { - return $this->workerStartHook; + return $this; } - - /** - * Is called when a Worker stops. - * @param callable $callback - * @return self - */ - // public function workerStop(callable $callback = null): self - // { - // $container = clone $this->container; - - // try { - // $this->adapter->workerStop(function (string $workerId) use ($this, $container, $callback) { - // Console::success("[Worker] Worker {$workerId} is ready!"); - // if (!is_null($callback)) { - // call_user_func($callback); - // $this->prepare($container, $hook, [], [])->inject($hook, true); - // } - // }); - // } catch (Throwable $error) { - // self::setResource('error', fn () => $error); - // foreach (self::$errors as $error) { // Global error hooks - // if (in_array('*', $error->getGroups())) { - // try { - // $this->prepare($container, $error, [], [])->inject($error, true); - // } catch (\Throwable $e) { - // throw new Exception('Error handler had an error: ' . $e->getMessage(). ' on: ' . $e->getFile().':'.$e->getLine(), 500, $e); - // } - // } - // } - // } - - // return $this; - // } } diff --git a/tests/Queue/servers/Swoole/worker.php b/tests/Queue/servers/Swoole/worker.php index 063eff7..29acc10 100644 --- a/tests/Queue/servers/Swoole/worker.php +++ b/tests/Queue/servers/Swoole/worker.php @@ -63,7 +63,7 @@ public function isValid(mixed $value): bool $container = new Container(); $connection = new Queue\Connection\Redis('redis'); -$adapter = new Queue\Adapter\Swoole($connection, 12, 'swoole'); +$adapter = new Queue\Adapter\Swoole\Server($connection, 1, 'swoole'); $server = new Queue\Server($adapter); $server->setContainer($container); diff --git a/tests/Queue/servers/Workerman/worker.php b/tests/Queue/servers/Workerman/worker.php index 97703c5..ae51966 100644 --- a/tests/Queue/servers/Workerman/worker.php +++ b/tests/Queue/servers/Workerman/worker.php @@ -10,7 +10,7 @@ $container = new Container(); $connection = new Queue\Connection\Redis('redis'); -$adapter = new Queue\Adapter\Workerman($connection, 12, 'workerman'); +$adapter = new Queue\Adapter\Workerman\Server($connection, 12, 'workerman'); $server = new Server($adapter); $server->setContainer($container); From 98c1a7a7ede0e8b3522472ad402cf314c58b17ed Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Fri, 19 Apr 2024 18:03:26 +0200 Subject: [PATCH 08/26] Changed worker class name --- src/Queue/{Server.php => Worker.php} | 2 +- tests/Queue/servers/Swoole/worker.php | 8 ++++---- tests/Queue/servers/Workerman/worker.php | 7 ++++--- 3 files changed, 9 insertions(+), 8 deletions(-) rename src/Queue/{Server.php => Worker.php} (99%) diff --git a/src/Queue/Server.php b/src/Queue/Worker.php similarity index 99% rename from src/Queue/Server.php rename to src/Queue/Worker.php index d3ccecd..c06b626 100644 --- a/src/Queue/Server.php +++ b/src/Queue/Worker.php @@ -9,7 +9,7 @@ use Utopia\DI\Dependency; use Utopia\Servers\Base; -class Server extends Base +class Worker extends Base { /** * Queue Adapter diff --git a/tests/Queue/servers/Swoole/worker.php b/tests/Queue/servers/Swoole/worker.php index 29acc10..48bc0ce 100644 --- a/tests/Queue/servers/Swoole/worker.php +++ b/tests/Queue/servers/Swoole/worker.php @@ -6,7 +6,7 @@ use Utopia\DI\Container; use Utopia\Queue; use Utopia\Queue\Message; -use Utopia\Queue\Server; +use Utopia\Queue\Worker; use Utopia\Servers\Validator; class Text extends Validator @@ -64,7 +64,7 @@ public function isValid(mixed $value): bool $container = new Container(); $connection = new Queue\Connection\Redis('redis'); $adapter = new Queue\Adapter\Swoole\Server($connection, 1, 'swoole'); -$server = new Queue\Server($adapter); +$server = new Queue\Worker($adapter); $server->setContainer($container); // Server::init() @@ -85,13 +85,13 @@ public function isValid(mixed $value): bool // echo "Job start" . PHP_EOL; // }); -Server::job() +Worker::job() ->inject('message') ->action(function (Message $message) { handleRequest($message); }); -Server::error() +Worker::error() ->inject('error') ->action(function ($th) { echo $th->getMessage() . PHP_EOL; diff --git a/tests/Queue/servers/Workerman/worker.php b/tests/Queue/servers/Workerman/worker.php index ae51966..d15aadc 100644 --- a/tests/Queue/servers/Workerman/worker.php +++ b/tests/Queue/servers/Workerman/worker.php @@ -7,20 +7,21 @@ use Utopia\Queue; use Utopia\Queue\Message; use Utopia\Queue\Server; +use Utopia\Queue\Worker; $container = new Container(); $connection = new Queue\Connection\Redis('redis'); $adapter = new Queue\Adapter\Workerman\Server($connection, 12, 'workerman'); -$server = new Server($adapter); +$server = new Worker($adapter); $server->setContainer($container); -Server::job() +Worker::job() ->inject('message') ->action(function (Message $message) { handleRequest($message); }); -Server::error() +Worker::error() ->inject('error') ->action(function ($th) { echo $th->getMessage() . PHP_EOL; From 3baf162971612e4bf7056a176c4f24b9e50c8c8e Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Fri, 19 Apr 2024 18:05:29 +0200 Subject: [PATCH 09/26] Fixed format --- src/Queue/Worker.php | 5 ++--- tests/Queue/servers/Workerman/worker.php | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Queue/Worker.php b/src/Queue/Worker.php index c06b626..daf70fc 100644 --- a/src/Queue/Worker.php +++ b/src/Queue/Worker.php @@ -132,7 +132,7 @@ public function start(): self protected function lifecycle(Job $job, Message $message, array $nextMessage, Container $context): static { Console::info("[Job] Received Job ({$message->getPid()})."); - + $groups = $job->getGroups(); /** @@ -150,9 +150,8 @@ protected function lifecycle(Job $job, Message $message, array $nextMessage, Con * Increment Processing Jobs from Stats. */ $this->adapter->connection->increment("{$this->adapter->namespace}.stats.{$this->adapter->queue}.processing"); - - try { + try { foreach (self::$init as $hook) { // Global init hooks if (in_array('*', $hook->getGroups())) { $this->prepare($context, $hook, [], $message->getPayload())->inject($hook, true); diff --git a/tests/Queue/servers/Workerman/worker.php b/tests/Queue/servers/Workerman/worker.php index d15aadc..f8e49ac 100644 --- a/tests/Queue/servers/Workerman/worker.php +++ b/tests/Queue/servers/Workerman/worker.php @@ -6,7 +6,6 @@ use Utopia\DI\Container; use Utopia\Queue; use Utopia\Queue\Message; -use Utopia\Queue\Server; use Utopia\Queue\Worker; $container = new Container(); From dc1709765db5d303551ff0c7c9bde5d739d7554d Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Fri, 19 Apr 2024 18:32:27 +0200 Subject: [PATCH 10/26] Added async execution --- src/Queue/Adapter/Swoole/Redis.php | 39 +++++++++++++++++++++++++++ src/Queue/Connection.php | 2 ++ src/Queue/Connection/Redis.php | 8 ++++++ src/Queue/Worker.php | 8 ++++-- tests/Queue/servers/Swoole/worker.php | 2 +- 5 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 src/Queue/Adapter/Swoole/Redis.php diff --git a/src/Queue/Adapter/Swoole/Redis.php b/src/Queue/Adapter/Swoole/Redis.php new file mode 100644 index 0000000..f67900c --- /dev/null +++ b/src/Queue/Adapter/Swoole/Redis.php @@ -0,0 +1,39 @@ +pool = new RedisPool((new RedisConfig()) + ->withHost($this->host) + ->withPort((int)$this->port) + ->withAuth((string)$this->password) + , $this->poolSize); + } + + public function getConnection(): void + { + $this->redis = $this->pool->get(); + } + + public function putConnection(): void + { + if(is_null($this->redis)) { + return; + } + + $this->pool->put($this->redis); + } +} \ No newline at end of file diff --git a/src/Queue/Connection.php b/src/Queue/Connection.php index 6f37505..7db470c 100644 --- a/src/Queue/Connection.php +++ b/src/Queue/Connection.php @@ -25,4 +25,6 @@ public function setArray(string $key, array $value): bool; public function increment(string $key): int; public function decrement(string $key): int; public function ping(): bool; + public function getConnection(): void; + public function putConnection(): void; } diff --git a/src/Queue/Connection/Redis.php b/src/Queue/Connection/Redis.php index 4536bb3..1b3bbf7 100644 --- a/src/Queue/Connection/Redis.php +++ b/src/Queue/Connection/Redis.php @@ -181,4 +181,12 @@ protected function getRedis(): \Redis return $this->redis; } + + public function getConnection(): void + { + } + + public function putConnection(): void + { + } } diff --git a/src/Queue/Worker.php b/src/Queue/Worker.php index daf70fc..0f296dc 100644 --- a/src/Queue/Worker.php +++ b/src/Queue/Worker.php @@ -104,7 +104,7 @@ public function start(): self ); $this->adapter->onJob(function () use ($job, $message, $nextMessage, $context) { - $this->lifecycle($job, $message, $nextMessage, $context); + $this->lifecycle($job, $message, $nextMessage, $context, $this->adapter->connection); }); } }); @@ -129,12 +129,14 @@ public function start(): self return $this; } - protected function lifecycle(Job $job, Message $message, array $nextMessage, Container $context): static + protected function lifecycle(Job $job, Message $message, array $nextMessage, Container $context, Connection $connection): static { Console::info("[Job] Received Job ({$message->getPid()})."); $groups = $job->getGroups(); + $connection->getConnection(); + /** * Move Job to Jobs and it's PID to the processing list. */ @@ -247,6 +249,8 @@ protected function lifecycle(Job $job, Message $message, array $nextMessage, Con * Decrease Processing Jobs from Stats. */ $this->adapter->connection->decrement("{$this->adapter->namespace}.stats.{$this->adapter->queue}.processing"); + + $connection->putConnection(); } return $this; diff --git a/tests/Queue/servers/Swoole/worker.php b/tests/Queue/servers/Swoole/worker.php index 48bc0ce..a00251f 100644 --- a/tests/Queue/servers/Swoole/worker.php +++ b/tests/Queue/servers/Swoole/worker.php @@ -62,7 +62,7 @@ public function isValid(mixed $value): bool } $container = new Container(); -$connection = new Queue\Connection\Redis('redis'); +$connection = new Queue\Adapter\Swoole\Redis('redis'); $adapter = new Queue\Adapter\Swoole\Server($connection, 1, 'swoole'); $server = new Queue\Worker($adapter); $server->setContainer($container); From a3f8b383ef0b511e73d1fb51acd521f2e33a68cf Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Sun, 21 Apr 2024 08:35:52 +0200 Subject: [PATCH 11/26] Added Redis insights --- docker-compose.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 8add0d9..97b04df 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -34,4 +34,12 @@ services: container_name: redis image: "redis:alpine" ports: - - "9303:6379" \ No newline at end of file + - "9303:6379" + + redis-insight: + image: redis/redisinsight:latest + restart: unless-stopped + environment: + - REDIS_HOSTS=redis + ports: + - "9304:5540" \ No newline at end of file From 071069372c92e4dd6d058822b1236fa67377e6d3 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Sun, 21 Apr 2024 08:37:38 +0200 Subject: [PATCH 12/26] Added load testing script --- src/Queue/Worker.php | 20 ++--- tests/Queue/servers/Swoole/load.php | 123 ++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+), 10 deletions(-) create mode 100644 tests/Queue/servers/Swoole/load.php diff --git a/src/Queue/Worker.php b/src/Queue/Worker.php index 0f296dc..a0074c2 100644 --- a/src/Queue/Worker.php +++ b/src/Queue/Worker.php @@ -140,18 +140,18 @@ protected function lifecycle(Job $job, Message $message, array $nextMessage, Con /** * Move Job to Jobs and it's PID to the processing list. */ - $this->adapter->connection->setArray("{$this->adapter->namespace}.jobs.{$this->adapter->queue}.{$message->getPid()}", $nextMessage); - $this->adapter->connection->leftPush("{$this->adapter->namespace}.processing.{$this->adapter->queue}", $message->getPid()); + $connection->setArray("{$this->adapter->namespace}.jobs.{$this->adapter->queue}.{$message->getPid()}", $nextMessage); + $connection->leftPush("{$this->adapter->namespace}.processing.{$this->adapter->queue}", $message->getPid()); /** * Increment Total Jobs Received from Stats. */ - $this->adapter->connection->increment("{$this->adapter->namespace}.stats.{$this->adapter->queue}.total"); + $connection->increment("{$this->adapter->namespace}.stats.{$this->adapter->queue}.total"); /** * Increment Processing Jobs from Stats. */ - $this->adapter->connection->increment("{$this->adapter->namespace}.stats.{$this->adapter->queue}.processing"); + $connection->increment("{$this->adapter->namespace}.stats.{$this->adapter->queue}.processing"); try { foreach (self::$init as $hook) { // Global init hooks @@ -173,12 +173,12 @@ protected function lifecycle(Job $job, Message $message, array $nextMessage, Con /** * Remove Jobs if successful. */ - $this->adapter->connection->remove("{$this->adapter->namespace}.jobs.{$this->adapter->queue}.{$message->getPid()}"); + $connection->remove("{$this->adapter->namespace}.jobs.{$this->adapter->queue}.{$message->getPid()}"); /** * Increment Successful Jobs from Stats. */ - $this->adapter->connection->increment("{$this->adapter->namespace}.stats.{$this->adapter->queue}.success"); + $connection->increment("{$this->adapter->namespace}.stats.{$this->adapter->queue}.success"); foreach ($groups as $group) { @@ -200,12 +200,12 @@ protected function lifecycle(Job $job, Message $message, array $nextMessage, Con /** * Move failed Job to Failed list. */ - $this->adapter->connection->leftPush("{$this->adapter->namespace}.failed.{$this->adapter->queue}", $message->getPid()); + $connection->leftPush("{$this->adapter->namespace}.failed.{$this->adapter->queue}", $message->getPid()); /** * Increment Failed Jobs from Stats. */ - $this->adapter->connection->increment("{$this->adapter->namespace}.stats.{$this->adapter->queue}.failed"); + $connection->increment("{$this->adapter->namespace}.stats.{$this->adapter->queue}.failed"); Console::error("[Job] ({$message->getPid()}) failed to run."); Console::error("[Job] ({$message->getPid()}) {$th->getMessage()}"); @@ -243,12 +243,12 @@ protected function lifecycle(Job $job, Message $message, array $nextMessage, Con /** * Remove Job from Processing. */ - $this->adapter->connection->listRemove("{$this->adapter->namespace}.processing.{$this->adapter->queue}", $message->getPid()); + $connection->listRemove("{$this->adapter->namespace}.processing.{$this->adapter->queue}", $message->getPid()); /** * Decrease Processing Jobs from Stats. */ - $this->adapter->connection->decrement("{$this->adapter->namespace}.stats.{$this->adapter->queue}.processing"); + $connection->decrement("{$this->adapter->namespace}.stats.{$this->adapter->queue}.processing"); $connection->putConnection(); } diff --git a/tests/Queue/servers/Swoole/load.php b/tests/Queue/servers/Swoole/load.php new file mode 100644 index 0000000..eb067d8 --- /dev/null +++ b/tests/Queue/servers/Swoole/load.php @@ -0,0 +1,123 @@ +enqueue(['id' => $i, 'time' => $time]); + // break; + if ($i % 10000 === 0) { + Console::log('Loaded ' . $i . ' jobs'); + } +} + +Console::log('Finished loading queue'); + +sleep($sleep); + +$container = new Container(); +$connection = new Queue\Adapter\Swoole\Redis('redis'); +$connection = new Queue\Connection\Redis('redis'); +$adapter = new Queue\Adapter\Swoole\Server($connection, 9000, 'swoole'); +$server = new Queue\Worker($adapter); +$server->setContainer($container); + +Worker::job() + ->param('id', 0, new Text(), 'Message ID', true) + ->param('time', 0, new Text(), 'Message ID', true) + ->inject('message') + ->action(function ($id, $time, $message) use ($jobs, $sleep) { + // usleep(100000); + if($time) { + $currentTimestamp = time(); + $timeDiff = ($currentTimestamp - $time) - $sleep; + $humanReadableDiff = formatTimeDiff($timeDiff); + Console::warning('Time took to process until job #'.$id . '/'. $jobs . ' jobs: '.$humanReadableDiff); + } + + }); + +Worker::error() + ->inject('error') + ->action(function ($th) { + echo $th->getMessage() . PHP_EOL; + exit(); + }); + +$server->start(); From aa95c26b5eeeb276181fbcd68f86d10982c0e746 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Sun, 21 Apr 2024 08:39:33 +0200 Subject: [PATCH 13/26] Fix format --- tests/Queue/servers/Swoole/load.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/Queue/servers/Swoole/load.php b/tests/Queue/servers/Swoole/load.php index eb067d8..5429bbb 100644 --- a/tests/Queue/servers/Swoole/load.php +++ b/tests/Queue/servers/Swoole/load.php @@ -104,13 +104,12 @@ public function isValid(mixed $value): bool ->inject('message') ->action(function ($id, $time, $message) use ($jobs, $sleep) { // usleep(100000); - if($time) { + if ($time) { $currentTimestamp = time(); $timeDiff = ($currentTimestamp - $time) - $sleep; $humanReadableDiff = formatTimeDiff($timeDiff); Console::warning('Time took to process until job #'.$id . '/'. $jobs . ' jobs: '.$humanReadableDiff); } - }); Worker::error() From ef8686171e4645428e613f6dab72a07975b35b6c Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Sun, 21 Apr 2024 08:41:57 +0200 Subject: [PATCH 14/26] Redis adapter for Swoole --- src/Queue/Adapter/Swoole/Redis.php | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/Queue/Adapter/Swoole/Redis.php b/src/Queue/Adapter/Swoole/Redis.php index f67900c..a9a43e5 100644 --- a/src/Queue/Adapter/Swoole/Redis.php +++ b/src/Queue/Adapter/Swoole/Redis.php @@ -10,17 +10,21 @@ class Redis extends ConnectionRedis { protected RedisPool $pool; - protected int $poolSize = 50; + protected int $poolSize = 5; public function __construct(string $host, int $port = 6379, ?string $user = null, ?string $password = null) { - parent::__construct($host, $port, $user, $password); + $this->host = $host; + $this->port = $port; + $this->user = $user; + $this->password = $password; + + $auth = (empty($this->user) || empty($this->password)) ? $this->user.$this->password : implode(':', array_filter([$this->user, $this->password])); $this->pool = new RedisPool((new RedisConfig()) ->withHost($this->host) - ->withPort((int)$this->port) - ->withAuth((string)$this->password) - , $this->poolSize); + ->withPort($this->port) + ->withAuth($auth), $this->poolSize); } public function getConnection(): void @@ -30,10 +34,19 @@ public function getConnection(): void public function putConnection(): void { - if(is_null($this->redis)) { + if (is_null($this->redis)) { return; } $this->pool->put($this->redis); } -} \ No newline at end of file + + protected function getRedis(): \Redis + { + if (empty($this->redis)) { + $this->redis = $this->pool->get(); + } + + return $this->redis; + } +} From c1655007ccbbfec8b02ea308e62061407fb97066 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Sun, 21 Apr 2024 19:46:39 +0200 Subject: [PATCH 15/26] Updated composer --- composer.json | 2 +- composer.lock | 161 ++++++++++++++++++++++++++------------------------ 2 files changed, 85 insertions(+), 78 deletions(-) diff --git a/composer.json b/composer.json index ad8dddd..8c1fbbe 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "type": "library", "keywords": ["php","framework", "upf", "utopia", "tasks", "queue"], "license": "MIT", - "minimum-stability": "stable", + "minimum-stability": "dev", "authors": [ { "name": "Torsten Dittmann", diff --git a/composer.lock b/composer.lock index 21ea5af..b2ecf3e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7ae591bf6380d4469179b803c24cdae8", + "content-hash": "28429f5229ee1b7a6baefe37eaee0832", "packages": [ { "name": "utopia-php/cli", @@ -240,31 +240,32 @@ "packages-dev": [ { "name": "doctrine/instantiator", - "version": "2.0.0", + "version": "2.0.x-dev", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "c6222283fa3f4ac679f8b9ced9a4e23f163e80d0" + "reference": "6c0ee619435c5d4f3bc515ab1514cf4cf1006c6e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/c6222283fa3f4ac679f8b9ced9a4e23f163e80d0", - "reference": "c6222283fa3f4ac679f8b9ced9a4e23f163e80d0", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/6c0ee619435c5d4f3bc515ab1514cf4cf1006c6e", + "reference": "6c0ee619435c5d4f3bc515ab1514cf4cf1006c6e", "shasum": "" }, "require": { "php": "^8.1" }, "require-dev": { - "doctrine/coding-standard": "^11", + "doctrine/coding-standard": "^12", "ext-pdo": "*", "ext-phar": "*", "phpbench/phpbench": "^1.2", "phpstan/phpstan": "^1.9.4", "phpstan/phpstan-phpunit": "^1.3", - "phpunit/phpunit": "^9.5.27", + "phpunit/phpunit": "^10.5", "vimeo/psalm": "^5.4" }, + "default-branch": true, "type": "library", "autoload": { "psr-4": { @@ -290,7 +291,7 @@ ], "support": { "issues": "https://github.com/doctrine/instantiator/issues", - "source": "https://github.com/doctrine/instantiator/tree/2.0.0" + "source": "https://github.com/doctrine/instantiator/tree/2.0.x" }, "funding": [ { @@ -306,7 +307,7 @@ "type": "tidelift" } ], - "time": "2022-12-30T00:23:10+00:00" + "time": "2023-12-09T14:19:21+00:00" }, { "name": "laravel/pint", @@ -376,16 +377,16 @@ }, { "name": "myclabs/deep-copy", - "version": "1.11.1", + "version": "1.x-dev", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c" + "reference": "2f5294676c802a62b0549f6bc8983f14294ce369" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/7284c22080590fb39f2ffa3e9057f10a4ddd0e0c", - "reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/2f5294676c802a62b0549f6bc8983f14294ce369", + "reference": "2f5294676c802a62b0549f6bc8983f14294ce369", "shasum": "" }, "require": { @@ -393,13 +394,15 @@ }, "conflict": { "doctrine/collections": "<1.6.8", - "doctrine/common": "<2.13.3 || >=3,<3.2.2" + "doctrine/common": "<2.13.3 || >=3 <3.2.2" }, "require-dev": { "doctrine/collections": "^1.6.8", "doctrine/common": "^2.13.3 || ^3.2.2", + "phpspec/prophecy": "^1.10", "phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13" }, + "default-branch": true, "type": "library", "autoload": { "files": [ @@ -423,7 +426,7 @@ ], "support": { "issues": "https://github.com/myclabs/DeepCopy/issues", - "source": "https://github.com/myclabs/DeepCopy/tree/1.11.1" + "source": "https://github.com/myclabs/DeepCopy/tree/1.x" }, "funding": [ { @@ -431,20 +434,20 @@ "type": "tidelift" } ], - "time": "2023-03-08T13:26:56+00:00" + "time": "2024-02-10T11:10:03+00:00" }, { "name": "nikic/php-parser", - "version": "v5.0.2", + "version": "dev-master", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "139676794dc1e9231bf7bcd123cfc0c99182cb13" + "reference": "c5ee33df86c06b3278c670f64273b1ba768a0744" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/139676794dc1e9231bf7bcd123cfc0c99182cb13", - "reference": "139676794dc1e9231bf7bcd123cfc0c99182cb13", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/c5ee33df86c06b3278c670f64273b1ba768a0744", + "reference": "c5ee33df86c06b3278c670f64273b1ba768a0744", "shasum": "" }, "require": { @@ -455,8 +458,9 @@ }, "require-dev": { "ircmaxell/php-yacc": "^0.0.7", - "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0" + "phpunit/phpunit": "^9.0" }, + "default-branch": true, "bin": [ "bin/php-parse" ], @@ -487,13 +491,13 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v5.0.2" + "source": "https://github.com/nikic/PHP-Parser/tree/master" }, - "time": "2024-03-05T20:51:40+00:00" + "time": "2024-04-19T12:04:10+00:00" }, { "name": "phar-io/manifest", - "version": "2.0.4", + "version": "dev-master", "source": { "type": "git", "url": "https://github.com/phar-io/manifest.git", @@ -513,6 +517,7 @@ "phar-io/version": "^3.0.1", "php": "^7.2 || ^8.0" }, + "default-branch": true, "type": "library", "extra": { "branch-alias": { @@ -611,16 +616,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.10.67", + "version": "1.11.x-dev", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "16ddbe776f10da6a95ebd25de7c1dbed397dc493" + "reference": "7b52251fae7e1ab8dae54b91d3a5d6f6d52390f0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/16ddbe776f10da6a95ebd25de7c1dbed397dc493", - "reference": "16ddbe776f10da6a95ebd25de7c1dbed397dc493", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/7b52251fae7e1ab8dae54b91d3a5d6f6d52390f0", + "reference": "7b52251fae7e1ab8dae54b91d3a5d6f6d52390f0", "shasum": "" }, "require": { @@ -629,6 +634,7 @@ "conflict": { "phpstan/phpstan-shim": "*" }, + "default-branch": true, "bin": [ "phpstan", "phpstan.phar" @@ -665,20 +671,20 @@ "type": "github" } ], - "time": "2024-04-16T07:22:02+00:00" + "time": "2024-04-21T14:58:44+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "9.2.31", + "version": "9.2.x-dev", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "48c34b5d8d983006bd2adc2d0de92963b9155965" + "reference": "3352293d9e91513d5508c415835014881b420218" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/48c34b5d8d983006bd2adc2d0de92963b9155965", - "reference": "48c34b5d8d983006bd2adc2d0de92963b9155965", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/3352293d9e91513d5508c415835014881b420218", + "reference": "3352293d9e91513d5508c415835014881b420218", "shasum": "" }, "require": { @@ -735,7 +741,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.31" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2" }, "funding": [ { @@ -743,20 +749,20 @@ "type": "github" } ], - "time": "2024-03-02T06:37:42+00:00" + "time": "2024-03-22T05:16:32+00:00" }, { "name": "phpunit/php-file-iterator", - "version": "3.0.6", + "version": "3.0.x-dev", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf" + "reference": "38b24367e1b340aa78b96d7cab042942d917bb84" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf", - "reference": "cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/38b24367e1b340aa78b96d7cab042942d917bb84", + "reference": "38b24367e1b340aa78b96d7cab042942d917bb84", "shasum": "" }, "require": { @@ -795,7 +801,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", - "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/3.0.6" + "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/3.0" }, "funding": [ { @@ -803,7 +809,7 @@ "type": "github" } ], - "time": "2021-12-02T12:48:52+00:00" + "time": "2022-02-11T16:23:04+00:00" }, { "name": "phpunit/php-invoker", @@ -988,16 +994,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.6.19", + "version": "9.6.x-dev", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "a1a54a473501ef4cdeaae4e06891674114d79db8" + "reference": "33a0610878994fc134c74c25d5276d606d49079b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a1a54a473501ef4cdeaae4e06891674114d79db8", - "reference": "a1a54a473501ef4cdeaae4e06891674114d79db8", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/33a0610878994fc134c74c25d5276d606d49079b", + "reference": "33a0610878994fc134c74c25d5276d606d49079b", "shasum": "" }, "require": { @@ -1071,7 +1077,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.19" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6" }, "funding": [ { @@ -1087,11 +1093,11 @@ "type": "tidelift" } ], - "time": "2024-04-05T04:35:58+00:00" + "time": "2024-04-20T06:05:08+00:00" }, { "name": "sebastian/cli-parser", - "version": "1.0.2", + "version": "1.0.x-dev", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/cli-parser.git", @@ -1258,16 +1264,16 @@ }, { "name": "sebastian/comparator", - "version": "4.0.8", + "version": "4.0.x-dev", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "fa0f136dd2334583309d32b62544682ee972b51a" + "reference": "b247957a1c8dc81a671770f74b479c0a78a818f1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/fa0f136dd2334583309d32b62544682ee972b51a", - "reference": "fa0f136dd2334583309d32b62544682ee972b51a", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/b247957a1c8dc81a671770f74b479c0a78a818f1", + "reference": "b247957a1c8dc81a671770f74b479c0a78a818f1", "shasum": "" }, "require": { @@ -1320,7 +1326,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/comparator/issues", - "source": "https://github.com/sebastianbergmann/comparator/tree/4.0.8" + "source": "https://github.com/sebastianbergmann/comparator/tree/4.0" }, "funding": [ { @@ -1328,11 +1334,11 @@ "type": "github" } ], - "time": "2022-09-14T12:41:17+00:00" + "time": "2022-09-14T12:46:14+00:00" }, { "name": "sebastian/complexity", - "version": "2.0.3", + "version": "2.0.x-dev", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/complexity.git", @@ -1389,7 +1395,7 @@ }, { "name": "sebastian/diff", - "version": "4.0.6", + "version": "4.0.x-dev", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", @@ -1455,7 +1461,7 @@ }, { "name": "sebastian/environment", - "version": "5.1.5", + "version": "5.1.x-dev", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", @@ -1506,7 +1512,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/environment/issues", - "source": "https://github.com/sebastianbergmann/environment/tree/5.1.5" + "source": "https://github.com/sebastianbergmann/environment/tree/5.1" }, "funding": [ { @@ -1518,7 +1524,7 @@ }, { "name": "sebastian/exporter", - "version": "4.0.6", + "version": "4.0.x-dev", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", @@ -1595,7 +1601,7 @@ }, { "name": "sebastian/global-state", - "version": "5.0.7", + "version": "5.0.x-dev", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", @@ -1659,7 +1665,7 @@ }, { "name": "sebastian/lines-of-code", - "version": "1.0.4", + "version": "1.0.x-dev", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/lines-of-code.git", @@ -1828,7 +1834,7 @@ }, { "name": "sebastian/recursion-context", - "version": "4.0.5", + "version": "4.0.x-dev", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/recursion-context.git", @@ -1891,16 +1897,16 @@ }, { "name": "sebastian/resource-operations", - "version": "3.0.4", + "version": "dev-main", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/resource-operations.git", - "reference": "05d5692a7993ecccd56a03e40cd7e5b09b1d404e" + "reference": "ff553e7482dcee39fa4acc2b175d6ddeb0f7bc25" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/05d5692a7993ecccd56a03e40cd7e5b09b1d404e", - "reference": "05d5692a7993ecccd56a03e40cd7e5b09b1d404e", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/ff553e7482dcee39fa4acc2b175d6ddeb0f7bc25", + "reference": "ff553e7482dcee39fa4acc2b175d6ddeb0f7bc25", "shasum": "" }, "require": { @@ -1909,6 +1915,7 @@ "require-dev": { "phpunit/phpunit": "^9.0" }, + "default-branch": true, "type": "library", "extra": { "branch-alias": { @@ -1933,7 +1940,7 @@ "description": "Provides a list of PHP built-in functions that operate on resources", "homepage": "https://www.github.com/sebastianbergmann/resource-operations", "support": { - "source": "https://github.com/sebastianbergmann/resource-operations/tree/3.0.4" + "source": "https://github.com/sebastianbergmann/resource-operations/tree/main" }, "funding": [ { @@ -1941,11 +1948,11 @@ "type": "github" } ], - "time": "2024-03-14T16:00:52+00:00" + "time": "2024-03-14T18:47:08+00:00" }, { "name": "sebastian/type", - "version": "3.2.1", + "version": "3.2.x-dev", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/type.git", @@ -1989,7 +1996,7 @@ "homepage": "https://github.com/sebastianbergmann/type", "support": { "issues": "https://github.com/sebastianbergmann/type/issues", - "source": "https://github.com/sebastianbergmann/type/tree/3.2.1" + "source": "https://github.com/sebastianbergmann/type/tree/3.2" }, "funding": [ { @@ -2001,7 +2008,7 @@ }, { "name": "sebastian/version", - "version": "3.0.2", + "version": "3.0.x-dev", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/version.git", @@ -2146,16 +2153,16 @@ }, { "name": "workerman/workerman", - "version": "v4.1.15", + "version": "4.1.x-dev", "source": { "type": "git", "url": "https://github.com/walkor/workerman.git", - "reference": "afc8242fc769ab7cf22eb4ac22b97cb59d465e4e" + "reference": "ac27d373acc9943630a140181ac279ee37362156" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/walkor/workerman/zipball/afc8242fc769ab7cf22eb4ac22b97cb59d465e4e", - "reference": "afc8242fc769ab7cf22eb4ac22b97cb59d465e4e", + "url": "https://api.github.com/repos/walkor/workerman/zipball/ac27d373acc9943630a140181ac279ee37362156", + "reference": "ac27d373acc9943630a140181ac279ee37362156", "shasum": "" }, "require": { @@ -2205,11 +2212,11 @@ "type": "patreon" } ], - "time": "2024-02-19T02:10:39+00:00" + "time": "2024-03-23T00:47:05+00:00" } ], "aliases": [], - "minimum-stability": "stable", + "minimum-stability": "dev", "stability-flags": { "utopia-php/servers": 20, "utopia-php/di": 20 From 309796b08891eac135540c241d8943dd42eccc9e Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Sun, 21 Apr 2024 20:59:04 +0200 Subject: [PATCH 16/26] Updated composer --- composer.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.lock b/composer.lock index b2ecf3e..dc97363 100644 --- a/composer.lock +++ b/composer.lock @@ -171,12 +171,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/servers.git", - "reference": "43881ed83f97cb31af7f940db74c520c70b914ab" + "reference": "20bb7ab93c21d0ae37bc309d41b70ddf2a78a6fd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/servers/zipball/43881ed83f97cb31af7f940db74c520c70b914ab", - "reference": "43881ed83f97cb31af7f940db74c520c70b914ab", + "url": "https://api.github.com/repos/utopia-php/servers/zipball/20bb7ab93c21d0ae37bc309d41b70ddf2a78a6fd", + "reference": "20bb7ab93c21d0ae37bc309d41b70ddf2a78a6fd", "shasum": "" }, "require": { @@ -234,7 +234,7 @@ "source": "https://github.com/utopia-php/servers/tree/dev", "issues": "https://github.com/utopia-php/servers/issues" }, - "time": "2024-04-18T20:51:43+00:00" + "time": "2024-04-21T18:53:43+00:00" } ], "packages-dev": [ From 8749796c05bf9a0abc9c949af5ceb2efa8531960 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Mon, 22 Apr 2024 20:32:34 +0200 Subject: [PATCH 17/26] Added reconnection logic --- src/Queue/Worker.php | 17 +++++++++++++++++ tests/Queue/servers/Swoole/load.php | 6 +++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/Queue/Worker.php b/src/Queue/Worker.php index a0074c2..31e8d42 100644 --- a/src/Queue/Worker.php +++ b/src/Queue/Worker.php @@ -78,6 +78,23 @@ public function start(): self { try { $this->adapter->onWorkerStart(function (string $workerId) { + // Check if the connection is ready + $retryAttempts = 30; + $retryDelay = 1; // seconds + + while (!$this->adapter->connection->ping()) { + if ($retryAttempts <= 0) { + Console::error("[Worker] connection is not ready. Exiting..."); + return $this; + } + + $retryAttempts--; + + Console::warning("[Worker] connection is not ready. Retrying in {$retryDelay} seconds [{$retryAttempts} left] ..."); + + sleep($retryDelay); + } + Console::success("[Worker] Worker {$workerId} is ready!"); while (true) { diff --git a/tests/Queue/servers/Swoole/load.php b/tests/Queue/servers/Swoole/load.php index 5429bbb..e5969cb 100644 --- a/tests/Queue/servers/Swoole/load.php +++ b/tests/Queue/servers/Swoole/load.php @@ -71,7 +71,7 @@ public function isValid(mixed $value): bool return true; } } -$jobs = 100000; +$jobs = 10000000; $sleep = 0; $connection = new Redis('redis', 6379); $client = new Client('swoole', $connection); @@ -92,9 +92,9 @@ public function isValid(mixed $value): bool sleep($sleep); $container = new Container(); -$connection = new Queue\Adapter\Swoole\Redis('redis'); +// $connection = new Queue\Adapter\Swoole\Redis('redis'); $connection = new Queue\Connection\Redis('redis'); -$adapter = new Queue\Adapter\Swoole\Server($connection, 9000, 'swoole'); +$adapter = new Queue\Adapter\Swoole\Server($connection, 1000, 'swoole'); $server = new Queue\Worker($adapter); $server->setContainer($container); From 2133eb6da85156ff4abf0d0940715fa3975424f2 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Mon, 22 Apr 2024 23:24:21 +0200 Subject: [PATCH 18/26] Updated composer --- composer.lock | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/composer.lock b/composer.lock index dc97363..24a9e23 100644 --- a/composer.lock +++ b/composer.lock @@ -61,12 +61,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/di.git", - "reference": "fb3c45b268018b87dcbbf87ad943ced9eea3bbe2" + "reference": "a0c8be65c19570c80e904d58f54bdd901d1d5d9c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/di/zipball/fb3c45b268018b87dcbbf87ad943ced9eea3bbe2", - "reference": "fb3c45b268018b87dcbbf87ad943ced9eea3bbe2", + "url": "https://api.github.com/repos/utopia-php/di/zipball/a0c8be65c19570c80e904d58f54bdd901d1d5d9c", + "reference": "a0c8be65c19570c80e904d58f54bdd901d1d5d9c", "shasum": "" }, "require": { @@ -115,7 +115,7 @@ "source": "https://github.com/utopia-php/di/tree/main", "issues": "https://github.com/utopia-php/di/issues" }, - "time": "2024-04-18T20:06:02+00:00" + "time": "2024-04-22T21:22:44+00:00" }, { "name": "utopia-php/framework", @@ -171,12 +171,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/servers.git", - "reference": "20bb7ab93c21d0ae37bc309d41b70ddf2a78a6fd" + "reference": "e7eee7f82399c89adc28cf79912a9a41d7bb3233" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/servers/zipball/20bb7ab93c21d0ae37bc309d41b70ddf2a78a6fd", - "reference": "20bb7ab93c21d0ae37bc309d41b70ddf2a78a6fd", + "url": "https://api.github.com/repos/utopia-php/servers/zipball/e7eee7f82399c89adc28cf79912a9a41d7bb3233", + "reference": "e7eee7f82399c89adc28cf79912a9a41d7bb3233", "shasum": "" }, "require": { @@ -234,7 +234,7 @@ "source": "https://github.com/utopia-php/servers/tree/dev", "issues": "https://github.com/utopia-php/servers/issues" }, - "time": "2024-04-21T18:53:43+00:00" + "time": "2024-04-22T21:23:28+00:00" } ], "packages-dev": [ @@ -620,12 +620,12 @@ "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "7b52251fae7e1ab8dae54b91d3a5d6f6d52390f0" + "reference": "3b03bac1068a585926a14e97692baef8642c2a1b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/7b52251fae7e1ab8dae54b91d3a5d6f6d52390f0", - "reference": "7b52251fae7e1ab8dae54b91d3a5d6f6d52390f0", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/3b03bac1068a585926a14e97692baef8642c2a1b", + "reference": "3b03bac1068a585926a14e97692baef8642c2a1b", "shasum": "" }, "require": { @@ -671,7 +671,7 @@ "type": "github" } ], - "time": "2024-04-21T14:58:44+00:00" + "time": "2024-04-22T13:39:03+00:00" }, { "name": "phpunit/php-code-coverage", From 016734a52eeca27f593c17050c4382319fb4a28a Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Fri, 7 Jun 2024 14:43:28 -0400 Subject: [PATCH 19/26] chore: Updating DI branch --- composer.json | 2 +- composer.lock | 65 +++++++++++++++++++++++++-------------------------- 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/composer.json b/composer.json index 8c1fbbe..3cdb60c 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "php": ">=8.0", "utopia-php/cli": "0.17.*", "utopia-php/servers": "dev-dev", - "utopia-php/di": "dev-main" + "utopia-php/di": "dev-dev" }, "require-dev": { "swoole/ide-helper": "4.8.8", diff --git a/composer.lock b/composer.lock index 24a9e23..546ec72 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "28429f5229ee1b7a6baefe37eaee0832", + "content-hash": "ea226502601a964fa455bc36130cd5e6", "packages": [ { "name": "utopia-php/cli", @@ -57,16 +57,16 @@ }, { "name": "utopia-php/di", - "version": "dev-main", + "version": "dev-dev", "source": { "type": "git", "url": "https://github.com/utopia-php/di.git", - "reference": "a0c8be65c19570c80e904d58f54bdd901d1d5d9c" + "reference": "ee69270a68df00a44af86f1deffb0b7c12aca944" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/di/zipball/a0c8be65c19570c80e904d58f54bdd901d1d5d9c", - "reference": "a0c8be65c19570c80e904d58f54bdd901d1d5d9c", + "url": "https://api.github.com/repos/utopia-php/di/zipball/ee69270a68df00a44af86f1deffb0b7c12aca944", + "reference": "ee69270a68df00a44af86f1deffb0b7c12aca944", "shasum": "" }, "require": { @@ -79,7 +79,6 @@ "phpunit/phpunit": "^9.5.25", "swoole/ide-helper": "4.8.3" }, - "default-branch": true, "type": "library", "autoload": { "psr-4": { @@ -112,10 +111,10 @@ "upf" ], "support": { - "source": "https://github.com/utopia-php/di/tree/main", + "source": "https://github.com/utopia-php/di/tree/dev", "issues": "https://github.com/utopia-php/di/issues" }, - "time": "2024-04-22T21:22:44+00:00" + "time": "2024-06-07T18:31:56+00:00" }, { "name": "utopia-php/framework", @@ -171,17 +170,17 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/servers.git", - "reference": "e7eee7f82399c89adc28cf79912a9a41d7bb3233" + "reference": "e751e03860df4dca60a3e31a32ee62613a3d0280" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/servers/zipball/e7eee7f82399c89adc28cf79912a9a41d7bb3233", - "reference": "e7eee7f82399c89adc28cf79912a9a41d7bb3233", + "url": "https://api.github.com/repos/utopia-php/servers/zipball/e751e03860df4dca60a3e31a32ee62613a3d0280", + "reference": "e751e03860df4dca60a3e31a32ee62613a3d0280", "shasum": "" }, "require": { "php": ">=8.0", - "utopia-php/di": "dev-main" + "utopia-php/di": "dev-dev" }, "require-dev": { "laravel/pint": "^0.2.3", @@ -234,7 +233,7 @@ "source": "https://github.com/utopia-php/servers/tree/dev", "issues": "https://github.com/utopia-php/servers/issues" }, - "time": "2024-04-22T21:23:28+00:00" + "time": "2024-06-07T18:38:46+00:00" } ], "packages-dev": [ @@ -244,12 +243,12 @@ "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "6c0ee619435c5d4f3bc515ab1514cf4cf1006c6e" + "reference": "9955122a490d18ce723cf9014b196c126222c180" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/6c0ee619435c5d4f3bc515ab1514cf4cf1006c6e", - "reference": "6c0ee619435c5d4f3bc515ab1514cf4cf1006c6e", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/9955122a490d18ce723cf9014b196c126222c180", + "reference": "9955122a490d18ce723cf9014b196c126222c180", "shasum": "" }, "require": { @@ -307,7 +306,7 @@ "type": "tidelift" } ], - "time": "2023-12-09T14:19:21+00:00" + "time": "2024-05-05T15:09:38+00:00" }, { "name": "laravel/pint", @@ -442,12 +441,12 @@ "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "c5ee33df86c06b3278c670f64273b1ba768a0744" + "reference": "daaadc3bae458908aa477b90a8932e7da9253f22" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/c5ee33df86c06b3278c670f64273b1ba768a0744", - "reference": "c5ee33df86c06b3278c670f64273b1ba768a0744", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/daaadc3bae458908aa477b90a8932e7da9253f22", + "reference": "daaadc3bae458908aa477b90a8932e7da9253f22", "shasum": "" }, "require": { @@ -493,7 +492,7 @@ "issues": "https://github.com/nikic/PHP-Parser/issues", "source": "https://github.com/nikic/PHP-Parser/tree/master" }, - "time": "2024-04-19T12:04:10+00:00" + "time": "2024-06-03T06:24:19+00:00" }, { "name": "phar-io/manifest", @@ -620,12 +619,12 @@ "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "3b03bac1068a585926a14e97692baef8642c2a1b" + "reference": "80b404fb7a47b1416ed37b9fe33793ad32e714a6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/3b03bac1068a585926a14e97692baef8642c2a1b", - "reference": "3b03bac1068a585926a14e97692baef8642c2a1b", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/80b404fb7a47b1416ed37b9fe33793ad32e714a6", + "reference": "80b404fb7a47b1416ed37b9fe33793ad32e714a6", "shasum": "" }, "require": { @@ -671,7 +670,7 @@ "type": "github" } ], - "time": "2024-04-22T13:39:03+00:00" + "time": "2024-06-07T10:21:58+00:00" }, { "name": "phpunit/php-code-coverage", @@ -998,12 +997,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "33a0610878994fc134c74c25d5276d606d49079b" + "reference": "feb499300d9595ea4587e7448ea990263bc47c10" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/33a0610878994fc134c74c25d5276d606d49079b", - "reference": "33a0610878994fc134c74c25d5276d606d49079b", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/feb499300d9595ea4587e7448ea990263bc47c10", + "reference": "feb499300d9595ea4587e7448ea990263bc47c10", "shasum": "" }, "require": { @@ -1093,7 +1092,7 @@ "type": "tidelift" } ], - "time": "2024-04-20T06:05:08+00:00" + "time": "2024-06-07T04:40:16+00:00" }, { "name": "sebastian/cli-parser", @@ -2157,12 +2156,12 @@ "source": { "type": "git", "url": "https://github.com/walkor/workerman.git", - "reference": "ac27d373acc9943630a140181ac279ee37362156" + "reference": "4b35b7ea5785121059613a9943b3509a79cbb077" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/walkor/workerman/zipball/ac27d373acc9943630a140181ac279ee37362156", - "reference": "ac27d373acc9943630a140181ac279ee37362156", + "url": "https://api.github.com/repos/walkor/workerman/zipball/4b35b7ea5785121059613a9943b3509a79cbb077", + "reference": "4b35b7ea5785121059613a9943b3509a79cbb077", "shasum": "" }, "require": { @@ -2212,7 +2211,7 @@ "type": "patreon" } ], - "time": "2024-03-23T00:47:05+00:00" + "time": "2024-06-04T14:22:00+00:00" } ], "aliases": [], From cad5651b38f0f69e20e805424d0c29818c15c174 Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Fri, 7 Jun 2024 14:50:32 -0400 Subject: [PATCH 20/26] chore: Updating DI branch --- composer.json | 2 +- composer.lock | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/composer.json b/composer.json index 3cdb60c..da9cb9e 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "php": ">=8.0", "utopia-php/cli": "0.17.*", "utopia-php/servers": "dev-dev", - "utopia-php/di": "dev-dev" + "utopia-php/di": "dev-feat-framework-v2" }, "require-dev": { "swoole/ide-helper": "4.8.8", diff --git a/composer.lock b/composer.lock index 546ec72..54bdc39 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ea226502601a964fa455bc36130cd5e6", + "content-hash": "b68549a5e9847efd3a2dabe9a81c1123", "packages": [ { "name": "utopia-php/cli", @@ -57,16 +57,16 @@ }, { "name": "utopia-php/di", - "version": "dev-dev", + "version": "dev-feat-framework-v2", "source": { "type": "git", "url": "https://github.com/utopia-php/di.git", - "reference": "ee69270a68df00a44af86f1deffb0b7c12aca944" + "reference": "8edd2c86df5db8383b197b6c5b8e35774ff8e4a8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/di/zipball/ee69270a68df00a44af86f1deffb0b7c12aca944", - "reference": "ee69270a68df00a44af86f1deffb0b7c12aca944", + "url": "https://api.github.com/repos/utopia-php/di/zipball/8edd2c86df5db8383b197b6c5b8e35774ff8e4a8", + "reference": "8edd2c86df5db8383b197b6c5b8e35774ff8e4a8", "shasum": "" }, "require": { @@ -111,10 +111,10 @@ "upf" ], "support": { - "source": "https://github.com/utopia-php/di/tree/dev", + "source": "https://github.com/utopia-php/di/tree/feat-framework-v2", "issues": "https://github.com/utopia-php/di/issues" }, - "time": "2024-06-07T18:31:56+00:00" + "time": "2024-06-07T18:49:13+00:00" }, { "name": "utopia-php/framework", @@ -170,17 +170,17 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/servers.git", - "reference": "e751e03860df4dca60a3e31a32ee62613a3d0280" + "reference": "4565c1c111f6da6b18bc0f00f350377a1e691e48" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/servers/zipball/e751e03860df4dca60a3e31a32ee62613a3d0280", - "reference": "e751e03860df4dca60a3e31a32ee62613a3d0280", + "url": "https://api.github.com/repos/utopia-php/servers/zipball/4565c1c111f6da6b18bc0f00f350377a1e691e48", + "reference": "4565c1c111f6da6b18bc0f00f350377a1e691e48", "shasum": "" }, "require": { "php": ">=8.0", - "utopia-php/di": "dev-dev" + "utopia-php/di": "dev-feat-framework-v2" }, "require-dev": { "laravel/pint": "^0.2.3", @@ -233,7 +233,7 @@ "source": "https://github.com/utopia-php/servers/tree/dev", "issues": "https://github.com/utopia-php/servers/issues" }, - "time": "2024-06-07T18:38:46+00:00" + "time": "2024-06-07T18:49:59+00:00" } ], "packages-dev": [ From 41b76eacae43bb3e46824ffc8e9aa14536771b88 Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Thu, 4 Jul 2024 14:02:23 -0400 Subject: [PATCH 21/26] feat: Adapting Redis adapter to receive active connection --- src/Queue/Connection/Redis.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Queue/Connection/Redis.php b/src/Queue/Connection/Redis.php index 1b3bbf7..8760422 100644 --- a/src/Queue/Connection/Redis.php +++ b/src/Queue/Connection/Redis.php @@ -12,8 +12,13 @@ class Redis implements Connection protected ?string $password; protected ?\Redis $redis = null; - public function __construct(string $host, int $port = 6379, ?string $user = null, ?string $password = null) + public function __construct(mixed $host, int $port = 6379, ?string $user = null, ?string $password = null) { + if(gettype($host) !== 'string') { + $this->redis = $host; + return; + } + $this->host = $host; $this->port = $port; $this->user = $user; From d59c8a3f8ab72abc069c8f0c8f963cdae1f135e6 Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Fri, 19 Jul 2024 13:00:55 -0400 Subject: [PATCH 22/26] chore: lint --- src/Queue/Connection/Redis.php | 2 +- src/Queue/Worker.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Queue/Connection/Redis.php b/src/Queue/Connection/Redis.php index 8760422..c91b521 100644 --- a/src/Queue/Connection/Redis.php +++ b/src/Queue/Connection/Redis.php @@ -14,7 +14,7 @@ class Redis implements Connection public function __construct(mixed $host, int $port = 6379, ?string $user = null, ?string $password = null) { - if(gettype($host) !== 'string') { + if (gettype($host) !== 'string') { $this->redis = $host; return; } diff --git a/src/Queue/Worker.php b/src/Queue/Worker.php index 31e8d42..6072986 100644 --- a/src/Queue/Worker.php +++ b/src/Queue/Worker.php @@ -84,14 +84,14 @@ public function start(): self while (!$this->adapter->connection->ping()) { if ($retryAttempts <= 0) { - Console::error("[Worker] connection is not ready. Exiting..."); - return $this; + Console::error("[Worker] connection is not ready. Exiting..."); + return $this; } $retryAttempts--; Console::warning("[Worker] connection is not ready. Retrying in {$retryDelay} seconds [{$retryAttempts} left] ..."); - + sleep($retryDelay); } From e781d957f9c8496cc71a54cb5f0fd0a240b358b3 Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Fri, 9 Aug 2024 16:58:19 -0400 Subject: [PATCH 23/26] chore: updating versions --- composer.json | 8 +- composer.lock | 257 +++++++++++++++++++++++++------------------------- 2 files changed, 130 insertions(+), 135 deletions(-) diff --git a/composer.json b/composer.json index da9cb9e..f1f7624 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "type": "library", "keywords": ["php","framework", "upf", "utopia", "tasks", "queue"], "license": "MIT", - "minimum-stability": "dev", + "minimum-stability": "RC", "authors": [ { "name": "Torsten Dittmann", @@ -25,9 +25,9 @@ }, "require": { "php": ">=8.0", - "utopia-php/cli": "0.17.*", - "utopia-php/servers": "dev-dev", - "utopia-php/di": "dev-feat-framework-v2" + "utopia-php/cli": "1.0.*", + "utopia-php/servers": "0.1.*", + "utopia-php/di": "0.1.*" }, "require-dev": { "swoole/ide-helper": "4.8.8", diff --git a/composer.lock b/composer.lock index 54bdc39..e8af90a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,31 +4,33 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b68549a5e9847efd3a2dabe9a81c1123", + "content-hash": "4fc1e5656826067a00231cbfd00b18b6", "packages": [ { "name": "utopia-php/cli", - "version": "0.17.0", + "version": "1.0.0-RC1", "source": { "type": "git", "url": "https://github.com/utopia-php/cli.git", - "reference": "0829fd5215afe88f53f3091cedc808da801fd1bb" + "reference": "7664161dcdb9b76a3ece0ae2f36a9aca1e548e80" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/cli/zipball/0829fd5215afe88f53f3091cedc808da801fd1bb", - "reference": "0829fd5215afe88f53f3091cedc808da801fd1bb", + "url": "https://api.github.com/repos/utopia-php/cli/zipball/7664161dcdb9b76a3ece0ae2f36a9aca1e548e80", + "reference": "7664161dcdb9b76a3ece0ae2f36a9aca1e548e80", "shasum": "" }, "require": { "php": ">=7.4", - "utopia-php/framework": "0.34.*" + "utopia-php/di": "0.1.*", + "utopia-php/framework": "1.0.*" }, "require-dev": { "laravel/pint": "1.2.*", + "phpstan/phpstan": "^1.10", "phpunit/phpunit": "^9.3", "squizlabs/php_codesniffer": "^3.6", - "vimeo/psalm": "4.0.1" + "swoole/ide-helper": "4.8.8" }, "type": "library", "autoload": { @@ -51,22 +53,22 @@ ], "support": { "issues": "https://github.com/utopia-php/cli/issues", - "source": "https://github.com/utopia-php/cli/tree/0.17.0" + "source": "https://github.com/utopia-php/cli/tree/1.0.0-RC1" }, - "time": "2024-01-24T11:37:29+00:00" + "time": "2024-08-09T17:35:04+00:00" }, { "name": "utopia-php/di", - "version": "dev-feat-framework-v2", + "version": "0.1.0", "source": { "type": "git", "url": "https://github.com/utopia-php/di.git", - "reference": "8edd2c86df5db8383b197b6c5b8e35774ff8e4a8" + "reference": "22490c95f7ac3898ed1c33f1b1b5dd577305ee31" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/di/zipball/8edd2c86df5db8383b197b6c5b8e35774ff8e4a8", - "reference": "8edd2c86df5db8383b197b6c5b8e35774ff8e4a8", + "url": "https://api.github.com/repos/utopia-php/di/zipball/22490c95f7ac3898ed1c33f1b1b5dd577305ee31", + "reference": "22490c95f7ac3898ed1c33f1b1b5dd577305ee31", "shasum": "" }, "require": { @@ -111,30 +113,32 @@ "upf" ], "support": { - "source": "https://github.com/utopia-php/di/tree/feat-framework-v2", + "source": "https://github.com/utopia-php/di/tree/0.1.0", "issues": "https://github.com/utopia-php/di/issues" }, - "time": "2024-06-07T18:49:13+00:00" + "time": "2024-08-08T14:35:19+00:00" }, { "name": "utopia-php/framework", - "version": "0.34.2", + "version": "1.0.0-RC2", "source": { "type": "git", "url": "https://github.com/utopia-php/http.git", - "reference": "fd126c02b78cc80678c9638f7b335dfb4a841b78" + "reference": "d1e9674dbf33bed03fa53854ec1f2c6e074cf4d7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/http/zipball/fd126c02b78cc80678c9638f7b335dfb4a841b78", - "reference": "fd126c02b78cc80678c9638f7b335dfb4a841b78", + "url": "https://api.github.com/repos/utopia-php/http/zipball/d1e9674dbf33bed03fa53854ec1f2c6e074cf4d7", + "reference": "d1e9674dbf33bed03fa53854ec1f2c6e074cf4d7", "shasum": "" }, "require": { "ext-swoole": "*", - "php": ">=8.0" + "php": ">=8.0", + "utopia-php/servers": "0.1.* " }, "require-dev": { + "ext-xdebug": "*", "laravel/pint": "^1.2", "phpbench/phpbench": "^1.2", "phpstan/phpstan": "^1.10", @@ -144,7 +148,7 @@ "type": "library", "autoload": { "psr-4": { - "Utopia\\Http\\": "src/Http" + "Utopia\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -160,27 +164,27 @@ ], "support": { "issues": "https://github.com/utopia-php/http/issues", - "source": "https://github.com/utopia-php/http/tree/0.34.2" + "source": "https://github.com/utopia-php/http/tree/1.0.0-RC2" }, - "time": "2024-02-20T11:36:56+00:00" + "time": "2024-08-08T14:46:41+00:00" }, { "name": "utopia-php/servers", - "version": "dev-dev", + "version": "0.1.0", "source": { "type": "git", "url": "https://github.com/utopia-php/servers.git", - "reference": "4565c1c111f6da6b18bc0f00f350377a1e691e48" + "reference": "7d9e4f364fb1ab1889fb89ca96eb9946467cb09c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/servers/zipball/4565c1c111f6da6b18bc0f00f350377a1e691e48", - "reference": "4565c1c111f6da6b18bc0f00f350377a1e691e48", + "url": "https://api.github.com/repos/utopia-php/servers/zipball/7d9e4f364fb1ab1889fb89ca96eb9946467cb09c", + "reference": "7d9e4f364fb1ab1889fb89ca96eb9946467cb09c", "shasum": "" }, "require": { "php": ">=8.0", - "utopia-php/di": "dev-feat-framework-v2" + "utopia-php/di": "0.1.*" }, "require-dev": { "laravel/pint": "^0.2.3", @@ -230,41 +234,40 @@ "utopia" ], "support": { - "source": "https://github.com/utopia-php/servers/tree/dev", + "source": "https://github.com/utopia-php/servers/tree/0.1.0", "issues": "https://github.com/utopia-php/servers/issues" }, - "time": "2024-06-07T18:49:59+00:00" + "time": "2024-08-08T14:31:39+00:00" } ], "packages-dev": [ { "name": "doctrine/instantiator", - "version": "2.0.x-dev", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "9955122a490d18ce723cf9014b196c126222c180" + "reference": "c6222283fa3f4ac679f8b9ced9a4e23f163e80d0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/9955122a490d18ce723cf9014b196c126222c180", - "reference": "9955122a490d18ce723cf9014b196c126222c180", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/c6222283fa3f4ac679f8b9ced9a4e23f163e80d0", + "reference": "c6222283fa3f4ac679f8b9ced9a4e23f163e80d0", "shasum": "" }, "require": { "php": "^8.1" }, "require-dev": { - "doctrine/coding-standard": "^12", + "doctrine/coding-standard": "^11", "ext-pdo": "*", "ext-phar": "*", "phpbench/phpbench": "^1.2", "phpstan/phpstan": "^1.9.4", "phpstan/phpstan-phpunit": "^1.3", - "phpunit/phpunit": "^10.5", + "phpunit/phpunit": "^9.5.27", "vimeo/psalm": "^5.4" }, - "default-branch": true, "type": "library", "autoload": { "psr-4": { @@ -290,7 +293,7 @@ ], "support": { "issues": "https://github.com/doctrine/instantiator/issues", - "source": "https://github.com/doctrine/instantiator/tree/2.0.x" + "source": "https://github.com/doctrine/instantiator/tree/2.0.0" }, "funding": [ { @@ -306,7 +309,7 @@ "type": "tidelift" } ], - "time": "2024-05-05T15:09:38+00:00" + "time": "2022-12-30T00:23:10+00:00" }, { "name": "laravel/pint", @@ -376,16 +379,16 @@ }, { "name": "myclabs/deep-copy", - "version": "1.x-dev", + "version": "1.12.0", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "2f5294676c802a62b0549f6bc8983f14294ce369" + "reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/2f5294676c802a62b0549f6bc8983f14294ce369", - "reference": "2f5294676c802a62b0549f6bc8983f14294ce369", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c", + "reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c", "shasum": "" }, "require": { @@ -401,7 +404,6 @@ "phpspec/prophecy": "^1.10", "phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13" }, - "default-branch": true, "type": "library", "autoload": { "files": [ @@ -425,7 +427,7 @@ ], "support": { "issues": "https://github.com/myclabs/DeepCopy/issues", - "source": "https://github.com/myclabs/DeepCopy/tree/1.x" + "source": "https://github.com/myclabs/DeepCopy/tree/1.12.0" }, "funding": [ { @@ -433,20 +435,20 @@ "type": "tidelift" } ], - "time": "2024-02-10T11:10:03+00:00" + "time": "2024-06-12T14:39:25+00:00" }, { "name": "nikic/php-parser", - "version": "dev-master", + "version": "v5.1.0", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "daaadc3bae458908aa477b90a8932e7da9253f22" + "reference": "683130c2ff8c2739f4822ff7ac5c873ec529abd1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/daaadc3bae458908aa477b90a8932e7da9253f22", - "reference": "daaadc3bae458908aa477b90a8932e7da9253f22", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/683130c2ff8c2739f4822ff7ac5c873ec529abd1", + "reference": "683130c2ff8c2739f4822ff7ac5c873ec529abd1", "shasum": "" }, "require": { @@ -459,7 +461,6 @@ "ircmaxell/php-yacc": "^0.0.7", "phpunit/phpunit": "^9.0" }, - "default-branch": true, "bin": [ "bin/php-parse" ], @@ -490,13 +491,13 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/master" + "source": "https://github.com/nikic/PHP-Parser/tree/v5.1.0" }, - "time": "2024-06-03T06:24:19+00:00" + "time": "2024-07-01T20:03:41+00:00" }, { "name": "phar-io/manifest", - "version": "dev-master", + "version": "2.0.4", "source": { "type": "git", "url": "https://github.com/phar-io/manifest.git", @@ -516,7 +517,6 @@ "phar-io/version": "^3.0.1", "php": "^7.2 || ^8.0" }, - "default-branch": true, "type": "library", "extra": { "branch-alias": { @@ -615,16 +615,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.11.x-dev", + "version": "1.11.10", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "80b404fb7a47b1416ed37b9fe33793ad32e714a6" + "reference": "640410b32995914bde3eed26fa89552f9c2c082f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/80b404fb7a47b1416ed37b9fe33793ad32e714a6", - "reference": "80b404fb7a47b1416ed37b9fe33793ad32e714a6", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/640410b32995914bde3eed26fa89552f9c2c082f", + "reference": "640410b32995914bde3eed26fa89552f9c2c082f", "shasum": "" }, "require": { @@ -633,7 +633,6 @@ "conflict": { "phpstan/phpstan-shim": "*" }, - "default-branch": true, "bin": [ "phpstan", "phpstan.phar" @@ -670,20 +669,20 @@ "type": "github" } ], - "time": "2024-06-07T10:21:58+00:00" + "time": "2024-08-08T09:02:50+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "9.2.x-dev", + "version": "9.2.31", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "3352293d9e91513d5508c415835014881b420218" + "reference": "48c34b5d8d983006bd2adc2d0de92963b9155965" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/3352293d9e91513d5508c415835014881b420218", - "reference": "3352293d9e91513d5508c415835014881b420218", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/48c34b5d8d983006bd2adc2d0de92963b9155965", + "reference": "48c34b5d8d983006bd2adc2d0de92963b9155965", "shasum": "" }, "require": { @@ -740,7 +739,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.31" }, "funding": [ { @@ -748,20 +747,20 @@ "type": "github" } ], - "time": "2024-03-22T05:16:32+00:00" + "time": "2024-03-02T06:37:42+00:00" }, { "name": "phpunit/php-file-iterator", - "version": "3.0.x-dev", + "version": "3.0.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "38b24367e1b340aa78b96d7cab042942d917bb84" + "reference": "cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/38b24367e1b340aa78b96d7cab042942d917bb84", - "reference": "38b24367e1b340aa78b96d7cab042942d917bb84", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf", + "reference": "cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf", "shasum": "" }, "require": { @@ -800,7 +799,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", - "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/3.0" + "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/3.0.6" }, "funding": [ { @@ -808,7 +807,7 @@ "type": "github" } ], - "time": "2022-02-11T16:23:04+00:00" + "time": "2021-12-02T12:48:52+00:00" }, { "name": "phpunit/php-invoker", @@ -993,45 +992,45 @@ }, { "name": "phpunit/phpunit", - "version": "9.6.x-dev", + "version": "9.6.20", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "feb499300d9595ea4587e7448ea990263bc47c10" + "reference": "49d7820565836236411f5dc002d16dd689cde42f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/feb499300d9595ea4587e7448ea990263bc47c10", - "reference": "feb499300d9595ea4587e7448ea990263bc47c10", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/49d7820565836236411f5dc002d16dd689cde42f", + "reference": "49d7820565836236411f5dc002d16dd689cde42f", "shasum": "" }, "require": { - "doctrine/instantiator": "^1.3.1 || ^2", + "doctrine/instantiator": "^1.5.0 || ^2", "ext-dom": "*", "ext-json": "*", "ext-libxml": "*", "ext-mbstring": "*", "ext-xml": "*", "ext-xmlwriter": "*", - "myclabs/deep-copy": "^1.10.1", - "phar-io/manifest": "^2.0.3", - "phar-io/version": "^3.0.2", + "myclabs/deep-copy": "^1.12.0", + "phar-io/manifest": "^2.0.4", + "phar-io/version": "^3.2.1", "php": ">=7.3", - "phpunit/php-code-coverage": "^9.2.28", - "phpunit/php-file-iterator": "^3.0.5", + "phpunit/php-code-coverage": "^9.2.31", + "phpunit/php-file-iterator": "^3.0.6", "phpunit/php-invoker": "^3.1.1", - "phpunit/php-text-template": "^2.0.3", - "phpunit/php-timer": "^5.0.2", - "sebastian/cli-parser": "^1.0.1", - "sebastian/code-unit": "^1.0.6", + "phpunit/php-text-template": "^2.0.4", + "phpunit/php-timer": "^5.0.3", + "sebastian/cli-parser": "^1.0.2", + "sebastian/code-unit": "^1.0.8", "sebastian/comparator": "^4.0.8", - "sebastian/diff": "^4.0.3", - "sebastian/environment": "^5.1.3", - "sebastian/exporter": "^4.0.5", - "sebastian/global-state": "^5.0.1", - "sebastian/object-enumerator": "^4.0.3", - "sebastian/resource-operations": "^3.0.3", - "sebastian/type": "^3.2", + "sebastian/diff": "^4.0.6", + "sebastian/environment": "^5.1.5", + "sebastian/exporter": "^4.0.6", + "sebastian/global-state": "^5.0.7", + "sebastian/object-enumerator": "^4.0.4", + "sebastian/resource-operations": "^3.0.4", + "sebastian/type": "^3.2.1", "sebastian/version": "^3.0.2" }, "suggest": { @@ -1076,7 +1075,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.20" }, "funding": [ { @@ -1092,11 +1091,11 @@ "type": "tidelift" } ], - "time": "2024-06-07T04:40:16+00:00" + "time": "2024-07-10T11:45:39+00:00" }, { "name": "sebastian/cli-parser", - "version": "1.0.x-dev", + "version": "1.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/cli-parser.git", @@ -1263,16 +1262,16 @@ }, { "name": "sebastian/comparator", - "version": "4.0.x-dev", + "version": "4.0.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "b247957a1c8dc81a671770f74b479c0a78a818f1" + "reference": "fa0f136dd2334583309d32b62544682ee972b51a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/b247957a1c8dc81a671770f74b479c0a78a818f1", - "reference": "b247957a1c8dc81a671770f74b479c0a78a818f1", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/fa0f136dd2334583309d32b62544682ee972b51a", + "reference": "fa0f136dd2334583309d32b62544682ee972b51a", "shasum": "" }, "require": { @@ -1325,7 +1324,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/comparator/issues", - "source": "https://github.com/sebastianbergmann/comparator/tree/4.0" + "source": "https://github.com/sebastianbergmann/comparator/tree/4.0.8" }, "funding": [ { @@ -1333,11 +1332,11 @@ "type": "github" } ], - "time": "2022-09-14T12:46:14+00:00" + "time": "2022-09-14T12:41:17+00:00" }, { "name": "sebastian/complexity", - "version": "2.0.x-dev", + "version": "2.0.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/complexity.git", @@ -1394,7 +1393,7 @@ }, { "name": "sebastian/diff", - "version": "4.0.x-dev", + "version": "4.0.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", @@ -1460,7 +1459,7 @@ }, { "name": "sebastian/environment", - "version": "5.1.x-dev", + "version": "5.1.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", @@ -1511,7 +1510,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/environment/issues", - "source": "https://github.com/sebastianbergmann/environment/tree/5.1" + "source": "https://github.com/sebastianbergmann/environment/tree/5.1.5" }, "funding": [ { @@ -1523,7 +1522,7 @@ }, { "name": "sebastian/exporter", - "version": "4.0.x-dev", + "version": "4.0.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", @@ -1600,7 +1599,7 @@ }, { "name": "sebastian/global-state", - "version": "5.0.x-dev", + "version": "5.0.7", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", @@ -1664,7 +1663,7 @@ }, { "name": "sebastian/lines-of-code", - "version": "1.0.x-dev", + "version": "1.0.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/lines-of-code.git", @@ -1833,7 +1832,7 @@ }, { "name": "sebastian/recursion-context", - "version": "4.0.x-dev", + "version": "4.0.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/recursion-context.git", @@ -1896,16 +1895,16 @@ }, { "name": "sebastian/resource-operations", - "version": "dev-main", + "version": "3.0.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/resource-operations.git", - "reference": "ff553e7482dcee39fa4acc2b175d6ddeb0f7bc25" + "reference": "05d5692a7993ecccd56a03e40cd7e5b09b1d404e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/ff553e7482dcee39fa4acc2b175d6ddeb0f7bc25", - "reference": "ff553e7482dcee39fa4acc2b175d6ddeb0f7bc25", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/05d5692a7993ecccd56a03e40cd7e5b09b1d404e", + "reference": "05d5692a7993ecccd56a03e40cd7e5b09b1d404e", "shasum": "" }, "require": { @@ -1914,7 +1913,6 @@ "require-dev": { "phpunit/phpunit": "^9.0" }, - "default-branch": true, "type": "library", "extra": { "branch-alias": { @@ -1939,7 +1937,7 @@ "description": "Provides a list of PHP built-in functions that operate on resources", "homepage": "https://www.github.com/sebastianbergmann/resource-operations", "support": { - "source": "https://github.com/sebastianbergmann/resource-operations/tree/main" + "source": "https://github.com/sebastianbergmann/resource-operations/tree/3.0.4" }, "funding": [ { @@ -1947,11 +1945,11 @@ "type": "github" } ], - "time": "2024-03-14T18:47:08+00:00" + "time": "2024-03-14T16:00:52+00:00" }, { "name": "sebastian/type", - "version": "3.2.x-dev", + "version": "3.2.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/type.git", @@ -1995,7 +1993,7 @@ "homepage": "https://github.com/sebastianbergmann/type", "support": { "issues": "https://github.com/sebastianbergmann/type/issues", - "source": "https://github.com/sebastianbergmann/type/tree/3.2" + "source": "https://github.com/sebastianbergmann/type/tree/3.2.1" }, "funding": [ { @@ -2007,7 +2005,7 @@ }, { "name": "sebastian/version", - "version": "3.0.x-dev", + "version": "3.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/version.git", @@ -2152,16 +2150,16 @@ }, { "name": "workerman/workerman", - "version": "4.1.x-dev", + "version": "v4.1.16", "source": { "type": "git", "url": "https://github.com/walkor/workerman.git", - "reference": "4b35b7ea5785121059613a9943b3509a79cbb077" + "reference": "405d904d33026e19497dffc3d085bbc16e66534e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/walkor/workerman/zipball/4b35b7ea5785121059613a9943b3509a79cbb077", - "reference": "4b35b7ea5785121059613a9943b3509a79cbb077", + "url": "https://api.github.com/repos/walkor/workerman/zipball/405d904d33026e19497dffc3d085bbc16e66534e", + "reference": "405d904d33026e19497dffc3d085bbc16e66534e", "shasum": "" }, "require": { @@ -2211,15 +2209,12 @@ "type": "patreon" } ], - "time": "2024-06-04T14:22:00+00:00" + "time": "2024-07-04T08:26:39+00:00" } ], "aliases": [], - "minimum-stability": "dev", - "stability-flags": { - "utopia-php/servers": 20, - "utopia-php/di": 20 - }, + "minimum-stability": "RC", + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { From ed85fd26200f07d9b93d18d2fa7f5bbef2984902 Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Wed, 4 Sep 2024 14:19:23 -0400 Subject: [PATCH 24/26] chore: updating versions --- composer.json | 12 +------ composer.lock | 89 +++++++++++++++++---------------------------------- 2 files changed, 30 insertions(+), 71 deletions(-) diff --git a/composer.json b/composer.json index f1f7624..4dd32ec 100644 --- a/composer.json +++ b/composer.json @@ -40,15 +40,5 @@ "ext-redis": "Needed to support Redis connections", "ext-swoole": "Needed to support Swoole.", "workerman/workerman": "Needed to support Workerman." - }, - "repositories": [ - { - "type": "vcs", - "url": "https://github.com/utopia-php/servers" - }, - { - "type": "vcs", - "url": "https://github.com/utopia-php/di" - } - ] + } } diff --git a/composer.lock b/composer.lock index e8af90a..793e66e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "4fc1e5656826067a00231cbfd00b18b6", + "content-hash": "7328e7b0bf776d939042e16843500afd", "packages": [ { "name": "utopia-php/cli", @@ -88,20 +88,7 @@ "Tests\\E2E\\": "tests/e2e" } }, - "scripts": { - "lint": [ - "vendor/bin/pint --test" - ], - "format": [ - "vendor/bin/pint" - ], - "check": [ - "vendor/bin/phpstan analyse -c phpstan.neon" - ], - "test": [ - "vendor/bin/phpunit --configuration phpunit.xml" - ] - }, + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -113,8 +100,8 @@ "upf" ], "support": { - "source": "https://github.com/utopia-php/di/tree/0.1.0", - "issues": "https://github.com/utopia-php/di/issues" + "issues": "https://github.com/utopia-php/di/issues", + "source": "https://github.com/utopia-php/di/tree/0.1.0" }, "time": "2024-08-08T14:35:19+00:00" }, @@ -197,25 +184,7 @@ "Utopia\\Servers\\": "src/Servers" } }, - "autoload-dev": { - "psr-4": { - "Tests\\E2E\\": "tests/Servers/Unit" - } - }, - "scripts": { - "test": [ - "phpunit" - ], - "analyse": [ - "vendor/bin/phpstan analyse" - ], - "format": [ - "vendor/bin/pint" - ], - "lint": [ - "vendor/bin/pint --test" - ] - }, + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -234,8 +203,8 @@ "utopia" ], "support": { - "source": "https://github.com/utopia-php/servers/tree/0.1.0", - "issues": "https://github.com/utopia-php/servers/issues" + "issues": "https://github.com/utopia-php/servers/issues", + "source": "https://github.com/utopia-php/servers/tree/0.1.0" }, "time": "2024-08-08T14:31:39+00:00" } @@ -615,16 +584,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.11.10", + "version": "1.12.1", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "640410b32995914bde3eed26fa89552f9c2c082f" + "reference": "d8ed7fffa66de1db0d2972267d8ed1d8fa0fe5a2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/640410b32995914bde3eed26fa89552f9c2c082f", - "reference": "640410b32995914bde3eed26fa89552f9c2c082f", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/d8ed7fffa66de1db0d2972267d8ed1d8fa0fe5a2", + "reference": "d8ed7fffa66de1db0d2972267d8ed1d8fa0fe5a2", "shasum": "" }, "require": { @@ -669,39 +638,39 @@ "type": "github" } ], - "time": "2024-08-08T09:02:50+00:00" + "time": "2024-09-03T19:55:22+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "9.2.31", + "version": "9.2.32", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "48c34b5d8d983006bd2adc2d0de92963b9155965" + "reference": "85402a822d1ecf1db1096959413d35e1c37cf1a5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/48c34b5d8d983006bd2adc2d0de92963b9155965", - "reference": "48c34b5d8d983006bd2adc2d0de92963b9155965", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/85402a822d1ecf1db1096959413d35e1c37cf1a5", + "reference": "85402a822d1ecf1db1096959413d35e1c37cf1a5", "shasum": "" }, "require": { "ext-dom": "*", "ext-libxml": "*", "ext-xmlwriter": "*", - "nikic/php-parser": "^4.18 || ^5.0", + "nikic/php-parser": "^4.19.1 || ^5.1.0", "php": ">=7.3", - "phpunit/php-file-iterator": "^3.0.3", - "phpunit/php-text-template": "^2.0.2", - "sebastian/code-unit-reverse-lookup": "^2.0.2", - "sebastian/complexity": "^2.0", - "sebastian/environment": "^5.1.2", - "sebastian/lines-of-code": "^1.0.3", - "sebastian/version": "^3.0.1", - "theseer/tokenizer": "^1.2.0" + "phpunit/php-file-iterator": "^3.0.6", + "phpunit/php-text-template": "^2.0.4", + "sebastian/code-unit-reverse-lookup": "^2.0.3", + "sebastian/complexity": "^2.0.3", + "sebastian/environment": "^5.1.5", + "sebastian/lines-of-code": "^1.0.4", + "sebastian/version": "^3.0.2", + "theseer/tokenizer": "^1.2.3" }, "require-dev": { - "phpunit/phpunit": "^9.3" + "phpunit/phpunit": "^9.6" }, "suggest": { "ext-pcov": "PHP extension that provides line coverage", @@ -710,7 +679,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "9.2-dev" + "dev-main": "9.2.x-dev" } }, "autoload": { @@ -739,7 +708,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.31" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.32" }, "funding": [ { @@ -747,7 +716,7 @@ "type": "github" } ], - "time": "2024-03-02T06:37:42+00:00" + "time": "2024-08-22T04:23:01+00:00" }, { "name": "phpunit/php-file-iterator", From e69974e774a24487479134a4100497cd3c214a4f Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Thu, 5 Sep 2024 12:24:34 -0400 Subject: [PATCH 25/26] chore: updating versions --- composer.json | 4 ++-- composer.lock | 40 ++++++++++++++++++++-------------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/composer.json b/composer.json index 4dd32ec..95e3a3a 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "type": "library", "keywords": ["php","framework", "upf", "utopia", "tasks", "queue"], "license": "MIT", - "minimum-stability": "RC", + "minimum-stability": "stable", "authors": [ { "name": "Torsten Dittmann", @@ -25,7 +25,7 @@ }, "require": { "php": ">=8.0", - "utopia-php/cli": "1.0.*", + "utopia-php/cli": "0.19.*", "utopia-php/servers": "0.1.*", "utopia-php/di": "0.1.*" }, diff --git a/composer.lock b/composer.lock index 793e66e..4a34a36 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7328e7b0bf776d939042e16843500afd", + "content-hash": "c21f21bc8417c85ea2d4b3a5d02818da", "packages": [ { "name": "utopia-php/cli", - "version": "1.0.0-RC1", + "version": "0.19.0", "source": { "type": "git", "url": "https://github.com/utopia-php/cli.git", - "reference": "7664161dcdb9b76a3ece0ae2f36a9aca1e548e80" + "reference": "f8af1d6087f498bc1f0191750a118d357ded9948" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/cli/zipball/7664161dcdb9b76a3ece0ae2f36a9aca1e548e80", - "reference": "7664161dcdb9b76a3ece0ae2f36a9aca1e548e80", + "url": "https://api.github.com/repos/utopia-php/cli/zipball/f8af1d6087f498bc1f0191750a118d357ded9948", + "reference": "f8af1d6087f498bc1f0191750a118d357ded9948", "shasum": "" }, "require": { @@ -53,9 +53,9 @@ ], "support": { "issues": "https://github.com/utopia-php/cli/issues", - "source": "https://github.com/utopia-php/cli/tree/1.0.0-RC1" + "source": "https://github.com/utopia-php/cli/tree/0.19.0" }, - "time": "2024-08-09T17:35:04+00:00" + "time": "2024-09-05T15:46:56+00:00" }, { "name": "utopia-php/di", @@ -107,22 +107,22 @@ }, { "name": "utopia-php/framework", - "version": "1.0.0-RC2", + "version": "1.0.0", "source": { "type": "git", "url": "https://github.com/utopia-php/http.git", - "reference": "d1e9674dbf33bed03fa53854ec1f2c6e074cf4d7" + "reference": "cc880ec41f7f163d4f9956fec26cc6be51b412cf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/http/zipball/d1e9674dbf33bed03fa53854ec1f2c6e074cf4d7", - "reference": "d1e9674dbf33bed03fa53854ec1f2c6e074cf4d7", + "url": "https://api.github.com/repos/utopia-php/http/zipball/cc880ec41f7f163d4f9956fec26cc6be51b412cf", + "reference": "cc880ec41f7f163d4f9956fec26cc6be51b412cf", "shasum": "" }, "require": { "ext-swoole": "*", "php": ">=8.0", - "utopia-php/servers": "0.1.* " + "utopia-php/servers": "0.1.*" }, "require-dev": { "ext-xdebug": "*", @@ -151,9 +151,9 @@ ], "support": { "issues": "https://github.com/utopia-php/http/issues", - "source": "https://github.com/utopia-php/http/tree/1.0.0-RC2" + "source": "https://github.com/utopia-php/http/tree/1.0.0" }, - "time": "2024-08-08T14:46:41+00:00" + "time": "2024-09-05T15:38:08+00:00" }, { "name": "utopia-php/servers", @@ -584,16 +584,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.12.1", + "version": "1.12.2", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "d8ed7fffa66de1db0d2972267d8ed1d8fa0fe5a2" + "reference": "0ca1c7bb55fca8fe6448f16fff0f311ccec960a1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/d8ed7fffa66de1db0d2972267d8ed1d8fa0fe5a2", - "reference": "d8ed7fffa66de1db0d2972267d8ed1d8fa0fe5a2", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/0ca1c7bb55fca8fe6448f16fff0f311ccec960a1", + "reference": "0ca1c7bb55fca8fe6448f16fff0f311ccec960a1", "shasum": "" }, "require": { @@ -638,7 +638,7 @@ "type": "github" } ], - "time": "2024-09-03T19:55:22+00:00" + "time": "2024-09-05T16:09:28+00:00" }, { "name": "phpunit/php-code-coverage", @@ -2182,7 +2182,7 @@ } ], "aliases": [], - "minimum-stability": "RC", + "minimum-stability": "stable", "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, From ac7c8d330f2909ca46f544ee68642ce851ca7dcd Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Thu, 5 Sep 2024 12:30:58 -0400 Subject: [PATCH 26/26] fix: removing leftover --- src/Queue/Adapter/Swoole/Server.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Queue/Adapter/Swoole/Server.php b/src/Queue/Adapter/Swoole/Server.php index d6281c9..5d83999 100644 --- a/src/Queue/Adapter/Swoole/Server.php +++ b/src/Queue/Adapter/Swoole/Server.php @@ -54,9 +54,6 @@ public function onWorkerStop(callable $callback): self public function onJob(callable $callback): self { call_user_func($callback); - // go(function () use ($callback) { - // call_user_func($callback); - // }); return $this; }