Skip to content

Cannot unschedule more than 100 events with a given hook #125

@johnbillion

Description

@johnbillion

Deleting all events with a given hook via wp cron event unschedule <hook> or wp_unschedule_hook( <hook> ) will only delete a maximum of 100 events. If there are more than 100 events with that hook then the remainder will not be deleted and the command will need to be run multiple times.

This problem was identified on a site with a runaway process that had scheduled thousands of events with the same hook name but different parameters. Unscheduling the events only unscheduled 100 at a time.

This is caused by the \HM\Cavalcade\Plugin\Connector\pre_clear_scheduled_hook function that's hooked into pre_clear_scheduled_hook which queries for a maximum of 100 jobs.

The fix would be to either repeat this query in a loop until there are no more matches, or to remove the limit on the query, although the latter risks exhausting memory if there's an exceptionally high number of jobs with that hook.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions