{"id":19737201,"url":"https://github.com/patchlevel/worker","last_synced_at":"2025-06-10T19:40:40.565Z","repository":{"id":180350012,"uuid":"607644319","full_name":"patchlevel/worker","owner":"patchlevel","description":"Gives the opportunity to build a stable worker that terminates properly when limits are exceeded.","archived":false,"fork":false,"pushed_at":"2025-04-15T17:06:44.000Z","size":541,"stargazers_count":2,"open_issues_count":3,"forks_count":0,"subscribers_count":3,"default_branch":"1.5.x","last_synced_at":"2025-05-22T02:49:46.136Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/patchlevel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-02-28T11:51:35.000Z","updated_at":"2025-04-15T17:06:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"46a10bcb-835e-478d-b449-df379759b9ed","html_url":"https://github.com/patchlevel/worker","commit_stats":null,"previous_names":["patchlevel/worker"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patchlevel%2Fworker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patchlevel%2Fworker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patchlevel%2Fworker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patchlevel%2Fworker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/patchlevel","download_url":"https://codeload.github.com/patchlevel/worker/tar.gz/refs/heads/1.5.x","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patchlevel%2Fworker/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259137728,"owners_count":22810767,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-12T01:09:58.344Z","updated_at":"2025-06-10T19:40:40.540Z","avatar_url":"https://github.com/patchlevel.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Mutation testing badge](https://img.shields.io/endpoint?style=flat\u0026url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fpatchlevel%2Fhydrator%2F2.0.x)](https://dashboard.stryker-mutator.io/reports/github.com/patchlevel/hydrator/2.0.x)\n[![Type Coverage](https://shepherd.dev/github/patchlevel/hydrator/coverage.svg)](https://shepherd.dev/github/patchlevel/hydrator)\n[![Latest Stable Version](https://poser.pugx.org/patchlevel/hydrator/v)](//packagist.org/packages/patchlevel/hydrator)\n[![License](https://poser.pugx.org/patchlevel/hydrator/license)](//packagist.org/packages/patchlevel/hydrator)\n\n# Worker\n\nGives the opportunity to build a stable worker that terminates properly when limits are exceeded.\nIt has now been outsourced by the [event-sourcing](https://github.com/patchlevel/event-sourcing) library as a separate library.\n\n## Installation\n\n```bash\ncomposer require patchlevel/worker\n```\n\n## Example\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nnamespace App\\Console\\Command;\n\nuse Symfony\\Component\\Console\\Attribute\\AsCommand;\nuse Symfony\\Component\\Console\\Command\\Command;\nuse Symfony\\Component\\Console\\Input\\InputInterface;\nuse Symfony\\Component\\Console\\Input\\InputOption;\nuse Symfony\\Component\\Console\\Logger\\ConsoleLogger;\nuse Symfony\\Component\\Console\\Output\\OutputInterface;\n\n#[AsCommand(\n    'app:worker',\n    'do stuff'\n)]\nfinal class WorkerCommand extends Command\n{\n    protected function configure(): void\n    {\n        $this\n            -\u003eaddOption(\n                'run-limit',\n                null,\n                InputOption::VALUE_OPTIONAL,\n                'The maximum number of runs this command should execute',\n                1\n            )\n            -\u003eaddOption(\n                'memory-limit',\n                null,\n                InputOption::VALUE_REQUIRED,\n                'How much memory consumption should the worker be terminated (500MB, 1GB, etc.)'\n            )\n            -\u003eaddOption(\n                'time-limit',\n                null,\n                InputOption::VALUE_REQUIRED,\n                'What is the maximum time the worker can run in seconds'\n            )\n            -\u003eaddOption(\n                'sleep',\n                null,\n                InputOption::VALUE_REQUIRED,\n                'How much time should elapse before the next job is executed in milliseconds',\n                1000\n            );\n    }\n\n    protected function execute(InputInterface $input, OutputInterface $output): int\n    {\n        $logger = new ConsoleLogger($output);\n        \n        $worker = DefaultWorker::create(\n            function ($stop): void {\n                // do something\n                \n                if (/* some condition */) {\n                    $stop();\n                }\n            },\n            [\n                'runLimit' =\u003e $input-\u003egetOption('run-limit'),\n                'memoryLimit' =\u003e $input-\u003egetOption('memory-limit'),\n                'timeLimit' =\u003e $input-\u003egetOption('time-limit'),\n            ],\n            $logger\n        );\n\n        $worker-\u003erun($input-\u003egetOption('sleep') ?: null);\n\n        return 0;\n    }\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatchlevel%2Fworker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpatchlevel%2Fworker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatchlevel%2Fworker/lists"}