Skip to content
Open
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
27 changes: 25 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ workflows:
- php73-build
- php74-build
- php80-build
- php81-build
- php82-build
- php83-build
- php84-build
- php85-build

version: 2

Expand Down Expand Up @@ -66,9 +71,27 @@ jobs:
docker:
- image: cimg/php:8.1
- image: *mysql_image

php82-build:
<<: *php_job
docker:
- image: cimg/php:8.2
- image: *mysql_image
- image: *mysql_image

php83-build:
<<: *php_job
docker:
- image: cimg/php:8.3
- image: *mysql_image

php84-build:
<<: *php_job
docker:
- image: cimg/php:8.4
- image: *mysql_image

php85-build:
<<: *php_job
docker:
- image: cimg/php:8.5
- image: *mysql_image
84 changes: 84 additions & 0 deletions .phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0"?>
<ruleset name="WordPress Coding Standards based custom ruleset for your plugin">
<description>Generally-applicable sniffs for WordPress plugins.</description>

<!-- What to scan -->
<file>src/</file>
<exclude-pattern>/vendor/</exclude-pattern>
<exclude-pattern>/node_modules/</exclude-pattern>
<exclude-pattern>/tests/*</exclude-pattern>

<!-- How to scan -->
<!-- Usage instructions: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage -->
<!-- Annotated ruleset: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml -->
<arg value="sp"/> <!-- Show sniff and progress -->
<arg name="basepath" value="./"/><!-- Strip the file paths down to the relevant bit -->
<arg name="colors"/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="8"/><!-- Enables parallel processing when available for faster results. -->

<!-- Rules: Check PHP version compatibility -->
<!-- https://github.com/PHPCompatibility/PHPCompatibility#sniffing-your-code-for-compatibility-with-specific-php-versions -->
<config name="testVersion" value="7.3-"/>
<!-- https://github.com/PHPCompatibility/PHPCompatibilityWP -->
<rule ref="PHPCompatibilityWP"/>

<!-- Rules: WordPress Coding Standards -->
<!-- https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards -->
<!-- https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties -->
<config name="minimum_supported_wp_version" value="5.0"/>
<rule ref="WordPress">
<!-- Unable to fix -->
<exclude name="WordPress.Files.FileName.InvalidClassFileName"/>
<exclude name="WordPress.Files.FileName.NotHyphenatedLowercase"/>
<exclude name="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound"/>
<exclude name="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound"/>
<exclude name="WordPress.DB.DirectDatabaseQuery.NoCaching"/>
<exclude name="WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize"/>
<exclude name="WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize"/>

<!-- TODO: Maybe fix -->
<exclude name="WordPress.WP.CronInterval.ChangeDetected"/>
<exclude name="WordPress.DB.DirectDatabaseQuery.DirectQuery"/>
</rule>
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<properties>
<!-- Value: replace the function, class, and variable prefixes used. -->
<property name="prefixes" type="array">
<element value="wp_queue"/>
</property>
</properties>

<!-- TODO: Maybe fix -->
<exclude name="WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound"/>
</rule>
<rule ref="WordPress.WP.I18n">
<properties>
<!-- Value: replace the text domain used. -->
<property name="text_domain" type="array">
<element value="wp-queue"/>
</property>
</properties>

<!-- TODO: Should fix -->
<exclude name="WordPress.WP.I18n.MissingArgDomain"/>
<exclude name="WordPress.WP.I18n.MissingTranslatorsComment"/>
</rule>
<rule ref="WordPress.WhiteSpace.ControlStructureSpacing">
<properties>
<property name="blank_line_check" value="true"/>
</properties>
</rule>
<rule ref="Squiz.Commenting">
<!-- TODO: Should fix -->
<exclude name="Squiz.Commenting.FileComment.Missing"/>
<exclude name="Squiz.Commenting.ClassComment.Missing"/>
<exclude name="Generic.Commenting.DocComment.MissingShort"/>
<exclude name="Squiz.Commenting.FunctionComment.MissingParamComment"/>
<exclude name="Squiz.Commenting.FunctionComment.EmptyThrows"/>
</rule>
<rule ref="Universal.Arrays">
<!-- TODO: Should fix -->
<exclude name="Universal.Arrays.DisallowShortArraySyntax.Found"/>
</rule>
</ruleset>
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ test-style: vendor
vendor/bin/phpcs

vendor: composer.json
composer install --ignore-platform-reqs
composer install

.PHONY: update-deps
update-deps:
composer update --with-all-dependencies

.PHONY: clean
clean:
rm -f tests/.phpunit.result.cache .phpunit.result.cache

.PHONY: clean-all
clean-all: clean
rm -rf vendor
rm -f tests/.phpunit.result.cache
rm -f composer.lock coverage.clover
12 changes: 5 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
}
],
"require": {
"php": ">=7.3.0",
"nesbot/carbon": "^2.0"
"php": "^7.3|^8.0",
"nesbot/carbon": "^2|^3"
},
"autoload": {
"psr-4": {
Expand All @@ -27,11 +27,9 @@
},
"require-dev": {
"phpunit/phpunit": "^9.0.0",
"10up/wp_mock": "^0.4.2",
"humanmade/coding-standards": "^1.1",
"php-stubs/wp-cli-stubs": "^2.6",
"phpstan/phpstan": "^1.4",
"szepeviktor/phpstan-wordpress": "^1.0"
"10up/wp_mock": "^0.5|^1",
"wp-coding-standards/wpcs": "^3",
"phpcompatibility/phpcompatibility-wp": "*"
},
"config": {
"allow-plugins": {
Expand Down
78 changes: 0 additions & 78 deletions phpcs.xml

This file was deleted.

10 changes: 0 additions & 10 deletions phpstan.neon

This file was deleted.

1 change: 0 additions & 1 deletion src/WP_Queue/Connections/ConnectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,4 @@ public function jobs();
* @return int
*/
public function failed_jobs();

}
55 changes: 36 additions & 19 deletions src/WP_Queue/Connections/DatabaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,14 @@ public function __construct( $wpdb, array $allowed_job_classes = [] ) {
* @return bool|int
*/
public function push( Job $job, $delay = 0 ) {
$result = $this->database->insert( $this->jobs_table, [
'job' => serialize( $job ),
'available_at' => $this->datetime( $delay ),
'created_at' => $this->datetime(),
] );
$result = $this->database->insert(
$this->jobs_table,
[
'job' => serialize( $job ),
'available_at' => $this->datetime( $delay ),
'created_at' => $this->datetime(),
]
);

if ( ! $result ) {
return false;
Expand All @@ -76,13 +79,16 @@ public function push( Job $job, $delay = 0 ) {
public function pop() {
$this->release_reserved();

$sql = $this->database->prepare( "
$sql = $this->database->prepare(
"
SELECT * FROM {$this->jobs_table}
WHERE reserved_at IS NULL
AND available_at <= %s
ORDER BY available_at, id
LIMIT 1
", $this->datetime() );
",
$this->datetime()
);

$raw_job = $this->database->get_row( $sql );

Expand Down Expand Up @@ -160,11 +166,14 @@ public function release( Job $job ) {
* @return bool
*/
public function failure( $job, Exception $exception ) {
$insert = $this->database->insert( $this->failures_table, [
'job' => serialize( $job ),
'error' => $this->format_exception( $exception ),
'failed_at' => $this->datetime(),
] );
$insert = $this->database->insert(
$this->failures_table,
[
'job' => serialize( $job ),
'error' => $this->format_exception( $exception ),
'failed_at' => $this->datetime(),
]
);

if ( $insert ) {
$this->delete( $job );
Expand Down Expand Up @@ -207,9 +216,13 @@ protected function reserve( Job $job ) {
'reserved_at' => $this->datetime(),
];

$this->database->update( $this->jobs_table, $data, [
'id' => $job->id(),
] );
$this->database->update(
$this->jobs_table,
$data,
[
'id' => $job->id(),
]
);
}

/**
Expand All @@ -218,10 +231,14 @@ protected function reserve( Job $job ) {
protected function release_reserved() {
$expired = $this->datetime( -300 );

$sql = $this->database->prepare( "
UPDATE {$this->jobs_table}
SET attempts = attempts + 1, reserved_at = NULL
WHERE reserved_at <= %s", $expired );
$sql = $this->database->prepare(
"
UPDATE {$this->jobs_table}
SET attempts = attempts + 1, reserved_at = NULL
WHERE reserved_at <= %s
",
$expired
);

$this->database->query( $sql );
}
Expand Down
Loading