• Resolved Jack

    (@jack1132132)


    Hello,

    I’ve been facing a strange issue with Action Scheduler where if I run ‘as_enqueue_async_action’ the action will run correctly and all code will be executed, however if in that action there’s code to write into any file (including debug.log) then the write will fail most of the time randomly, however the code will run to the end correctly with no errors at all.

    Take this example:

    
    //...
    as_enqueue_async_action( 'my_test_hook', ['test' => 'hello'] );
    //...
    
    //...
    add_action( 'my_test_hook', function( $args ) {
        
    	$logger = wc_get_logger();
    
    	// Write a log entry
    	$logger->debug('Your log message');
    
    	error_log('test');
    }, 10, 1 );
    //...

    In the example, in my case, the logger will log about 1/5th of the my_test_hook executions.

    Things I’ve tried;

    • Turning off caches;
    • Making sure debug is on;
    • Re-writing all functions in every way I can think of;
    • Checking file permissions;
    • Updating plugins;
    • Scouring the internet and talking to ChatGPT for solutions.

    If anyone has ANY idea about what could be causing this strange inconsistency, please share it.


    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Jack

    (@jack1132132)

    Hello,

    An update, I’ve found that this jobs only fail to write to fies when the action is executed with WP Cron instead of Async Request by Action Scheduler.
    It seems since I turned off WP Cron using define('DISABLE_WP_CRON', true); and created a custom wp-cron.php caller, the actions called with WP Cron still work but cause this strange behaviour.

    Is there any way to make use all Action Scheduler actions run using Async Request instead of WP Cron?

    Thank you.

    Thread Starter Jack

    (@jack1132132)

    I figured it out.

    I had setup to run wp-cron.php every minute with wp cron disabled in wp-config.php. And I forgot to set the user I was running wp-cron.php as to the new daemon after migrating to a new stack, so it didn’t have permission to create and edit files.

    The inconsistent behaviour was due to Action Scheduler either opting for WP CRON or using its Async Request instead randomly, Async Requests didn’t have the permission error because they were using the correct daemon to execute the jobs 

    Thank you

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘actions not writing to outputs’ is closed to new replies.