Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PJAS-466 Tasks being enqueued multiple times during peak hours #1

Merged
merged 14 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Code Quality

on:
push:
branches: [ '*' ]
pull_request:
branches: [ '*' ]

jobs:
build:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: ['ubuntu-latest']
php-versions: ['8.1', '8.2', '8.3']

services:
redis:
image: redis
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379

steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
tools: cs2pr

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest

- name: Run phpcs
run: composer run-script ci-phpcs -- --report=checkstyle | cs2pr --graceful-warnings

- name: Run phpstan
run: composer run-script ci-phpstan
25 changes: 17 additions & 8 deletions .github/workflows/hydrogen.yml → .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
name: Hydrogen PHPUnit
name: Tests

on:
push:
branches: [ master, stage ]
branches: [ '*' ]
pull_request:
branches: [ master, stage ]
branches: [ '*' ]

jobs:
build:
runs-on: ubuntu-latest

runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: ['ubuntu-latest']
php-versions: ['8.1', '8.2', '8.3']

services:
redis:
image: redis
Expand All @@ -19,16 +25,19 @@ jobs:
--health-retries 5
ports:
- 6379:6379

steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest

- name: Run PHPUnit
run: php vendor/bin/phpunit
run: composer run-script ci-phpunit
env:
PHPUNIT_BERYILLIUM_PARALLEL_WAIT: 15

- name: Run PHPStan
run: php vendor/bin/phpstan analyse src --error-format=github -l8
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
vendor/
coverage/
composer.lock
.phpunit.result.cache
phpunit.xml
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,31 @@ StartLimitBurst=10
WantedBy=multi-user.target
```

### Code Quality

Make sure the latest quality standards are met by executing the `phpcs` and `phpstan` scripts. There are three commands available which are defined in the root `composer.json` as custom scripts.

Execute `phpcs` and `phpcbf` for linting and automatic fixing respectively:

```
composer run-script ci-phpcs
composer run-script ci-phpcs-fix
```

Execute `phpstan` to analyse the code to detect code issues.

```
composer run-script ci-phpstan
```

### Tests

There are tests as part of this package in order to verify that everything works as expected.

Execute the following command to run the tests:

```
composer run-script ci-phpunit
```

**Note: You need to configure your database connection first in `phpunit.xml` before running the tests. If `phpunit.xml` does not exist, copy the `phpunit.xml.dist` file.**
35 changes: 30 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,27 @@
],
"bin": [],
"require": {
"php": ">=7.4",
"php": "^8.1",
"symfony/process": "^5.4"
},
"require-dev": {
"phpstan/phpstan": "^1.5",
"phpunit/phpunit": "^9.5"
"phpunit/phpunit": "^9.5",
"cineman/hydrogen-cs": "dev-master",
"phpstan/phpstan": "^1.7.0",
"squizlabs/php_codesniffer": "^3.5"
},
"repositories": [
{
"type": "composer",
"url": "https://repos-php.cineman.ch",
"options": { "http": {
"header": [ "X-Access-Token: BBvDcoQjBCC4MCN8YBZyzPwbZqUZfKLnHvv8ZQVp4RwVDr6dyMuaTYLCBiyBRUmT" ]
}}
}
],
"autoload": {
"psr-4": {
"Beryllium\\": "src/"
"Beryllium\\": "src/"
}
},
"autoload-dev": {
Expand All @@ -26,5 +37,19 @@
}
},
"minimum-stability": "dev",
"prefer-stable": true
"prefer-stable": true,
"scripts": {
"ci-phpcs": [
"vendor/bin/phpcs src/ --standard=vendor/cineman/hydrogen-cs"
],
"ci-phpcs-fix": [
"vendor/bin/phpcbf src/ --standard=vendor/cineman/hydrogen-cs"
],
"ci-phpstan": [
"vendor/bin/phpstan analyse src --error-format=github -l8"
],
"ci-phpunit": [
"vendor/bin/phpunit"
]
}
}
7 changes: 0 additions & 7 deletions phpstan.neon

This file was deleted.

6 changes: 6 additions & 0 deletions phpunit.xml → phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="phpunit.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<php>
<env name="BERYLLIUM_REDIS_HOST" value="127.0.0.1"/>
<env name="BERYLLIUM_REDIS_PORT" value="6379"/>
<env name="BERYLLIUM_IDLE_WAIT" value="10000"/>
<env name="BERYLLIUM_MAX_WORKERS" value="8"/>
</php>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
Expand Down
63 changes: 41 additions & 22 deletions src/Driver/DriverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,31 @@ interface DriverInterface
/**
* Adds the given Job to the queue
*
* @param Job $job
* @param int $maxRetries
* @param Job $job
* @param int $maxRetries
*
* @return void
*/
public function add(Job $job, int $maxRetries = 3) : void;

/**
* Get a job instance by the given id.
*
* @param string $id The Job identifier.
* @return Job
* @param string $id The Job identifier.
*
* @return Job|null
*/
public function get(string $id) : ?Job;

/**
* Check if a job exists in the queue
*
* @param string $id The Job identifier.
*
* @return bool
*/
public function exists(string $id) : bool;

/**
* Get the ID of a waiting job
*
Expand All @@ -46,31 +57,35 @@ public function waitingCount() : int;
/**
* Reinsert the job into the waitlist
*
* @param string $id The Job identifier.
* @param string $id The Job identifier.
*
* @return void
*/
public function retry(string $id) : void;

/**
* Get the maximum number of attempts we should try for the job
*
* @param string $id The Job identifier.
* @return int Returns -1 if the job has never been executed
* @param string $id The Job identifier.
*
* @return int Returns -1 if the job has never been executed
*/
public function getMaxRetries(string $id) : int;

/**
* Get the number of attempts this job already had.
*
* @param string $id The Job identifier.
* @return int Returns -1 if the job has never been executed
* @param string $id The Job identifier.
*
* @return int Returns -1 if the job has never been executed
*/
public function attemptCount(string $id) : int;

/**
* Cleanup the jobs data
*
* @param string $id The Job identifier.
* @param string $id The Job identifier.
*
* @return void
*/
public function cleanup(string $id) : void;
Expand All @@ -92,19 +107,21 @@ public function clearEverything() : void;
/**
* Simply store a value
*
* @param string $key
* @param mixed $value
* @param string $key
* @param mixed $value
*
* @return void
*/
public function storeStatsValue(string $key, $value) : void;

/**
* Simply get a value
*
* @param string $key
* @param string $key
*
* @return mixed
*/
public function getStatsValue(string $key);
public function getStatsValue(string $key) : mixed;

/**
* Locking System Methods
Expand All @@ -115,25 +132,27 @@ public function getStatsValue(string $key);
/**
* Checks if the given key is locked on the driver.
*
* @param string $key
* @param string $key
*
* @return bool
*/
public function isLocked(string $key) : bool;

/**
* Returns the locks token
*
* @param string $key
* @return string
* @param string $key
*
* @return string|null
*/
public function getLockToken(string $key) : ?string;

/**
* Creates a lock entry on the driver, this must be synchronised!
*
* @param string $key
* @param string $token
* @param int $ttl
* @param string $key
* @param string $token
* @param int $ttl
*
* @return bool Returns true if the lock could be created
*/
Expand All @@ -143,8 +162,8 @@ public function lock(string $key, string $token, int $ttl) : bool;
* Removes a lock entry on the driver, this must be synchronised!
* Also the lock for the key should only be removed if the token matches!
*
* @param string $key
* @param string $token
* @param string $key
* @param string $token
*
* @return bool Retruns true if the lock could be removed.
*/
Expand Down
Loading
Loading