anchor.diff:  %% Internal Function Definitions
   %% ------------------------------------------------------------------
   
  --spec schedule_build(State :: record()) -> {ok, NewState :: record()}.
  -schedule_build(State) when State#state.next_to_build == none ->
  -    get_build_candidate(State);
  -schedule_build(State) ->
  -    {ok, State}.
  -
  --spec get_build_candidate(State :: record()) -> {ok, NewState :: record()}.
  -get_build_candidate(State) ->
  -    case {
  -            queue:is_empty(State#state.wait_queue),
  -            queue:is_empty(State#state.main_queue)} of
  -        {true, true} ->
  -            {ok, State};
  -        _Other -> %%TODO
  +%% Build section
  +%% ------------------------------------------------------------------
  +
  +-spec try_build(State :: record()) -> {ok, NewState :: record()}.
  +try_build(State) ->
  +    case number_free_workers(State) of
  +        Int when Int > 0 ->
  +            job_free_worker(State);
  +        _Other ->
               {ok, State}
       end.
   
  +-spec job_free_worker(State :: record()) -> {ok, NewState :: record()}.
  +job_free_worker(State) ->
  +    NewWorkers = job_free_worker(
  +        State#state.workers, State#state.next_to_build),
  +    {ok, State#state{workers=NewWorkers}}.
  +
  +job_free_worker([{Pid, none}|Other], ToBuild) ->
  +    gen_server:cast(Pid, {build, ToBuild}),
  +    [{Pid, ToBuild}|Other];
  +job_free_worker([{Pid, SomeRef}|Other], ToBuild) ->
  +    job_free_worker(Other, ToBuild, [{Pid, SomeRef}]).
  +
  +job_free_worker([{Pid, none}|Other], ToBuild, OldW) ->
  +    gen_server:cast(Pid, {build, ToBuild}),
  +    [{Pid, ToBuild}|Other] ++ OldW;
  +job_free_worker([{Pid, SomeRef}|Other], ToBuild, OldW) ->
  +    job_free_worker(Other, ToBuild, [{Pid, SomeRef}|OldW]).
  +    
   -spec create_workers(WorkerNumber :: non_neg_integer()) -> 
       {ok, [{Pid :: pid(), none}]}.
   create_workers(WorkerNumber) ->
  
positive.code: %% ------------------------------------------------------------------
  
  init(Settings) ->
      VCSPlugins = ?GV(vcs_plugin, Settings),
      Plugins = lists:map(fun({Plugin, PluginSettings}) -> 
                  {ok, Pid} = Plugin:start(PluginSettings),
                  Pid end, VCSPlugins),
      Unpack = ?GV(unpack_dir, Settings),
      Stats = dets:open_file(
          ?GV(stats, Settings, "/var/lib/smprc/caterpillar/stats")),
      BuildQueue = queue:new(),
      WaitQueue = queue:new(),
      WorkerList = create_workers(?GV(build_workers_number, Settings, 5)),
      {ok, #state{
              plugins=Plugins,
              stats=Stats,
              unpack_dir=Unpack,
              main_queue=BuildQueue,
              wait_queue=WaitQueue,
  
negative.code:     }).
  
  -type rev_def() :: {atom(), atom(), list()}.
  -type plugin_def() :: {PluginName :: atom(), PluginArguments :: [term()]}.
  
  %% ------------------------------------------------------------------
  %% API Function Exports
  