Giter VIP home page Giter VIP logo

Comments (11)

amenk avatar amenk commented on June 3, 2024

would exit(0) work :D ?

from import.

amenk avatar amenk commented on June 3, 2024

We could either introduce a new type of exception or replace
https://github.com/techdivision/import-app-simple/blob/master/src/Simple.php#L667

by

return $ase->getCode() ?? 1;

so we can throw such an exception with a custom code

from import.

amenk avatar amenk commented on June 3, 2024

Actually it might be better to introduce a new exception type, because in such cases of allowed stops, we do not need to print the full exception.

Our use case is that we have empty imports in some cases - which are okay - and we do not need to generate an artefact. That's why we simply need to stop the process.

from import.

DanieliMi avatar DanieliMi commented on June 3, 2024

I think it would be nice to be able to pass an exit code to \TechDivision\Import\ApplicationInterface::stop and we could then pass the code to \TechDivision\Import\Exceptions\ApplicationStoppedException which is used as exit code.

from import.

DanieliMi avatar DanieliMi commented on June 3, 2024

I image it something like this:
https://github.com/techdivision/import-app-simple/blob/master/src/Simple.php#L638-L668

        } catch (ApplicationStoppedException $ase) {
            // rollback the transaction, if single transaction mode has been configured
            if ($this->getConfiguration()->isSingleTransaction()) {
                $this->getImportProcessor()->getConnection()->rollBack();
            }

            // invoke the event that has to be fired after the application rollbacked the
            // transaction (if single transaction mode has been activated)
            $this->getEmitter()->emit(EventNames::APP_PROCESS_TRANSACTION_FAILURE, $this, $ase);

            // finally, if a PID has been set (because CSV files has been found),
            // remove it from the PID file to unlock the importer
            $this->unlock();

            // track the time needed for the import in seconds
            $endTime = microtime(true) - $startTime;

            // If the exit code is above 0 it's an error that we have to handle like it else it is an expected stop and we gracefully end
            if ($ase->getCode() > 0) {
                // log a message that the file import failed
                foreach ($this->systemLoggers as $systemLogger) {
                    $systemLogger->error($ase->__toString());
                }

                // log a message that import has been finished
                $this->getSystemLogger()->warning(sprintf('Can\'t finish import with serial %s in %f s', $this->getSerial(), $endTime));

                // log the exception message as warning
                $this->log($ase->getMessage(), LogLevel::WARNING);

                // return the exit code of the exception
                return $ase->getCode();
            } else {
                // log a info message that import has been finished
                $this->getSystemLogger()->info($ase->getMessage());
                $this->getSystemLogger()->info(sprintf('Execution time for operation with serial %s in %f s', $this->getSerial(), $endTime));

                // invoke the event that has to be fired before the application has the transaction
                // committed successfully (if single transaction mode has been activated)
                $this->getEmitter()->emit(EventNames::APP_PROCESS_TRANSACTION_SUCCESS, $this);
            }
        }

from import.

amenk avatar amenk commented on June 3, 2024

#211
techdivision/import-app-simple#29

from import.

amenk avatar amenk commented on June 3, 2024

Made some pull requests to have something to discuss, but we should also avoid the rollback on finish. Or we find another way to exit the app if nothing is to do, for example with a series of return statements? @DanieliMi

from import.

amenk avatar amenk commented on June 3, 2024

I think this is a better approach here - so we do not need a PR to the Pacemaker-Core

We define a new LocalFinishedException()

@DanieliMi

public function process()
{
    try {
        $this->export(time(), 1);
    } catch (LocalFinishedException $e) {
        echo $e->getMessage();
        return;
    }
}


public function getArtefacts() {

   ....

    if (empty($artefacts)) {
        throw new LocalFinishedException('Found no simple products to delete.');
    }
}

from import.

DanieliMi avatar DanieliMi commented on June 3, 2024

I don't think this will work because after this there will be following operations executed which will result in Exceptions in this case so we have to stop the whole application.

from import.

amenk avatar amenk commented on June 3, 2024

true, understood

from import.

amenk avatar amenk commented on June 3, 2024

@wagnert what do you think?

We have process chains which should be stopped if initial jobs do not produce output, but this should have a success exit-code.
Is there a better way to solve that or do you think our approach is generally feasible?

Currently we use vendor/bin/import-simple .... || true in our bash script to avoid stopping the general chain, but this also covers up other problems.

from import.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.