import logging
from followthemoney import model
from servicelayer.worker import Worker

from ingestors.manager import Manager

log = logging.getLogger(__name__)


class IngestWorker(Worker):
    """A long running task runner that uses Redis as a task queue"""

    def dispatch_next(self, task, entities):
        next_stage = task.context.get('next_stage')
        if next_stage is None:
            return
        stage = task.job.get_stage(next_stage)
        log.info("Sending %s entities to: %s", len(entities), next_stage)
        for entity_id in entities:
            stage.queue({'entity_id': entity_id}, task.context)

    def handle(self, task):
        manager = Manager(task.stage, task.context)
        entity = model.get_proxy(task.payload)
        log.debug("Ingest: %r", entity)
        manager.ingest_entity(entity)
        manager.close()
        self.dispatch_next(task, manager.emitted)

@@ -526,47 +526,8 @@
 ge)%0A
-        for entity_id in entities:%0A    
     
@@ -557,16 +557,17 @@
 y_id
+s
 ': entit
 y_id
@@ -562,20 +562,19 @@
 ': entit
-y_id
+ies
 %7D, task.

Fix entity index aggregator argument error