wp-cli / cron-command
测试、运行和删除 WP-Cron 事件;管理 WP-Cron 调度。
Requires
- wp-cli/wp-cli: ^2.5
Requires (Dev)
- wp-cli/entity-command: ^1.3 || ^2
- wp-cli/eval-command: ^2.0
- wp-cli/server-command: ^2.0
- wp-cli/wp-cli-tests: ^4
This package is auto-updated.
Last update: 2024-09-05 16:59:16 UTC
README
测试、运行和删除 WP-Cron 事件;管理 WP-Cron 调度。
使用
此软件包实现了以下命令
wp cron
测试、运行和删除 WP-Cron 事件;管理 WP-Cron 调度。
wp cron
示例
# Test WP Cron spawning system
$ wp cron test
Success: WP-Cron spawning is working as expected.
wp cron test
测试 WP Cron 生成系统并报告其状态。
wp cron test
此命令通过以下步骤测试生成系统:
- 检查是否设置了
DISABLE_WP_CRON
常量;如果为真,则返回错误,因为 WP-Cron 已禁用。 - 检查是否设置了
ALTERNATE_WP_CRON
常量;如果为真,则发出警告。 - 尝试通过 HTTP 生成 WP-Cron;如果返回非 200 响应代码,则发出警告。
示例
# Cron test runs successfully.
$ wp cron test
Success: WP-Cron spawning is working as expected.
wp cron event
安排、运行和删除 WP-Cron 事件。
wp cron event
示例
# Schedule a new cron event
$ wp cron event schedule cron_test
Success: Scheduled event with hook 'cron_test' for 2016-05-31 10:19:16 GMT.
# Run all cron events due right now
$ wp cron event run --due-now
Executed the cron event 'cron_test_1' in 0.01s.
Executed the cron event 'cron_test_2' in 0.006s.
Success: Executed a total of 2 cron events.
# Delete all scheduled cron events for the given hook
$ wp cron event delete cron_test
Success: Deleted a total of 2 cron events.
# List scheduled cron events in JSON
$ wp cron event list --fields=hook,next_run --format=json
[{"hook":"wp_version_check","next_run":"2016-05-31 10:15:13"},{"hook":"wp_update_plugins","next_run":"2016-05-31 10:15:13"},{"hook":"wp_update_themes","next_run":"2016-05-31 10:15:14"}]
wp cron event delete
删除给定钩子的所有安排的 cron 事件。
wp cron event delete [<hook>...] [--due-now] [--exclude=<hooks>] [--all]
选项
[<hook>...]
One or more hooks to delete.
[--due-now]
Delete all hooks due right now.
[--exclude=<hooks>]
Comma-separated list of hooks to exclude.
[--all]
Delete all hooks.
示例
# Delete all scheduled cron events for the given hook
$ wp cron event delete cron_test
Success: Deleted a total of 2 cron events.
wp cron event list
列出安排的 cron 事件。
wp cron event list [--fields=<fields>] [--<field>=<value>] [--field=<field>] [--format=<format>]
选项
[--fields=<fields>]
Limit the output to specific object fields.
[--<field>=<value>]
Filter by one or more fields.
[--field=<field>]
Prints the value of a single field for each event.
[--format=<format>]
Render output in a particular format.
---
default: table
options:
- table
- csv
- ids
- json
- count
- yaml
---
可用字段
以下字段将默认显示在每个 cron 事件中
- hook
- next_run_gmt
- next_run_relative
- recurrence
以下字段是可选的
- time
- sig
- args
- schedule
- interval
- next_run
示例
# List scheduled cron events
$ wp cron event list
+-------------------+---------------------+---------------------+------------+
| hook | next_run_gmt | next_run_relative | recurrence |
+-------------------+---------------------+---------------------+------------+
| wp_version_check | 2016-05-31 22:15:13 | 11 hours 57 minutes | 12 hours |
| wp_update_plugins | 2016-05-31 22:15:13 | 11 hours 57 minutes | 12 hours |
| wp_update_themes | 2016-05-31 22:15:14 | 11 hours 57 minutes | 12 hours |
+-------------------+---------------------+---------------------+------------+
# List scheduled cron events in JSON
$ wp cron event list --fields=hook,next_run --format=json
[{"hook":"wp_version_check","next_run":"2016-05-31 10:15:13"},{"hook":"wp_update_plugins","next_run":"2016-05-31 10:15:13"},{"hook":"wp_update_themes","next_run":"2016-05-31 10:15:14"}]
wp cron event run
运行给定钩子的下一个计划 cron 事件。
wp cron event run [<hook>...] [--due-now] [--exclude=<hooks>] [--all]
选项
[<hook>...]
One or more hooks to run.
[--due-now]
Run all hooks due right now.
[--exclude=<hooks>]
Comma-separated list of hooks to exclude.
[--all]
Run all hooks.
示例
# Run all cron events due right now
$ wp cron event run --due-now
Executed the cron event 'cron_test_1' in 0.01s.
Executed the cron event 'cron_test_2' in 0.006s.
Success: Executed a total of 2 cron events.
wp cron event schedule
安排新的 cron 事件。
wp cron event schedule <hook> [<next-run>] [<recurrence>] [--<field>=<value>]
选项
<hook>
The hook name.
[<next-run>]
A Unix timestamp or an English textual datetime description compatible with `strtotime()`. Defaults to now.
[<recurrence>]
How often the event should recur. See `wp cron schedule list` for available schedule names. Defaults to no recurrence.
[--<field>=<value>]
Arguments to pass to the hook for the event. <field> should be a numeric key, not a string.
示例
# Schedule a new cron event
$ wp cron event schedule cron_test
Success: Scheduled event with hook 'cron_test' for 2016-05-31 10:19:16 GMT.
# Schedule new cron event with hourly recurrence
$ wp cron event schedule cron_test now hourly
Success: Scheduled event with hook 'cron_test' for 2016-05-31 10:20:32 GMT.
# Schedule new cron event and pass arguments
$ wp cron event schedule cron_test '+1 hour' --0=first-argument --1=second-argument
Success: Scheduled event with hook 'cron_test' for 2016-05-31 11:21:35 GMT.
wp cron schedule
获取 WP-Cron 调度。
wp cron schedule
示例
# List available cron schedules
$ wp cron schedule list
+------------+-------------+----------+
| name | display | interval |
+------------+-------------+----------+
| hourly | Once Hourly | 3600 |
| twicedaily | Twice Daily | 43200 |
| daily | Once Daily | 86400 |
+------------+-------------+----------+
wp cron schedule list
列出可用的 cron 调度。
wp cron schedule list [--fields=<fields>] [--field=<field>] [--format=<format>]
选项
[--fields=<fields>]
Limit the output to specific object fields.
[--field=<field>]
Prints the value of a single field for each schedule.
[--format=<format>]
Render output in a particular format.
---
default: table
options:
- table
- csv
- ids
- json
- yaml
---
可用字段
以下字段将默认显示在每个 cron 调度中
- name
- display
- interval
没有其他字段。
示例
# List available cron schedules
$ wp cron schedule list
+------------+-------------+----------+
| name | display | interval |
+------------+-------------+----------+
| hourly | Once Hourly | 3600 |
| twicedaily | Twice Daily | 43200 |
| daily | Once Daily | 86400 |
+------------+-------------+----------+
# List id of available cron schedule
$ wp cron schedule list --fields=name --format=ids
hourly twicedaily daily
wp cron event unschedule
取消安排给定钩子的所有 cron 事件。
wp cron event unschedule <hook>
选项
<hook>
Name of the hook for which all events should be unscheduled.
示例
# Unschedule a cron event on given hook.
$ wp cron event unschedule cron_test
Success: Unscheduled 2 events for hook 'cron_test'.
安装
此软件包包含在 WP-CLI 本身中,无需额外安装。
要安装此软件包的最新版本,而不仅仅是 WP-CLI 中包含的版本,请运行
wp package install [email protected]:wp-cli/cron-command.git
贡献
我们感谢您主动为这个项目做出贡献。
贡献不仅仅局限于代码。我们鼓励您以最适合您能力的方式做出贡献,例如编写教程、在当地聚会中演示、帮助其他用户解决支持问题或修订我们的文档。
要获得更详细的介绍,请查看 WP-CLI 贡献指南。此软件包遵循那些政策和指南。
报告错误
认为您已经找到了一个错误?我们很高兴您能帮助我们修复它。
在创建新问题之前,您应该搜索现有问题,以查看是否存在对该问题的现有解决方案,或者它是否已在较新版本中修复。
在搜索一段时间后,如果您发现没有针对您错误的公开或已固定的issue,请创建一个新的issue。尽可能提供详细信息,如果可能的话,请提供重现问题的清晰步骤。更多信息,请查看我们的bug报告文档。
创建pull request
想要贡献一个新特性吗?请首先打开一个新的issue来讨论这个特性是否适合项目。
一旦您决定投入时间来推动您的pull request,请遵循我们创建pull request的指南以确保这是一个愉快的体验。有关在本地处理此包的详细信息,请参阅"设置"。
支持
GitHub issue不是用于一般支持问题的地方,但您可以尝试其他途径:https://wp-cli.org/#support
此README.md是从项目的代码库动态生成的,使用wp scaffold package-readme
(文档)。要提出更改建议,请提交针对代码库相应部分的pull request。