Repository: appwrite/appwrite
File: src/Appwrite/Platform/Tasks/ScheduleExecutions.php (PHP)

Code before:
    public static function getName(): string
    {
        return 'schedule-executions';
    }

    public static function getSupportedResource(): string
    {
        return 'execution';
    }

    protected function enqueueResources(Group $pools, Database $dbForConsole): void
    {
        foreach ($this->schedules as $schedule) {
            if (!$schedule['active'] || CronExpression::isValidExpression($schedule['schedule'])) {
                unset($this->schedules[$schedule['resourceId']]);
                continue;
            }

            $now = new \DateTime();
            $scheduledAt = new \DateTime($schedule['schedule']);

            if ($scheduledAt > $now) {
                continue;
            }

            \go(function () use ($schedule, $pools, $dbForConsole) {
                $queue = $pools->get('queue')->pop();
                $connection = $queue->getResource();

                $queueForFunctions = new Func($connection);

                $queueForFunctions
                    ->setType('schedule')
                    ->setFunctionId($schedule['resource']['functionId'])
                    ->setExecution($schedule['resource'])
                    ->setMethod('POST')
                    ->setPath('/')
                    ->setProject($schedule['project'])
                    ->trigger();

                $dbForConsole->deleteDocument(
                    'schedules',
                    $schedule['$id'],
                );

                $queue->reclaim();

                unset($this->schedules[$schedule['resourceId']]);
            });
        }
    }

Review comment (suggestion):
I think we don't need to do this in `go`. We do it for CRONs because we delay it some more with sleep. But here it's instant execution - we can do it without go.

Code after:
    {
        return 'schedule-executions';
    }

    public static function getSupportedResource(): string
    {
        return 'execution';
    }

    protected function enqueueResources(Group $pools, Database $dbForConsole): void
    {
        $queue = $pools->get('queue')->pop();
        $connection = $queue->getResource();
        $queueForFunctions = new Func($connection);

        foreach ($this->schedules as $schedule) {
            if (!$schedule['active']) {
                $dbForConsole->deleteDocument(
                    'schedules',
                    $schedule['$id'],
                );

                unset($this->schedules[$schedule['resourceId']]);
                continue;
            }

            $now = new \DateTime();
            $scheduledAt = new \DateTime($schedule['schedule']);

            if ($scheduledAt > $now) {
                continue;
            }

            $queueForFunctions
                ->setType('schedule')
                // Set functionId instead of function as we don't have $dbForProject
                // TODO: Refactor to use function instead of functionId
                ->setFunctionId($schedule['resource']['functionId'])
                ->setExecution($schedule['resource'])
                ->setMethod($schedule['data']['method'] ?? 'POST')
                ->setPath($schedule['data']['path'] ?? '/')
                ->setHeaders($schedule['data']['headers'] ?? [])
                ->setBody($schedule['data']['body'] ?? '')
                ->setProject($schedule['project'])
                ->trigger();

            $dbForConsole->deleteDocument(
                'schedules',
                $schedule['$id'],
            );