anchor.diff:      {noreply, NewState :: #state{}} |
       {noreply, NewState :: #state{}, timeout() | hibernate} |
       {stop, Reason :: term(), NewState :: #state{}}).
  -handle_cast(check, State = #state{ids_queue = IdsQueue, active_tasks = Active}) ->
  -    ?critical("~nQueue: ~p~nActive: ~p~n", [queue:len(IdsQueue), Active]),
  +handle_cast(check, State = #state{queue = Queue, active_tasks = Active}) ->
  +    % TODO wywalić ten clause przed końcem ticketa !!!
  +    ?critical("~nQueue: ~p~nActive: ~p~n", [queue:len(Queue), Active]),
       {noreply, State, ?DIE_AFTER};
   handle_cast(Task = #task{id = ReportId}, State = #state{
       active_tasks = ActiveTasks,
  
positive.code:             ok = handle_task(Task, SpaceId)
      end,
      {noreply, State#state{active_tasks = ActiveTasks + 1}, ?DIE_AFTER};
  handle_cast(Task = #task{id = ReportId}, State = #state{
      queues = Queues,
      ids_queue = IdsQueue
  }) ->
      % there are too many active requests, add this one to queue
      QueuePerId = maps:get(ReportId, Queues, queue:new()),
      QueuePerId2 = queue:in(Task, QueuePerId),
      {noreply, State#state{
          queues = Queues#{ReportId => QueuePerId2},
          ids_queue = queue:in(ReportId, IdsQueue)
      }, ?DIE_AFTER};
  handle_cast(?FINISHED, State = #state{
      queues = Queues,
      ids_queue = IdsQueue,
      active_tasks = ActiveTasks
  }) ->
      case queue:out(IdsQueue) of
          {empty, IdsQueue} ->
              State2 = State#state{
                  active_tasks = ActiveTasks - 1
              },
              {noreply, State2, ?DIE_AFTER};
          {{value, ReportId}, IdsQueue2} ->
              QueuePerId = maps:get(ReportId, Queues),
              {{value, Task}, QueuePerId2} = queue:out(QueuePerId),
              State2 = State#state{
                  ids_queue = IdsQueue2,
                  queues = Queues#{ReportId => QueuePerId2},
                  active_tasks = ActiveTasks - 1
              },
              handle_cast(Task, State2)
  
negative.code:     id :: replica_deletion:report_id()
  }).
  
  -type task() :: #task{}.
  -type deletion_task() :: #deletion_task{}.
  
  %%%===================================================================
  %%% API
  