Comments (5)
It would be nice if this library introduced it's own DOING_ACTION_SCHEDULER or something similar.
Re-opening so we don't lose sight of this idea (a little unsure if defining a constant is the best approach for us, but the general idea makes sense).
from action-scheduler.
Hi!
However, it seems that wp_doing_cron() does not always return true when running "Action Scheduler" tasks.
That's right. By default, there are up to three different contexts through which Action Scheduler may be triggered:
- WP Cron
- Async HTTP requests
- WP CLI
In most cases, it's a mix of the first two: it doesn't always run via WP Cron (and so DOING_CRON
will not always be set).
However, we wonder whether this is wise and/or correct, so we are curious about the opinion of the developers of this library.
If you are finding you need something like this, then possibly? Can I just highlight though that we already have some related functionality within the library:
This is generally called immediately prior to processing waiting actions. However, there isn't really any way to ensure this takes effect: restrictions in a given hosting environment take precedence, in many cases.
from action-scheduler.
Thanks @barryhughes, good to know about these 3 contexts. I think the PHP timeouts you were referring to are different from the WordPress HTTP API timeouts. WordPress uses a standard timeout of 5
seconds for HTTP requests: https://developer.wordpress.org/reference/classes/wp_http/request/#parameters. For HTTP requests that are executed via background tasks, this may be slightly higher. However, there is currently no easy way to check whether a script is running in one of the 3 contexts mentioned? For the WordPress cron wp_doing_cron()
for WP-CLI defined( 'WP_CLI' ) && WP_CLI
and for the Action Scheduler "Async HTTP requests"?
from action-scheduler.
I'm sorry, I misunderstood.
However, there is currently no easy way to check whether a script is running in one of the 3 contexts mentioned?
I'm not sure how useful this would be in your case, but the action_scheduler_begin_execute
hook is triggered immediately before each scheduled action is fetched and executed, and supplies two parameters to its callbacks:
$action_id
$context
The second of those provides the information you are looking for (and even without it, you could still use the action itself as a signal that you are 'inside' the scheduled action queue).
Might that work? If not, we could explore alternatives. For instance, it would seem reasonable to also share the context via the action_scheduler_before_process_queue
action hook, and there are probably various other possibilities.
from action-scheduler.
Thanks, for now we handled it this way:
- https://github.com/pronamic/wp-pay-core/blob/b1c28b0d2f7e4772ce4e600ff6215e613cc87996/src/ActionSchedulerController.php#L1-L41
- https://github.com/pronamic/wp-mollie/blob/13bfb8f77bb4333c975e45093b19ffb2771d0c82/src/Client.php#L102-L147
It would be nice if this library introduced it's own DOING_ACTION_SCHEDULER
or something similar.
from action-scheduler.
Related Issues (20)
- action_scheduler/migration_hook will not be executed as no callbacks are registered. HOT 2
- Need to add a hook when ever new action is registered HOT 2
- Switch translation inside schedule hook HOT 1
- Document all the hooks and publish to documentation page about them
- Hybrid store does not support unique actions HOT 1
- PHP Fatal error: Uncaught Error: Class "ActionScheduler_Lock" on plugin uninstall HOT 2
- WordPress.org plugin review warnings/issues HOT 1
- Action not scheduled, no error logged HOT 5
- ActionScheduler tables are not reinitialized after manually deleting the tables HOT 3
- Documentation - clarify that tasks will run at the specified time or later HOT 1
- Improve timeout calculations with more accurate start time and by including all tasks HOT 1
- `has_pending_actions_due()` performance improvements HOT 2
- Batch size should be adjustable during processing HOT 1
- Document all WP CLI (sub-)commands
- Have Past Due Items but CLI command won't pick them up HOT 3
- Action scheduler in comments HOT 1
- Could I pause scheduled actions? HOT 2
- Use ErrorException when catching errors while processing scheduled actions HOT 1
- How to avoid failed actions because of unable to update status to "in-progress"? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from action-scheduler.