[wp-trac] [WordPress Trac] #63938: A feature to bulk schedule events

WordPress Trac noreply at wordpress.org
Sat Sep 6 10:06:08 UTC 2025


#63938: A feature to bulk schedule events
-----------------------------------------+------------------------------
 Reporter:  urlund                       |       Owner:  (none)
     Type:  enhancement                  |      Status:  new
 Priority:  normal                       |   Milestone:  Awaiting Review
Component:  Cron API                     |     Version:
 Severity:  normal                       |  Resolution:
 Keywords:  has-patch reporter-feedback  |     Focuses:
-----------------------------------------+------------------------------

Comment (by urlund):

 @johnbillion thanks for asking, the real life use case is a customer who
 generates reports on custom post types, and another case where a customer
 is exporting order data to an old C5 integration, both using bulk actions,
 and the ''handle_bulk_actions-{$screen}'' filter.

 Typically they submit between 100-200 items in each bulk action.

 This is how we currently handle it in the hook callback:

 {{{#!php
 <?php
 $event_args = array_map(function ($i) {
     return [$i];
 }, $items);

 // split $event_args into chunks
 $event_arg_chunks = array_chunk($event_args,
 apply_filters('generate_ticket_report_chunk_size', 10));

 // event scheduling
 foreach ($event_arg_chunks as $i => $event_args) {
     $timestamp  = time() + ($i * 60);
     foreach ($event_args as $event_arg) {
         wp_schedule_single_event($timestamp, 'generate_ticket_report',
 $event_arg);
     }
 }
 }}}

 Depending in the number of items, server load, etc. this takes around 1-2
 sec. to complete.

 If I instead change this to "bulk scheduling", like this:

 {{{#!php
 <?php
 foreach ($event_arg_chunks as $i => $event_arg_chunk) {
     $timestamp  = time() + ($i * 60);
     wp_schedule_bulk_events($timestamp, 'generate_ticket_report',
 $event_arg_chunk);
 }
 }}}

 My execution time is now around 0.1-0.3 src. instead.

 So the test case in my code from the first example was just to overstate
 my point that savings in execution time can be made using a "bulk
 transaction".

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/63938#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list