Skip to content

Commit c346306

Browse files
authored
Initial version of the plugin (#1)
Add wp cron-concurrent command for parallel cron execution
2 parents 08ca5df + 08bfdb3 commit c346306

9 files changed

Lines changed: 594 additions & 0 deletions

File tree

.github/workflows/test.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches:
6+
- trunk
7+
pull_request:
8+
9+
jobs:
10+
test:
11+
name: Integration tests (wp-env)
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: 'lts/*'
24+
25+
- name: Install Node.js dependencies
26+
run: npm install
27+
28+
# Cache the wp-env working directory (~/.wp-env) so that the WordPress
29+
# download and database setup are reused across runs when nothing changes.
30+
- name: Cache wp-env
31+
uses: actions/cache@v4
32+
with:
33+
path: ~/.wp-env
34+
key: wp-env-${{ hashFiles('package.json', '.wp-env.json') }}
35+
restore-keys: |
36+
wp-env-
37+
38+
- name: Start wp-env
39+
run: npx wp-env start
40+
41+
- name: Run tests
42+
run: npm test
43+
44+
- name: Stop wp-env
45+
run: npx wp-env stop
46+
if: always()

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules/
2+
vendor/
3+
.wp-env/
4+
composer.lock
5+
package-lock.json

.wp-env.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"plugins": ["."],
3+
"mappings": {
4+
"wp-cli.yml": "./wp-cli.yml"
5+
},
6+
"testsEnvironment": false
7+
}

composer.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "dd32/wpcli-cron-concurrent",
3+
"description": "Runs WordPress cron tasks concurrently via wp-cli.",
4+
"type": "wp-cli-package",
5+
"keywords": ["wp-cli", "cron", "concurrent"],
6+
"license": "MIT",
7+
"require": {
8+
"wp-cli/wp-cli": "^2.0"
9+
},
10+
"autoload": {
11+
"classmap": ["src/"],
12+
"files": ["cron-concurrent.php"]
13+
},
14+
"extra": {
15+
"commands": [
16+
"cron-concurrent",
17+
"cron-concurrent run"
18+
]
19+
},
20+
"minimum-stability": "dev",
21+
"prefer-stable": true
22+
}

cron-concurrent.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* Plugin Name: WP-CLI Cron Concurrent
4+
* Description: Runs WordPress cron tasks concurrently via wp-cli.
5+
* Version: 1.0.0
6+
* Author: dd32
7+
* License: MIT
8+
*/
9+
10+
/**
11+
* WP-CLI Cron Concurrent – entry point.
12+
*
13+
* Loaded automatically by WP-CLI when this package is installed via Composer,
14+
* or explicitly via `--require` / a `wp-cli.yml` require entry.
15+
* Registers the `wp cron-concurrent` command group.
16+
*
17+
* @package dd32/wpcli-cron-concurrent
18+
*/
19+
20+
if ( ! class_exists( 'WP_CLI' ) ) {
21+
return;
22+
}
23+
24+
// When installed as a Composer package the classmap autoloader already
25+
// handles this file; the direct require is only a safety-net for manual
26+
// --require usage (e.g. inside wp-env test containers).
27+
if ( ! class_exists( 'CronConcurrent' ) ) {
28+
require_once __DIR__ . '/src/CronConcurrent.php';
29+
}
30+
31+
WP_CLI::add_command( 'cron-concurrent', 'CronConcurrent' );

package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "wpcli-cron-concurrent",
3+
"description": "Runs WordPress cron tasks concurrently via wp-cli.",
4+
"private": true,
5+
"scripts": {
6+
"env:start": "wp-env start",
7+
"env:stop": "wp-env stop",
8+
"env:destroy": "wp-env destroy",
9+
"test": "bash tests/run-tests.sh"
10+
},
11+
"devDependencies": {
12+
"@wordpress/env": "^11.0.0"
13+
}
14+
}

0 commit comments

Comments
 (0)