Skip to content

Commit 3832d44

Browse files
Merge pull request #33 from netlogix/feat/postgres
feat: postgres
2 parents ae8cd99 + 4db374f commit 3832d44

17 files changed

Lines changed: 766 additions & 441 deletions

.github/workflows/functionaltests.yml

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,68 @@ on: [ push, pull_request ]
44

55
jobs:
66
unittests:
7-
name: '[PHP ${{ matrix.php-version }} | Flow ${{ matrix.flow-version }} | MySQL ${{ matrix.mysql-version }}] Functional Tests'
7+
name: '[PHP ${{ matrix.php-version }} | Flow ${{ matrix.flow-version }} | Database ${{ matrix.database.image }} ${{ matrix.database.version }}] Functional Tests'
88
runs-on: ubuntu-latest
99

1010
strategy:
1111
fail-fast: false
1212
matrix:
13-
php-version: [ 8.2, 8.3 ]
13+
php-version: [ 8.3, 8.4, 8.5 ]
1414
flow-version: [ 8.3 ]
15-
mysql-version: [5.7, 8.0]
15+
database:
16+
- image: postgres
17+
version: 16
18+
port: 5432
19+
options: --health-cmd="exit 0"
20+
env:
21+
POSTGRES_USER: 'flow'
22+
POSTGRES_PASSWORD: 'flow'
23+
POSTGRES_DB: 'flow'
24+
- image: postgres
25+
version: 14
26+
port: 5432
27+
options: --health-cmd="pg_isready" --health-interval=10s --health-timeout=5s --health-retries=3 --health-start-period 10s
28+
env:
29+
POSTGRES_USER: 'flow'
30+
POSTGRES_PASSWORD: 'flow'
31+
POSTGRES_DB: 'flow'
32+
- image: mysql
33+
version: 8.0
34+
port: 3306
35+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
36+
env:
37+
MYSQL_USER: 'flow'
38+
MYSQL_PASSWORD: 'flow'
39+
MYSQL_DATABASE: 'flow'
40+
MYSQL_ROOT_PASSWORD: 'root'
41+
- image: mysql
42+
version: 5.7
43+
port: 3306
44+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
45+
env:
46+
MYSQL_USER: 'flow'
47+
MYSQL_PASSWORD: 'flow'
48+
MYSQL_DATABASE: 'flow'
49+
MYSQL_ROOT_PASSWORD: 'root'
1650

1751
services:
18-
mysql:
19-
image: 'mysql:${{ matrix.mysql-version }}'
20-
env:
21-
MYSQL_USER: flow
22-
MYSQL_PASSWORD: flow
23-
MYSQL_DATABASE: flow
24-
MYSQL_ROOT_PASSWORD: root
52+
database:
53+
image: ${{ matrix.database.image }}:${{ matrix.database.version }}
2554
ports:
26-
- '3306:3306'
27-
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
55+
- ${{ matrix.database.port }}:${{ matrix.database.port }}
56+
env: ${{ matrix.database.env }}
57+
options: ${{ matrix.database.options }}
2858

2959
env:
3060
APP_ENV: true
3161
FLOW_CONTEXT: Testing/Functional
3262
FLOW_DIST_FOLDER: flow-base-distribution
33-
MYSQL_HOST: '127.0.0.1'
34-
MYSQL_PORT: 3306
35-
MYSQL_DATABASE: 'flow'
36-
MYSQL_USER: 'flow'
37-
MYSQL_PASSWORD: 'flow'
3863

3964
steps:
4065
- uses: shivammathur/setup-php@v2
4166
with:
4267
php-version: ${{ matrix.php-version }}
43-
extensions: mbstring, xml, json, zlib, iconv, intl, pdo_sqlite
68+
extensions: mbstring, xml, json, zlib, iconv, intl, pdo_pgsql, pdo_mysql
4469
ini-values: opcache.fast_shutdown=0
4570

4671
- name: "[1/5] Create composer project - Cache composer dependencies"
@@ -53,7 +78,7 @@ jobs:
5378
php-${{ matrix.php-version }}-flow-
5479
5580
- name: "[2/5] Create composer project - No install"
56-
run: composer create-project neos/flow-base-distribution ${{ env.FLOW_DIST_FOLDER }} --prefer-dist --no-progress --no-install "^${{ matrix.flow-version }}"
81+
run: composer create-project neos/flow-base-distribution ${{ env.FLOW_DIST_FOLDER }} --prefer-dist --no-progress --no-install "${{ matrix.flow-version }}"
5782

5883
- name: "[3/5] Allow neos composer plugin"
5984
run: composer config --no-plugins allow-plugins.neos/composer-plugin true
@@ -73,11 +98,13 @@ jobs:
7398
path: ${{ env.FLOW_DIST_FOLDER }}/DistributionPackages/Netlogix.JobQueue.Scheduled
7499

75100
- name: Install netlogix/jobqueue-scheduled
76-
run: composer require netlogix/jobqueue-scheduled:@dev
101+
run: |
102+
composer config minimum-stability dev
103+
composer require netlogix/jobqueue-scheduled:@dev
77104
working-directory: ${{ env.FLOW_DIST_FOLDER }}
78105

79106
- name: "Copy Settings.yaml.dist"
80-
run: cp DistributionPackages/Netlogix.JobQueue.Scheduled/Settings.yaml.dist Configuration/Testing/Settings.yaml
107+
run: "cp DistributionPackages/Netlogix.JobQueue.Scheduled/Settings.yaml.${{ matrix.database.image }}.dist Configuration/Testing/Settings.yaml"
81108
working-directory: ${{ env.FLOW_DIST_FOLDER }}
82109

83110
- name: Run tests

Classes/Command/SchedulerCommandController.php

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
namespace Netlogix\JobQueue\Scheduled\Command;
66

7+
use Doctrine\DBAL\Exception;
8+
use Doctrine\DBAL\Platforms\MySqlPlatform;
9+
use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
10+
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
711
use Doctrine\DBAL\Types\Types;
812
use Flowpack\JobQueue\Common\Job\JobManager;
913
use Neos\Flow\Cli\CommandController;
@@ -24,7 +28,7 @@ class SchedulerCommandController extends CommandController
2428

2529
protected ThrowableStorageInterface $throwableStorage;
2630

27-
protected Connection $dbal;
31+
protected Connection $connection;
2832

2933
public function injectScheduler(Scheduler $scheduler): void
3034
{
@@ -43,22 +47,25 @@ public function injectThrowableStorageInterface(ThrowableStorageInterface $throw
4347

4448
public function injectConnection(Connection $connection): void
4549
{
46-
$this->dbal = $connection;
50+
$this->connection = $connection;
4751
}
4852

4953
/**
5054
* Reset stale jobs that have not changed for too long.
5155
*
5256
* @param string $groupName Free jobs in this group only
5357
* @param int $minutes Count jobs as stale if their last activity was more than these many minutes ago
58+
* @throws Exception
5459
*/
5560
public function resetStaleJobsCommand(
5661
string $groupName,
5762
int $minutes = 10
5863
): void {
5964
$tableName = ScheduledJob::TABLE_NAME;
60-
$freed = $this->dbal->executeQuery(
61-
sql: <<<MySQL
65+
$platform = $this->connection->getDbal()->getDatabasePlatform();
66+
if ($platform instanceof MySqlPlatform)
67+
{
68+
$sql = <<<MySQL
6269
UPDATE {$tableName}
6370
SET running = 0,
6471
claimed = '',
@@ -67,7 +74,26 @@ public function resetStaleJobsCommand(
6774
AND claimed NOT LIKE 'failed(%)'
6875
AND groupname = :groupName
6976
AND activity < NOW() - INTERVAL :minutes MINUTE
70-
MySQL,
77+
MySQL;
78+
}
79+
else if ($platform instanceof PostgreSqlPlatform || $platform instanceof PostgreSQL94Platform)
80+
{
81+
$sql = <<<PostgreSQL
82+
UPDATE {$tableName}
83+
SET running = FALSE,
84+
claimed = '',
85+
incarnation = incarnation + 1
86+
WHERE running = TRUE
87+
AND claimed NOT LIKE 'failed(%)'
88+
AND groupname = :groupName
89+
AND activity < NOW() - make_interval(mins => :minutes)
90+
PostgreSQL;
91+
} else {
92+
throw new \RuntimeException("unsupported database platform " . $this->connection->getDbal()->getDatabasePlatform()->getName());
93+
}
94+
95+
$freed = $this->connection->executeQuery(
96+
sql: $sql,
7197
params: [
7298
'groupName' => $groupName,
7399
'minutes' => max($minutes, 1),

0 commit comments

Comments
 (0)