基本上,我有API提供商对50个同时作业的速率限制。举个例子,假设我必须运行500个作业:
$jobs = $this->db->get('jobs')->result_array();
(加载所有500个作业(
Bellow代码为所有500个作业循环api查询。
foreach($jobs as $job)
{
//API call
}
每个作业都有状态参数$job['status'],我想做以下操作:
为了避免滥用速率限制,我想对处于繁忙状态的行进行计数$busy = $this->db->get_where('jobs', ['status' => 'busy']->num_rows();
并且继续检查(循环(直到$busy<50
最终结果
foreach($jobs as $job)
{
//API call
//Count busy jobs
//If busy >= 50 wait(50) and check again - (I need help with this part, no idea how to do it)
//If busy < 50 continue foreach loop
}
希望所有细节都到位。
p.s。我正在使用:
CodeIgniter3,PHP7.4
编辑:
为了避免最终结果中提到的混乱(//如果忙>=50,请等待(50(并再次检查-(我需要这部分的帮助,不知道如何做到()
我正在寻找一种方法来循环$busy SQL查询,直到num_row((小于50。
找到解决方案
$busy = $this->db->get_where('jobs', ['status' => 'busy']->num_rows();
while($busy >= 50 ) {
$busy = $this->db->get_where('jobs', ['status' => 'busy']->num_rows();
}