-
Notifications
You must be signed in to change notification settings - Fork 26
Closed
Description
This is more a question than an issue. Do you think an optional parameter for timeout will be beneficial?
If found this code in a legacy project I am mantaining
/**
* Keep trying a number of times until it actually saves. This is for really important tasks.
*
* @param $entity
* @param int $iterations
* @return bool
*/
public function reallySave( $entity, $iterations = 5 ) {
for( $i = 0; $i < $iterations; $i++ ) {
if( $entity->save() ) {
return TRUE;
}
//sleep for 100 milliseconds between each try. Without the delay two back to back attempts are likely to fail.
usleep( 100 * 1000 );
}
return FALSE;
}
I don't know if this is a bad practice, but I think retry could replace this.
Metadata
Metadata
Assignees
Labels
No labels