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

플러그인 상에서 커맨드를 실행하는 scedule을 생성해주고, 크론으로 schedule 실행시 커맨드가 두번 실행되는 이슈 #1511

Open
bingle625 opened this issue Oct 30, 2023 · 0 comments
Assignees
Labels

Comments

@bingle625
Copy link

현재, 스케쥴로 특정 커맨드 실행시 두번씩 실행이 되는 이슈가 있어 살펴보니, Kernel에서 scheduledPlugins 프로퍼티에 똑같은 플러그인이 두번 등록되는 이슈가 있었습니다.
코드상 $this->scheduledPlugins 에 plugin을 넣어주는 메서드인 registerPluginMethods 에서 플러그인을 등록해주는데, 해당 메서드가 스케쥴 등록과, 커맨드 등록시에 한번씩 총 두번 실행되며 중복적으로 같은 plugin이 array에 적재되어, 스케쥴을 통해 커맨드 실행시 커맨드가 두번 실행되는 현상으로 보입니다.

 /**
     * Define the application's command schedule.
     *
     * @param Schedule $schedule Schedule instance
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        $this->registerPluginMethods();

        /**
        ** working with cron
        ** register crontab -e : * * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
        **/
        // plugin list in site
        foreach($this->scheduledPlugins as $siteKey => $plugins) {
            foreach($plugins as $pluginObj) {
                try {
                    $pluginObj->schedule($schedule, $siteKey);
                } catch (\Exception $e) {
                    Log::info(sprintf('Failed Schedule Working in %s site.\n%s:%s\n%s\n%s',$siteKey,$e->getFile(),$e->getLine(),$e->getMessage(),$e->getCode()));
                }
            }
        }
    }
/**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->registerPluginMethods();
        require base_path('routes/console.php');
    }

이를 해결하기 위해, 아래와 같이 registerPluginMethods 메서드를 통해 scheduledPlugins에 특정 plugin을 적재하기 전에, 해당 플러그인이 적재되어있는지 확인 후 적재하도록 수정하려고 합니다.

[이슈 작성 시점 코드]

if (method_exists($pluginObj, 'schedule')) {

[변경 코드]

                        //register schedule method of plugin
                        //커맨드라인에서 URL없이 접속하기때문에, 사이트키 구분을 위해 해당 플러그인이 활성화된 사이트의 config에 붙어있는 site_key를 활용
                        if (method_exists($pluginObj, 'schedule')) {
                            if(array_get($this->scheduledPlugins, $config->site_key) == null) {
                                $this->scheduledPlugins[$config->site_key] = [];
                            }
                            $array = $this->scheduledPlugins[$config->site_key];
                            if (!in_array($pluginObj, $array)) {
                                $this->scheduledPlugins[$config->site_key][] = $pluginObj;
                            }
                        }
@bingle625 bingle625 self-assigned this Oct 30, 2023
bingle625 added a commit that referenced this issue Mar 20, 2024
…되는 이슈 (#1516)

* #1511 플러그인 상에서 커맨드를 실행하는 scedule을 생성해주고, 크론으로 schedule 실행시 커맨드가 두번 실행되는 이슈

* MODIFY: scheduledPlugins 할당 코드 변경
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant