• Resolved elektrobank

    (@elektrobank)


    I need to be able to log the result of each action that gets run as to whether it succeeded and an error message if it failed. I can throw an exception to cause the status to be ‘failed’ but the exception message doesn’t get stored anywhere, so that doesn’t help much. Is there already a way to do this that I am missing or do I have to make my own table and track it separately?

    Another option would be to add a column to wp_actionscheduler_actions to store an error message and update that myself, but I can’t see any way to get the action_id from within the hook that gets called to be able to update that table. Is it possible to get it or is there a better way to do this?

    Thanks

    • This topic was modified 4 years, 2 months ago by elektrobank.
Viewing 9 replies - 1 through 9 (of 9 total)
  • @elektrobank Using the hooks you asked about previously would allow you to store the result elsewhere. You could also define a custom logger I believe, but I’ve no experience with that.

    Also, worth noting, that the exception message is shown in the list table of Scheduled Actions, in the Log column.

    Thread Starter elektrobank

    (@elektrobank)

    Are you saying it already stores that exception message? That’s the only missing piece in getting this working the way I need it. Which table are you referring to? I don’t see a log column in any of the wp_actionscheduler tables and it doesn’t show that message in the wp_actionscheduler_logs table.
    Thanks!

    @elektrobank In the WordPress admin: Tools > Scheduled Actions.

    Thread Starter elektrobank

    (@elektrobank)

    It shows the same message that shows up in wp_actionscheduler_logs, but it is showing a different PHP error that doesn’t include my exception message. Is there a specific type of exception I need to throw? It is going to be possible for my exception message to be displayed there in a format I can parse and display?

    Thanks

    @elektrobank In my uses I do throw new Exception( 'Exception message' ) and ‘Exception message’ shows in the Logs column as the reason for the failure.

    Perhaps better for you to indicate what it is you’re trying to do than to speak generally.

    Thread Starter elektrobank

    (@elektrobank)

    Specially I want to log the response code (complete or failed), which it already does, with an error message if it failed.

    I see where my issue is now, the exception wasn’t thrown correctly. I fixed that and now it’s logging the exception just fine, so this will work fine for my needs as is.

    I guess the only thing that would make it better is if I could add a “response” column to the wp_actionscheduler_actions table and store it there for easier access. Is there an easy way to access the “action_id” from within the hook that gets called so once it runs it’s job it can update the table with an error if it didn’t succeed?

    Thanks

    @elektrobank The first parameter passed in the action_scheduler_after_execute, action_scheduler_failed_execution, and action_scheduler_failed_validation actions is the action’s ID. You’ll probably want to use a WordPress option or transient, maybe post meta depending on what your use is. Best to leave Action Scheduler’s tables alone.

    Thread Starter elektrobank

    (@elektrobank)

    Thanks for your help, very helpful, I got everything working the way I need it now.

    Moderator Yui

    (@fierevere)

    永子

    @crstauf

    Please do not “Report” resolved topics, ask the OP to mark topic as resolved.
    (Otherwise Plugin Support Rep. can mark topics as resolved too)

    Reporting a topic is used to draw moderator attention to guideline violations and similar issues. Resolved topics do NOT need moderator attention.

    • This reply was modified 4 years, 2 months ago by Yui.
Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘How to log the result of an action?’ is closed to new replies.