Locking a row of falcones with models

Since forUpdate still doesn't work ( https://github.com/phalcon/cphalcon/issues/2407 ) what's the best way to block SELECTed rows in the db?

I have an innodb table with items to process. I run through a cronjob some tasks that look for items to process (status=open)

, update the line with status=processing

, and then do some things. How can I protect the time between

$oModel->findFirst('status="open"');

      

and

$oModel->update(['status' => 'processing']);

      

?

+3


source to share


1 answer


You can do this by setting the parameters for_update => true.

$this->db->begin();

$oModel->findFirst( [
   'conditions' => 'status="open"',
   'for_update' => true
] );

$oModel->status = 'processing';

$oModel->update();

$this->db->commit();

      



the for_update parameter will set an exclusive lock for every row read. can also see the doc https://docs.phalconphp.com/en/latest/reference/models.html

0


source







All Articles