Re-schedule a failed action
-
Hello,
I’m trying to reschedule a failed action using the hook: action_scheduler_failed_execution.
But , when I test my code , I notice that the call back function is never called
-
Hello @vanbom ,
Even though I’m not a developer I would like to see the code you were working with.
If you need to consult with a developer I will recommend joining WooCommerce’s Slack channel and you can also the WooCommerce Community on Facebook has some awesome people who can help you out as well.
hi @rur165 .
I have actions registered with the status ‘Failed’.
So I use the ‘…..’ hook to reschedule them.Code:
add_action( 'action_scheduler_failed_execution', 'reschedule_failed_action', 10, 3 ); function reschedule_failed_action( $action_id, $e, $context ){ // test update_option('action_failed_' . $action_id, $action_id ); }The call back function is never called
-
This reply was modified 4 years, 4 months ago by
Younes.
Hi @vanbom,
If I use your code and conspire to make a scheduled action fail (by throwing an exception) then the callback function is successfully called and the
action_failed_<ID>option is created/updated.In your case:
- Are you positive the action is failing?
- Where did you add your code? Asking this because, depending on where or how you added it, it may not be executed early enough.
Thanks!
Hello and thank you for your response .
So here is my code:
<?php class Handle_Failed_Action{ public function __construct() { // Some code .... $this->catch_failed_action(); } public function catch_failed_action(){ add_action( 'init', array ( $this, 'failed_execution' ) ); } public function failed_execution(){ if ( has_action ( 'action_scheduler_failed_execution' ) ) { // The option is successfully created update_option('action_failed__execution' , 1 ); add_action( 'action_scheduler_failed_execution', array ( $this , 'call_failed_execution' ) ); } } public function call_failed_execution ( $action_id ){ // Here ... failed create / update the option update_option('action_failed_' . $action_id, $action_id ); } }So if I set that up, and enqueue a scheduled action where the callback throws an exception, method
call_failed_execution()is successfully executed and theaction_failed_<ID>option is set.I’m afraid there’s no obvious answer I can offer you on this occasion, and likely there are factors at play that I can’t see based on the information shared so far.
if ( has_action ( 'action_scheduler_failed_execution' ) ) { /*...*/ }One thing I would note (though perhaps I’m just missing context) is that the above check is probably unnecessary, but I don’t think that is relevant to the actual problem you are facing.
There probably isn’t much more assistance we can provide right here in the forums, but if you manage to distill this down into something we can easily replicate definitely feel free to follow-up over on the issue tracker.
Thanks!
Hi @barryhughes-1 ,
First thank you for your follow-up, messages and explanation.
I will follow your recommendation and go to the Plugin’s github repository, and see in depth. -
This reply was modified 4 years, 4 months ago by
The topic ‘Re-schedule a failed action’ is closed to new replies.