ไม่ทราบว่าโปรเซสหลักคือ ต้องการแค่ query ตาม last_id(ID) ไปเรื่อยๆหรือเปล่าครับ
ถ้าใช่ ท่านก็แค่ทำการ log last_id(cursor) ที่โปรเซสในแต่ละรอบหลังจบโปรเซสแค่นั้นเอง
แล้วในรอบต่อไปก็แค่ดึง last_id จากรอบที่แล้วมาเช็คว่าถึงไหนแล้ว แล้วเอา last_id ตัวนี้มาเป็นเงื่อนไขในการค้นหา
รายการในรอบปัจจุบัน ถ้างานง่ายๆ ใช้ PHP file เดียว รัน cron task เดียวก็น่าจะพอนะครับ
งงมั้ย?
เช่น
- step 1. get_last_id from log txt file
- last_id = get_last_id ? get_last_id : 0
- step 2. select id,name,date from blah_tb where ID>{$last_id} and updated_at < NOW() limit {$limit}
- step 3. if no record found ? return to first? : any process you want to
- step 4. save last id when finished(from step2.) to log text file
ตัวอย่าง logfile.txt (json_encode())
{"start_id":"0","end_id":"120","processed_items":"98","last_id":"120","updated_at":"2017-06-06 11:05:33"}
^
ในรอบการ query หรือโปรเซสถัดไป ID ต้องเริ่มจาก ID ที่มากกว่า 120
อันนี้แค่ logic ง่ายๆ นะครับ สามารถนำไปประยุกต์ได้