title: Erlang supervisor. Restarting process, if it fails several times, give up and send message
body: <p>I have several <code>gen_server</code> workers periodically requesting some information from hardware sensors. Sensors may temporary fail, it is normal. If sensor fails worker terminates with an exception. </p>
  
  <p>All workers are spawned form supervisor with <code>simple_one_to_one</code> strategy. Also I have a control <code>gen_server</code>, which can start and stop workers and also recives <code>'DOWN'</code> messages.</p>
  
  <p>So now I have two problems:</p>
  
  <ol>
  <li><p>If worker is restarted by supervisor its state is lost, which is not acceptable to me. I need to recreate the worker with the same state.</p></li>
  <li><p>If the worker is failing several times in period of time something serious has happened with the sensors and it requires the operator's attention. Thus I need to give up restarting the worker and send a message to event handlers. But the default behaviuor of supervisor is terminate after exhaust process restart limit.</p></li>
  </ol>
  
  <p>I see two solutions:</p>
  
  <ol>
  <li><p>Set the type of the processes in the supervisor as temporary and control them and restart them in control <code>gen_server</code>. But this is exactly what supervisor should do, so I'm reinventing the wheel.</p></li>
  <li><p>Create a supervisor for each worker under the main supervisor. This exactly solves my second problem, but the state of workers is lost after restart, thus I need some storage like ets table storing the states of workers.</p></li>
  </ol>
  
  <p>I am very new to Erlang, so I need some advice to my problem, as to which (if any) solution is the best. Thanks in advance.</p>