temporalio / sdk-php

Temporal PHP SDK
https://php.preview.thundergun.io
MIT License
255 stars 44 forks source link

[Bug] Schedule API: Schedule creating without start and end time not working #383

Closed zemkogabor closed 7 months ago

zemkogabor commented 8 months ago

What are you really trying to do?

Create scheduled workflow without start and end time.

Describe the bug

If startTime and endTime not declared in Schedule spec, I got this error:

Uncaught Exception TypeError: "Given value is not an instance of Google\Protobuf\Timestamp."

Minimal Reproduction

Working code:

        $handleSubscriptionRenewal = $this->scheduleClient->createSchedule(
            Schedule::new()->withAction(
                StartWorkflowAction::new(SubscriptionRenewalWorkflow::WORKFLOW_TYPE)
                    ->withRetryPolicy(
                        RetryOptions::new()
                            ->withInitialInterval(CarbonInterval::seconds(10))
                            ->withMaximumAttempts(3)
                    )
                    ->withWorkflowId(SubscriptionRenewalWorkflow::WORKFLOW_ID)
                    ->withWorkflowRunTimeout(CarbonInterval::minute(10))
            )->withSpec(
                ScheduleSpec::new()->withAddedCronString('15 7 * * *')
                    ->withStartTime(new \DateTime('now'))
                    ->withEndTime(new \DateTime('+ 1 month'))
            ),
            scheduleId: SubscriptionRenewalWorkflow::SCHEDULE_ID,
        );

TypeError Exception:

        $handleSubscriptionRenewal = $this->scheduleClient->createSchedule(
            Schedule::new()->withAction(
                StartWorkflowAction::new(SubscriptionRenewalWorkflow::WORKFLOW_TYPE)
                    ->withRetryPolicy(
                        RetryOptions::new()
                            ->withInitialInterval(CarbonInterval::seconds(10))
                            ->withMaximumAttempts(3)
                    )
                    ->withWorkflowId(SubscriptionRenewalWorkflow::WORKFLOW_ID)
                    ->withWorkflowRunTimeout(CarbonInterval::minute(10))
            )->withSpec(
                ScheduleSpec::new()->withAddedCronString('15 7 * * *')
            ),
            scheduleId: SubscriptionRenewalWorkflow::SCHEDULE_ID,
        );

If I unset these keys in the V1/ScheduleSpec file, the schedule is successful created:

   public function __construct($data = NULL) {
        unset($data['start_time']);
        unset($data['end_time']);
        \GPBMetadata\Temporal\Api\Schedule\V1\Message::initOnce();
        parent::__construct($data);
    }

Environment/Versions

zemkogabor commented 8 months ago

I also noticed that I also get an error when listing:

Screenshot 2024-01-05 at 19 28 21

Code:

...

    public function execute(InputInterface $input, OutputInterface $output): int
    {
        $schedules = $this->scheduleClient->listSchedules();

        if (count($schedules->getPageItems()) === 0) {
            $output->writeln('<fg=red>No Schedules found</fg=red>');
            return self::FAILURE;
        }

        $rows = [];
        foreach ($schedules as $schedule) {
            $previous = count($schedule->info->recentActions) === 0
                ? null
                : $schedule->info->recentActions[array_key_last($schedule->info->recentActions)];
            $rows[] = [
                $schedule->scheduleId,
                $schedule->info->workflowType->name,
                number_format((float)$schedule->info->futureActionTimes[0]
                    ->diff(new DateTimeImmutable())->format('%s.%F'), 3) . 's',
                $previous === null
                    ? 'N/A'
                    : number_format((float)$previous->actualTime
                        ->diff(new DateTimeImmutable())->format('%s.%F'), 3) . 's',
            ];
        }

        (new Table($output))
            ->setHeaderTitle('Recent Actions')
            ->setHeaders(['ID', 'WF Type', 'Next run in', 'Last run'])
            ->setRows($rows)
            ->render();

        return self::SUCCESS;
    }

...
roxblnfk commented 8 months ago

Do you use PHP protobuf extension? Or composer package only?

zemkogabor commented 8 months ago

Yes, I use extension (no protobuf composer package). Here is part of my Dockerfile:

# Protobuf
ENV PROTOBUF_VERSION "3.25.1"
RUN pecl channel-update pecl.php.net
RUN pecl install protobuf-${PROTOBUF_VERSION} grpc \
    && docker-php-ext-enable protobuf grpc

# Roadrunner binary
# https://roadrunner.dev/docs/app-server-images/current/en
COPY --from=ghcr.io/roadrunner-server/roadrunner:2023.3.8 /usr/bin/rr /usr/local/bin/rr
RUN chmod +x /usr/local/bin/rr