Programatically updating node immediately after creation causes PDOException
Drupal provides a Lock API for this purpose - to handle when multiple processes are competing for a resource.

In your case, you need to acquire a lock and release it when finished, checking if that lock is available prior to processing from the other component.

i.e:


lock_acquire
lock_release
lock_wait


Although not directly related, you may also be interested in the Queue API for other queue based processing tasks.