-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ingenerator/initial-extract
Initial extraction from donor project
- Loading branch information
Showing
49 changed files
with
4,810 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
name: Run tests | ||
on: | ||
push: | ||
branches: | ||
# Only mainline branches, features etc are covered on the pull_request trigger | ||
- '*.x' | ||
pull_request: | ||
|
||
jobs: | ||
run-tests: | ||
runs-on: ubuntu-latest | ||
name: Run tests | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
php_version: | ||
- '8.2' | ||
dependencies: | ||
- 'default' | ||
include: | ||
- php_version: '8.2' | ||
dependencies: 'lowest' | ||
steps: | ||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php_version }} | ||
tools: composer:v2 | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Get Composer Cache Directory | ||
id: composer-cache | ||
run: | | ||
echo "::set-output name=dir::$(composer config cache-files-dir)" | ||
- uses: actions/cache@v2 | ||
with: | ||
path: ${{ steps.composer-cache.outputs.dir }} | ||
key: ${{ runner.os }}-composer-${{ matrix.dependencies }}-${{ hashFiles('**/composer.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-composer-${{ matrix.dependencies }} | ||
- name: Install composer dependencies | ||
env: | ||
DEPENDENCIES: ${{ matrix.dependencies }} | ||
run: | | ||
if [ $DEPENDENCIES == 'lowest' ] | ||
then | ||
composer update --prefer-lowest --no-interaction --no-suggest --no-progress | ||
else | ||
composer install --no-interaction --no-suggest --no-progress | ||
fi | ||
- name: Run unit tests | ||
run: | | ||
vendor/bin/phpunit --testsuite=unit --verbose | ||
- name: Start MySQL server | ||
run: | | ||
sudo systemctl start mysql.service | ||
- name: Run integration tests | ||
run: | | ||
vendor/bin/phpunit --testsuite=integration --verbose |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/.idea | ||
/vendor/ | ||
/composer.lock | ||
.phpunit.result.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## Unreleased | ||
|
||
## v1.0.0 (2024-02-06) | ||
|
||
* Initial version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Copyright (c) 2024, inGenerator Ltd | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the | ||
following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the | ||
following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following | ||
disclaimer in the documentation and/or other materials provided with the distribution. | ||
|
||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products | ||
derived from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
use Ingenerator\ScheduledTaskRunner\CronjobRunnerFactory; | ||
|
||
|
||
ini_set('display_errors', 1); | ||
error_reporting(E_ALL); | ||
set_error_handler( | ||
function ($code, $msg, $file, $line) { | ||
throw new ErrorException($msg, 0, $code, $file, $line); | ||
} | ||
); | ||
|
||
try { | ||
$factory = require_once($argv[1]); | ||
if ( ! $factory instanceof CronjobRunnerFactory) { | ||
throw new RuntimeException('You must provide a script which returns a CronjobRunnerFactory as the first arg'); | ||
} | ||
|
||
$controller = $factory->getController(); | ||
|
||
pcntl_async_signals(TRUE); | ||
pcntl_signal(SIGTERM, fn() => $controller->signalTermination()); | ||
|
||
$controller->execute(); | ||
|
||
} catch (Throwable $e) { | ||
fwrite( | ||
STDERR, | ||
sprintf( | ||
"Fatal error executing %s- [%s] %s (%s:%s)\n", | ||
__FILE__, | ||
get_class($e), | ||
$e->getMessage(), | ||
$e->getFile(), | ||
$e->getLine() | ||
) | ||
); | ||
exit(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ | ||
"name": "ingenerator/scheduled-task-runner", | ||
"homepage": "https://github.com/ingenerator/scheduled-task-runner", | ||
"type": "library", | ||
"license": "BSD-3-Clause", | ||
"authors": [ | ||
{ | ||
"name": "Andrew Coulton", | ||
"email": "andrew@ingenerator.com" | ||
}, | ||
{ | ||
"name": "Craig Gosman", | ||
"email": "craig@ingenerator.com" | ||
} | ||
], | ||
"minimum-stability": "stable", | ||
"bin": [ | ||
"bin/cronjob-runner" | ||
], | ||
"config": { | ||
"preferred-install": "dist", | ||
"sort-packages": true | ||
}, | ||
"support": { | ||
"source": "https://github.com/ingenerator/scheduled-task-runner", | ||
"issues": "https://github.com/ingenerator/scheduled-task-runner/issues" | ||
}, | ||
"require": { | ||
"php": "~8.2.0", | ||
"ext-pcntl": "*", | ||
"ext-pdo": "*", | ||
"dragonmantank/cron-expression": "^3.3.2", | ||
"ingenerator/php-utils": "^2.0", | ||
"psr/log": "^1.0 || ^2.0 || ^3.0", | ||
"symfony/lock": "^5.4 || ^6.0 || ^7.0", | ||
"symfony/process": "^5.4 || ^6.0 || ^7.0" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^9.5.5" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Ingenerator\\ScheduledTaskRunner\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"test\\integration\\Ingenerator\\ScheduledTaskRunner\\": "test/integration", | ||
"test\\mock\\Ingenerator\\ScheduledTaskRunner\\": "test/mock", | ||
"test\\unit\\Ingenerator\\ScheduledTaskRunner\\": "test/unit" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0"?> | ||
<!-- Config file for PHPUnit automated tests --> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
beStrictAboutChangesToGlobalState="true" | ||
bootstrap="test/phpunit-bootstrap.php" | ||
cacheResultFile="test/.phpunit.result.cache" | ||
colors="true" | ||
convertDeprecationsToExceptions="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"> | ||
<coverage> | ||
<include> | ||
<directory suffix=".php">src</directory> | ||
</include> | ||
</coverage> | ||
<testsuites> | ||
<testsuite name="unit"> | ||
<directory>test/unit</directory> | ||
</testsuite> | ||
<testsuite name="integration"> | ||
<directory>test/integration</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Ingenerator\ScheduledTaskRunner; | ||
|
||
class CronConfigLoader | ||
{ | ||
/** | ||
* @var CronTaskGroupDefinition[] | ||
*/ | ||
private array $definitions; | ||
|
||
public function __construct(array $config) | ||
{ | ||
$this->definitions = []; | ||
foreach ($config as $group_name => $values) { | ||
$values['group_name'] = $group_name; | ||
$this->definitions[] = CronTaskGroupDefinition::fromArray($values); | ||
} | ||
} | ||
|
||
/** | ||
* @return CronTaskGroupDefinition[] | ||
*/ | ||
public function getAllTaskDefinitions(): array | ||
{ | ||
return $this->definitions; | ||
} | ||
|
||
/** | ||
* @return CronTaskGroupDefinition[] | ||
*/ | ||
public function getActiveTaskDefinitions(): array | ||
{ | ||
return array_values(array_filter($this->definitions, fn (CronTaskGroupDefinition $d) => $d->isEnabled())); | ||
} | ||
} |
Oops, something went wrong.