def worker_state=(state)

      raise RuntimeError.new(
        "'worker_state_enabled' is not set, cannot change state"
      ) unless @context['worker_state_enabled']

      state = state.to_s

      raise ArgumentError.new(
        "#{state.inspect} not in #{WORKER_STATES.inspect}"
      ) unless WORKER_STATES.include?(state)

      doc =
        @context.storage.get('variables', 'worker') ||
        { 'type' => 'variables', '_id' => 'worker', 'state' => 'running' }

      doc['state'] = state

      @context.storage.put(doc) && worker_state=(state)
    end
def worker_state=(state)

      raise RuntimeError.new(
        "'worker_state_enabled' is not set, cannot change state"
      ) unless @context['worker_state_enabled']

      state = state.to_s

      raise ArgumentError.new(
        "#{state.inspect} not in #{WORKER_STATES.inspect}"
      ) unless WORKER_STATES.include?(state)

      doc =
        @context.storage.get('variables', 'worker') ||
        { 'type' => 'variables', '_id' => 'worker', 'state' => 'running' }

      doc['state'] = state

      @context.storage.put(doc) && worker_state=(state)
    end
Sets the [desired] worker state. The workers will check that target
 state at their next beat and switch to it.

 Setting the state to 'stopped' will force the workers to stop as soon
 as they notice the new state.

 Setting the state to 'paused' will force the workers to pause. They
 will not process msgs until the state is set back to 'running'.

 By default the [engine] option 'worker_state_enabled' is not set, so
 calling this method will result in a error, unless 'worker_state_enabled'
 was set to true when the storage was initialized.