• Resolved 3yq9nfgnvh

    (@3yq9nfgnvh)


    I’m using the “as_get_scheduled_actions” function to get all the pending and completed tasks for a certain hook. However, that function doesn’t work for in-progress tasks it appears. Before I dive into things, is there an easy way to achieve this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support LovingBro (woo-hc)

    (@lovingbro)

    Hi @3yq9nfgnvh,

    I understand you’re trying to retrieve all actions, including those currently in progress, and it makes sense that as_get_scheduled_actions() not returning those is getting in the way. Let’s see how we can approach this.

    By default, as_get_scheduled_actions() does support querying by status, but “in-progress” actions are stored under the in-progress status and may not show up unless explicitly requested. You can try passing the status parameter like this:

    as_get_scheduled_actions( [
        'status' => ActionScheduler_Store::STATUS_RUNNING,
        'hook'   => 'your_hook_name',
    ] );
    

    Alternatively, you can also try:

    as_get_scheduled_actions( [
        'status' => 'in-progress',
        'hook'   => 'your_hook_name',
    ] );
    

    If that still does not return results, it could be due to how the data store is handling running actions, as these are sometimes transient and not always queryable in the same way as pending or completed actions.

    For more details on how Action Scheduler handles statuses and querying, you can check the documentation here: https://actionscheduler.org/api/

    If you can share what you’re seeing when trying the above, I’ll be happy to take a closer look with you and help narrow it down further.

    Thread Starter 3yq9nfgnvh

    (@3yq9nfgnvh)

    If that isn’t the most unhelpful, AI slop response I’ve ever seen then I don’t know what is. I will look into it myself.

    Plugin Support Shameem – a11n

    (@shameemreza)

    Hi @3yq9nfgnvh

    Apologies for the runaround.

    as_get_scheduled_actions() does work for in-progress actions. The query itself is straightforward, and there’s no technical limitation preventing it:

    $running = as_get_scheduled_actions( array(
    'status' => ActionScheduler_Store::STATUS_RUNNING,
    'hook' => 'your_hook_name',
    'per_page' => 100,
    ) );

    The reason you’re probably not seeing results is that actions only stay in in-progress status for the few seconds they’re actually executing. Once done, they immediately flip to complete (or failed). There’s also a cleanup process (ActionScheduler_QueueCleaner::mark_failures()) that runs every queue cycle and auto-marks any in-progress action older than 5 minutes as failed. So the window to catch one mid-flight is very small.

    If what you actually need is “all actions that haven’t finished yet” (both queued and currently executing), query both statuses at once:

    $active = as_get_scheduled_actions( array(
    'status' => array(
    ActionScheduler_Store::STATUS_PENDING,
    ActionScheduler_Store::STATUS_RUNNING,
    ),
    'hook' => 'your_hook_name',
    'per_page' => 100,
    ) );

    Or if you just need to know whether a specific hook has something pending or running, as_has_scheduled_action() already checks both statuses internally:

    if ( as_has_scheduled_action( 'your_hook_name' ) ) {
    // Something is either pending or currently running.
    }

    One other thing, the default per_page is 5. If you have more than 5 actions and aren’t setting that parameter, you’ll get an incomplete set back.

    Let me know what you’re trying to do with this, and I can point you to the most direct path.

Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.