Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP 500 error on job execution: "Typed property Configuration::$executorSettings must not be accessed before initialization" #204

Open
APochmann opened this issue Feb 27, 2024 · 2 comments

Comments

@APochmann
Copy link
Contributor

I run into this issue since migration to pimcore 11 (and therefore ProcessManager 5.x). It seems it's an issue that I do not use predefined configuration but start the job directly and fill some data in the callback function. With ProcessManager 4.x I used parameter $configId = null which gave an error in new version so I use empty string now:

        $jobResult = Helper::executeJob(
                '',                               // $configId
                [],                               // $callbackSettings = []
                $this->getPimcoreUser()->getId(), // $userId = 0
                $metadata,                        // $metaData = '[]'
                null,                             // $parentMonitoringItemId = null
                'App\Helper\ProcessHelper::processCallback');

executeJob recognizes there is no Configuration and creates a new one but with this one getExecutorClassObject fails:

    public static function executeJob(string $configId, array $callbackSettings = [], int $userId = 0, mixed $metaData = [], mixed $parentMonitoringItemId = null, ?callable $callback = null)
    {
        try {
            $config = Configuration::getById($configId);

            if(!$config instanceof \Elements\Bundle\ProcessManagerBundle\Model\Configuration) {
                $config = new Configuration();
                $config->setExecutorClass(Executor\PimcoreCommand::class);
            }

            $executor = $config->getExecutorClassObject();

getExecutorClassObject (method of Configuration class) is failing on calling setDataFromResource by passing its own instance created in executeJob:

    public function getExecutorClassObject(): AbstractExecutor
    {
        if (!isset($this->executorClassObject)) {

            $className = $this->getExecutorClass();
            $class = new $className();
            $class->setDataFromResource($this);

setDataFromResource in AbstractExecuter class tries to get Executer settings

    public function setDataFromResource(Configuration $configuration): Configuration
    {
        $settings = $configuration->getExecutorSettings();

getExecutorSettings (method of Configuration class) finally raises the exception as global variable $this->executorSettings is not initialized yet:

    public function getExecutorSettings(): string
    {
        return $this->executorSettings;
    }

I assume, having no predefined configuration is still a valid use case as executeJob handles that by creating a new Configuration instance. It just seems that this new instance is not initialized in a functional way

@APochmann
Copy link
Contributor Author

Just as a hint as it is for sure not the correct solution: If I enhance the original code

            if(!$config instanceof \Elements\Bundle\ProcessManagerBundle\Model\Configuration) {
                $config = new Configuration();
                $config->setExecutorClass(Executor\PimcoreCommand::class);
            }

in Helper::executeJob like this

            if(!$config instanceof \Elements\Bundle\ProcessManagerBundle\Model\Configuration) {
                $config = new Configuration();
                $config->setExecutorClass(Executor\PimcoreCommand::class);
                $config->setName('');
                $config->setExecutorSettings('{"values":{"group":""}}');
            }

al least my code from previous version is running again

@APochmann
Copy link
Contributor Author

Hi @ctippler, would the change described in my last comment be an acceptable fix of the issue? If so, I could create a PR. If not, do you have a better proposal to support start of jobs without predefined configurations?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant