Batch API Dániel Kalmár March 28, 2013
What is batch API?
What is batch API? ● Batch (execution of a series of “jobs”) ● Application Programming Interface ● Avoid PHP timeout ● Spread out the processing over several page requests ● Feedback for users (progress bar) ● Cannot use in cron jobs
When can batch API be useful? ● designed to integrate with the Form API workflow ● can be used by non-Form API scripts (update, page callbacks) ● site install (module install) ● bulk operations (nodes, users) ● search API (indexing)
Functions ● batch_get() ● batch_process() ● batch_set() ● hook_batch_alter() ● _batch_populate_queue() ● _batch_queue()
How does it work?
Configuration
Process ● set batch operation ● execute batch operation (only need outside of a form submit handler)
Operations ● $context ● Set the starting values
Operations ● update the values in each steps
Operations ● check if all the steps have been executed
Operations
“Finished” callback
Cron queue
What is cron queue? ● cron ● hooks ● queue API ● limit the processing time of a queue per cron run
When can cron queue be useful? ● processing large amounts of data in cron ● bulk operations (nodes, users) ● regular newsletter sending
How does it work?
Define a queue ● Implement hook_cron_queue_info()
Load the queue ● Loading items in the queue in hook_cron()
Process a queue item ● worker callback deals with the individual queue items
Questions?

Drupal course - batch API

  • 1.
    Batch API DánielKalmár March 28, 2013
  • 2.
  • 3.
    What is batchAPI? ● Batch (execution of a series of “jobs”) ● Application Programming Interface ● Avoid PHP timeout ● Spread out the processing over several page requests ● Feedback for users (progress bar) ● Cannot use in cron jobs
  • 4.
    When can batchAPI be useful? ● designed to integrate with the Form API workflow ● can be used by non-Form API scripts (update, page callbacks) ● site install (module install) ● bulk operations (nodes, users) ● search API (indexing)
  • 5.
    Functions ● batch_get() ● batch_process() ● batch_set() ● hook_batch_alter() ● _batch_populate_queue() ● _batch_queue()
  • 6.
  • 7.
  • 8.
    Process ● set batch operation ● execute batch operation (only need outside of a form submit handler)
  • 9.
    Operations ● $context ● Set the starting values
  • 10.
    Operations ● update the values in each steps
  • 11.
    Operations ● check if all the steps have been executed
  • 12.
  • 13.
  • 14.
  • 15.
    What is cronqueue? ● cron ● hooks ● queue API ● limit the processing time of a queue per cron run
  • 16.
    When can cronqueue be useful? ● processing large amounts of data in cron ● bulk operations (nodes, users) ● regular newsletter sending
  • 17.
  • 18.
    Define a queue ● Implement hook_cron_queue_info()
  • 19.
    Load the queue ● Loading items in the queue in hook_cron()
  • 20.
    Process a queueitem ● worker callback deals with the individual queue items
  • 21.