Should this be variable_set?

May want to consider using Drupals lock interface since it will timeout if something bad happens.

https://api.drupal.org/api/drupal/includes!lock.inc/group/lock/7