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●  ...
When can batch API be useful?●   designed to integrate with the Form API    workflow●   can be used by non-Form API script...
Functions●   batch_get()●   batch_process()●   batch_set()●   hook_batch_alter()●   _batch_populate_queue()●   _batch_queu...
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 ne...
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?
Upcoming SlideShare
Loading in …5
×

Drupal course - batch API

0 views
556 views

Published on

Published in: Education
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
0
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Drupal course - batch API

  1. 1. Batch API Dániel Kalmár March 28, 2013
  2. 2. What is batch API?
  3. 3. 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
  4. 4. 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)
  5. 5. Functions● batch_get()● batch_process()● batch_set()● hook_batch_alter()● _batch_populate_queue()● _batch_queue()
  6. 6. How does it work?
  7. 7. Configuration
  8. 8. Process● set batch operation● execute batch operation (only need outside of a form submit handler)
  9. 9. Operations● $context● Set the starting values
  10. 10. Operations● update the values in each steps
  11. 11. Operations● check if all the steps have been executed
  12. 12. Operations
  13. 13. “Finished” callback
  14. 14. Cron queue
  15. 15. What is cron queue?● cron● hooks● queue API● limit the processing time of a queue per cron run
  16. 16. When can cron queue be useful?● processing large amounts of data in cron● bulk operations (nodes, users)● regular newsletter sending
  17. 17. How does it work?
  18. 18. Define a queue● Implement hook_cron_queue_info()
  19. 19. Load the queue● Loading items in the queue in hook_cron()
  20. 20. Process a queue item● worker callback deals with the individual queue items
  21. 21. Questions?

×