• Resolved baggyno

    (@baggyno)


    Not sure if this is possible.
    I have an class object that has a lot of attributes.
    There is also a method that needs to evaluate the attributes and come to a result. That process is HUGE, so I need to schedule it to run in the background and wait for it to be completed.

    Problem is that I can’t get actionscheduler to run that method. It fails all the time. I use this:

    In class:

    as_enqueue_async_action( [$this, 'pair_posts'] );

    Where class is instantiated (as $color):

    $color = new ColorPost();
    add_action( 'init', '$color->pair_posts()');

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter baggyno

    (@baggyno)

    My solution would be to just export all the attributes to a function outside the object, but that feels like a simple cop-out.
    There has to be a better way.

    Thread Starter baggyno

    (@baggyno)

    I found the solution with a new day and fresh brain. ??

    For those in the future with similar issues:

    in functions/plugin file:

    function register_async(){
    add_action('init_paint_pairing', 'pair_paints');
    }
    add_action('init', register_async');

    function pair_paints(){
    $paint= new ColorPost();
    add_action( 'init', '$paint->pair_posts()');
    }


    Inside method pair_posts:

    as_enqueue_async_action( 'init_paint_pairing' );


    • This reply was modified 1 year, 9 months ago by baggyno.
    Thread Starter baggyno

    (@baggyno)

    Turns out I was wrong.

    Also there is a typo in the solution… my bad.

    Anyway, it only runs a SINGLE method. While that method has multiple other methods in use inside, it does not use them. So it is a fail.

    Seems like I have to store the attributes in wp_options and then do the job that way via a simple function.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How can I schedule method in class as as_enqueue_async_action?’ is closed to new replies.