elements-at / ProcessManager

Manage processes in Pimcore
Other
45 stars 31 forks source link

Odd failure: "Process died. Last State: initializing" #167

Open NiklasBr opened 1 year ago

NiklasBr commented 1 year ago

Trying to implement in a custom command, by taking inspiration from ProcessManagerSampleCommandSimple.php, what would cause this execute() method to fail like this?

   use ExecutionTrait;
   protected function execute(InputInterface $input, OutputInterface $output): int
   {
        $monitoringItem = self::initProcessManager(
            implode('|', $input->getOption(self::ARGUMENT_TYPES)),
            ['autoCreate' => true]
        );
        $monitoringItem->setStatus(MonitoringItem::STATUS_INITIALIZING);

        $types = $input->getOption(self::ARGUMENT_TYPES);

        $monitoringItem->setTotalSteps(1 + count($types))->setMessage('Starting process')->save();
        $step = 0;

        if (in_array(Category::classId(), $types, true)) {
            $monitoringItem->setMessage('Indexing categories')->setCurrentStep(++$step)->save();
            $this->output->writeln('Indexing categories');
            $categories = new Category\Listing();
            $categories->setObjectTypes([AbstractObject::OBJECT_TYPE_OBJECT, AbstractObject::OBJECT_TYPE_VARIANT]);
            $total = $categories->getTotalCount();
            for ($i = 0; $i < (ceil($total / $this->paginationCount)); $i++) {
                $categories->setLimit($this->paginationCount);
                $categories->setOffset($i * $this->paginationCount);
                $monitoringItem->setMessage("Indexing categories (offset {$categories->getOffset()} of {$total})")->setCurrentStep(++$step)->save();
                foreach ($categories->getObjects() as $category) {
                    $this->output->writeln("Indexing {$category->getFullPath()}");
                    $this->bus->dispatch(new IndexMessage($category->getId(), $category::class));
                }
                $monitoringItem->setStatus(MonitoringItem::STATUS_RUNNING);
            }
        }

        if (in_array(Product::classId(), $types, true)) {
            $monitoringItem->setMessage('Indexing products')->setCurrentStep(++$step)->save();
            $this->output->writeln('Indexing products');
            $products = new Product\Listing();
            $products->setObjectTypes([AbstractObject::OBJECT_TYPE_OBJECT, AbstractObject::OBJECT_TYPE_VARIANT]);
            $total = $products->getTotalCount();
            for ($i = 0; $i < (ceil($total / $this->paginationCount)); $i++) {
                $products->setLimit($this->paginationCount);
                $products->setOffset($i * $this->paginationCount);
                $monitoringItem->setMessage("Indexing products (offset {$products->getOffset()} of {$total})")->setCurrentStep(++$step)->save();
                foreach ($products->getObjects() as $product) {
                    $this->output->writeln("Indexing {$product->getFullPath()}");
                    $this->bus->dispatch(new IndexMessage($product->getId(), $product::class));
                }
                $monitoringItem->setStatus(MonitoringItem::STATUS_RUNNING);
            }
        }

        $monitoringItem->setMessage('Job finished')->setCompleted();

        return self::SUCCESS;
    }

Screenshot 2023-02-16 at 13 58 16

RickardAhlstedt commented 1 year ago

I'm having a similiar issue, where the process first reports as "Finished with errors" (expected in this case), but after 10-15 minutes it switches to "Failed" along with a message of "Process died. Error occurred, file has not been imported Last State: finished_with_errors".

@ctippler Could you point both of us in the right direction regarding this issue?