Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/patchlevel/worker
Gives the opportunity to build a stable worker that terminates properly when limits are exceeded.
https://github.com/patchlevel/worker
Last synced: about 1 month ago
JSON representation
Gives the opportunity to build a stable worker that terminates properly when limits are exceeded.
- Host: GitHub
- URL: https://github.com/patchlevel/worker
- Owner: patchlevel
- License: mit
- Created: 2023-02-28T11:51:35.000Z (almost 2 years ago)
- Default Branch: 1.3.x
- Last Pushed: 2024-05-29T03:30:53.000Z (7 months ago)
- Last Synced: 2024-05-29T16:40:13.007Z (7 months ago)
- Language: PHP
- Homepage:
- Size: 267 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=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)
[![Type Coverage](https://shepherd.dev/github/patchlevel/hydrator/coverage.svg)](https://shepherd.dev/github/patchlevel/hydrator)
[![Latest Stable Version](https://poser.pugx.org/patchlevel/hydrator/v)](//packagist.org/packages/patchlevel/hydrator)
[![License](https://poser.pugx.org/patchlevel/hydrator/license)](//packagist.org/packages/patchlevel/hydrator)# Worker
Gives the opportunity to build a stable worker that terminates properly when limits are exceeded.
It has now been outsourced by the [event-sourcing](https://github.com/patchlevel/event-sourcing) library as a separate library.## Installation
```bash
composer require patchlevel/worker
```## Example
```php
addOption(
'run-limit',
null,
InputOption::VALUE_OPTIONAL,
'The maximum number of runs this command should execute',
1
)
->addOption(
'memory-limit',
null,
InputOption::VALUE_REQUIRED,
'How much memory consumption should the worker be terminated (500MB, 1GB, etc.)'
)
->addOption(
'time-limit',
null,
InputOption::VALUE_REQUIRED,
'What is the maximum time the worker can run in seconds'
)
->addOption(
'sleep',
null,
InputOption::VALUE_REQUIRED,
'How much time should elapse before the next job is executed in milliseconds',
1000
);
}protected function execute(InputInterface $input, OutputInterface $output): int
{
$logger = new ConsoleLogger($output);
$worker = DefaultWorker::create(
function ($stop): void {
// do something
if (/* some condition */) {
$stop();
}
},
[
'runLimit' => $input->getOption('run-limit'),
'memoryLimit' => $input->getOption('memory-limit'),
'timeLimit' => $input->getOption('time-limit'),
],
$logger
);$worker->run($input->getOption('sleep') ?: null);
return 0;
}
}
```