-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add Windows support * Allow Symfony 7 and CS * Added CI workflow * Failover if supervision is not possible * use posix_getpgid * update comment * Split into providers * Add static test methods --------- Co-authored-by: Fritz Michael Gschwantner <fmg@inspiredminds.at>
- Loading branch information
Showing
11 changed files
with
287 additions
and
30 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 @@ | ||
github: Toflar |
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,75 @@ | ||
name: CI | ||
|
||
on: | ||
pull_request: ~ | ||
schedule: | ||
- cron: 0 13 * * MON | ||
|
||
jobs: | ||
cs: | ||
name: Coding Style | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: '8.3' | ||
coverage: none | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install the dependencies | ||
run: composer update --no-interaction --no-suggest | ||
|
||
- name: Run the CS fixer | ||
run: composer cs-fixer | ||
|
||
tests-linux: | ||
name: 'Linux: PHP ${{ matrix.php }}' | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
php: ['8.1', '8.2', '8.3'] | ||
steps: | ||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
coverage: none | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install the dependencies | ||
run: composer update --no-interaction --no-suggest | ||
|
||
- name: Run the unit tests | ||
run: composer unit-tests | ||
|
||
tests-windows: | ||
name: 'Windows: PHP ${{ matrix.php }}' | ||
runs-on: windows-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
php: ['8.1', '8.2', '8.3'] | ||
steps: | ||
- name: Set up Cygwin | ||
uses: egor-tensin/setup-cygwin@v4 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
coverage: none | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install the dependencies | ||
run: composer update --no-interaction --no-suggest | ||
|
||
- name: Run the unit tests | ||
run: composer unit-tests |
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
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
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,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Toflar\CronjobSupervisor\Provider; | ||
|
||
class PosixProvider implements ProviderInterface | ||
{ | ||
public function isSupported(): bool | ||
{ | ||
return \function_exists('posix_getpgid'); | ||
} | ||
|
||
public function isPidRunning(int $pid): bool | ||
{ | ||
// posix_getpgid returns false, if the process is not running anymore | ||
return false !== posix_getpgid($pid); | ||
} | ||
} |
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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Toflar\CronjobSupervisor\Provider; | ||
|
||
interface ProviderInterface | ||
{ | ||
public function isSupported(): bool; | ||
|
||
public function isPidRunning(int $pid): bool; | ||
} |
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,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Toflar\CronjobSupervisor\Provider; | ||
|
||
use Symfony\Component\Process\Process; | ||
|
||
class PsProvider implements ProviderInterface | ||
{ | ||
public function isSupported(): bool | ||
{ | ||
try { | ||
$process = new Process(['ps']); | ||
$process->mustRun(); | ||
|
||
return true; | ||
} catch (\Throwable) { | ||
return false; | ||
} | ||
} | ||
|
||
public function isPidRunning(int $pid): bool | ||
{ | ||
try { | ||
$process = new Process(['ps', '-p', $pid]); | ||
$process->mustRun(); | ||
|
||
// Check for defunct output. If the process was started within this very process, | ||
// it will still be listed, although it's actually finished. | ||
if (str_contains($process->getOutput(), '<defunct>')) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} catch (\Throwable) { | ||
return false; | ||
} | ||
} | ||
} |
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,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Toflar\CronjobSupervisor\Provider; | ||
|
||
use Symfony\Component\Process\Process; | ||
|
||
class WindowsTaskListProvider implements ProviderInterface | ||
{ | ||
public function isSupported(): bool | ||
{ | ||
if ('\\' !== \DIRECTORY_SEPARATOR) { | ||
return false; | ||
} | ||
|
||
try { | ||
$process = new Process(['tasklist']); | ||
$process->mustRun(); | ||
|
||
return true; | ||
} catch (\Throwable) { | ||
return false; | ||
} | ||
} | ||
|
||
public function isPidRunning(int $pid): bool | ||
{ | ||
try { | ||
$process = new Process(['tasklist', '/FI', "PID eq $pid"]); | ||
$process->mustRun(); | ||
|
||
// Symfony Process starts Windows processes via cmd.exe | ||
return str_contains($process->getOutput(), 'cmd.exe'); | ||
} catch (\Throwable) { | ||
return false; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.