Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/build-cli.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,6 @@ jobs:
dphp exec tests/PerformanceTests/PerformanceClient.php
echo "Running fan out/in test"
dphp exec tests/PerformanceTests/FanOutFanInClient.php
echo "Running seq test"
dphp exec tests/PerformanceTests/SequenceClient.php
- uses: peter-evans/find-comment@v3
continue-on-error: true
id: fc
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ RUN install-php-extensions @composer apcu bcmath bz2 calendar ctype curl dom exi
FROM common AS builder

COPY --from=golang-base /usr/local/go /usr/local/go
ENV PATH /usr/local/go/bin:$PATH
ENV PATH=/usr/local/go/bin:$PATH

RUN apt-get update && \
apt-get -y --no-install-recommends install \
Expand Down
1 change: 1 addition & 0 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ func main() {
WithOption(cli.NewOption("no-api", "Disable the api server").WithType(cli.TypeBool)).
WithOption(cli.NewOption("verbose", "Enable info level logging").WithType(cli.TypeBool)).
WithOption(cli.NewOption("debug", "Enable debug logging").WithType(cli.TypeBool)).
WithOption(cli.NewOption("typesense-url", "The url to the typesense server").WithType(cli.TypeString)).
WithCommand(run).
WithCommand(initCmd).
WithCommand(version).
Expand Down
3 changes: 3 additions & 0 deletions cli/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ func ApplyOptions(config *Config, options map[string]string) (*Config, error) {
config.Nat.Url = options["nats-server"]
config.Nat.Internal = false
}
if options["typesense-url"] != "" {
config.Extensions.Search.Url = options["typesense-url"]
}
if options["bootstrap"] != "" {
config.Bootstrap = options["bootstrap"]
}
Expand Down
7 changes: 7 additions & 0 deletions cli/glue/glue.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"net/url"
"os"
"path/filepath"
"strings"
"sync"
)

Expand Down Expand Up @@ -98,9 +99,15 @@ func FromApiRequest(ctx context.Context, r *http.Request, function Method, logge
env := make(map[string]string)
env["FROM_REQUEST"] = "1"
env["STATE_ID"] = id.String()
remoteAddr := strings.Split(r.RemoteAddr, ":")[0]
env["REMOTE_ADDR"] = remoteAddr

msgs, responseHeaders, _, deleteAfter := glu.Execute(ctx, headers, logger, env, stream, id)

for _, msg := range msgs {
msg.Header.Add("Remote-Addr", remoteAddr)
}

return msgs, temp.Name(), nil, &responseHeaders, deleteAfter
}

Expand Down
2 changes: 1 addition & 1 deletion cli/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module durable_php

go 1.22
go 1.23

require github.com/dunglas/frankenphp v1.2.5

Expand Down
1 change: 1 addition & 0 deletions cli/lib/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ func processMsg(ctx context.Context, logger *zap.Logger, msg jetstream.Msg, js j
headers.Add("X-Correlation-ID", ctx.Value("cid").(string))
env["EVENT"] = string(msg.Data())
env["STATE_ID"] = msg.Headers().Get(string(glue.HeaderStateId))
env["REMOTE_ADDR"] = msg.Headers().Get("Remote-Addr")

msgs, headers, _, deleteAfter := glu.Execute(ctx, headers, logger, env, js, id)

Expand Down
15 changes: 10 additions & 5 deletions src/Events/EventQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@
namespace Bottledcode\DurablePhp\Events;

use Amp\DeferredCancellation;
use DateTimeImmutable;
use Revolt\EventLoop;
use SplQueue;
use Withinboredom\Time\Seconds;
use Withinboredom\Time\Time;
use Withinboredom\Time\TimeUnit;

use function Withinboredom\Time\Seconds;

class EventQueue
{
Expand Down Expand Up @@ -96,8 +101,8 @@ public function getNext(array $requeueKeys): Event|null
public function enqueue(string $key, Event $event): void
{
$delay = $this->getDelay($event);
if ($delay->inSeconds() > 0) {
EventLoop::delay($delay->inSeconds(), function () use ($key, $event): void {
if ($delay->as(TimeUnit::Seconds) > 0) {
EventLoop::delay($delay->as(TimeUnit::Seconds), function () use ($key, $event): void {
$this->enqueue($key, $event);
if ($this->cancellation !== null) {
$this->cancellation?->cancel();
Expand All @@ -116,14 +121,14 @@ public function enqueue(string $key, Event $event): void
$this->size++;
}

private function getDelay(Event $event): Seconds
private function getDelay(Event $event): Time
{
while ($event instanceof HasInnerEventInterface) {
if ($event instanceof WithDelay) {
$at = $event->fireAt->getTimestamp();
$now = (new \DateTimeImmutable())->getTimestamp();
$now = (new DateTimeImmutable())->getTimestamp();
$seconds = $at - $now;
return new Seconds(max(0, $seconds));
return Seconds(max(0, $seconds));
}

$event = $event->getInnerEvent();
Expand Down
33 changes: 20 additions & 13 deletions src/Glue/glue.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
use Ramsey\Uuid\Uuid;
use ReflectionClass;
use ReflectionFunction;
use Withinboredom\Time\TimeUnit;

require_once __DIR__ . '/autoload.php';

Expand Down Expand Up @@ -85,18 +86,21 @@ public function __construct(private DurableLogger $logger)
$this->method = $_SERVER['HTTP_DPHP_FUNCTION'];
try {
$provenance = json_decode($_SERVER['HTTP_DPHP_PROVENANCE'] ?? 'null', true, 32, JSON_THROW_ON_ERROR);
if (! $provenance || $provenance === ['userId' => '', 'roles' => null]) {
if (!$provenance || $provenance === ['userId' => '', 'roles' => null]) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder: Add tests for provenance handling.

The provenance handling logic is not covered by tests.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 89-89: src/Glue/glue.php#L89
Added line #L89 was not covered by tests

$this->provenance = null;
} else {
$provenance['roles'] ??= [];
$this->provenance = Serializer::deserialize($provenance, Provenance::class);
}
} catch (JsonException $e) {
$this->logger->alert('Failed to capture provenance', ['provenance' => $_SERVER['HTTP_DPHP_PROVENANCE'] ?? null]);
$this->logger->alert(
'Failed to capture provenance',
['provenance' => $_SERVER['HTTP_DPHP_PROVENANCE'] ?? null],
Comment on lines +96 to +98
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder: Add tests for JSON decoding error handling.

The JSON decoding error handling logic is not covered by tests.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 96-98: src/Glue/glue.php#L96-L98
Added lines #L96 - L98 were not covered by tests

);
$this->provenance = null;
}

if (! file_exists($_SERVER['HTTP_DPHP_PAYLOAD'])) {
if (!file_exists($_SERVER['HTTP_DPHP_PAYLOAD'])) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder: Add tests for payload file existence check.

The payload file existence check logic is not covered by tests.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 103-103: src/Glue/glue.php#L103
Added line #L103 was not covered by tests

throw new LogicException('Unable to load payload');
}

Expand Down Expand Up @@ -186,14 +190,20 @@ public function outputEvent(EventDescription $event): void

private function startOrchestration(): void
{
if (! $this->target->toOrchestrationInstance()->executionId) {
$this->target = StateId::fromInstance(new OrchestrationInstance($this->target->toOrchestrationInstance()->instanceId, Uuid::uuid7()->toString()));
if (!$this->target->toOrchestrationInstance()->executionId) {
$this->target = StateId::fromInstance(
new OrchestrationInstance(
$this->target->toOrchestrationInstance()->instanceId,
Uuid::uuid7()->toString(),
),
Comment on lines +193 to +198
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder: Add tests for orchestration instance creation.

The orchestration instance creation logic is not covered by tests.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 193-198: src/Glue/glue.php#L193-L198
Added lines #L193 - L198 were not covered by tests

);
}

header('X-Id: ' . $this->target->id);
$input = SerializedArray::import($this->payload['input'])->toArray();

$event = WithOrchestration::forInstance($this->target, StartExecution::asParent($input, []/* todo: scheduling */));
$event =
WithOrchestration::forInstance($this->target, StartExecution::asParent($input, []/* todo: scheduling */));
Comment on lines +205 to +206
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder: Add tests for event creation.

The event creation logic is not covered by tests.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 205-206: src/Glue/glue.php#L205-L206
Added lines #L205 - L206 were not covered by tests

$this->outputEvent(new EventDescription($event));

$actualId = $this->target->toOrchestrationInstance();
Expand Down Expand Up @@ -301,19 +311,16 @@ private function getPermissions(): void
$permissions['mode'] = 'anon';
break;
case $attribute->getName() === AllowCreateForRole::class:
/** @var AllowCreateForRole $attribute */
$attribute = $attribute->newInstance();
/** @var AllowCreateForRole $attribute */ $attribute = $attribute->newInstance();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder: Add tests for role permissions.

The role permissions logic is not covered by tests.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 314-314: src/Glue/glue.php#L314
Added line #L314 was not covered by tests

$permissions['roles'][] = $attribute->role;
break;
case $attribute->getName() === AllowCreateForUser::class:
/** @var AllowCreateForUser $attribute */
$attribute = $attribute->newInstance();
/** @var AllowCreateForUser $attribute */ $attribute = $attribute->newInstance();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder: Add tests for user permissions.

The user permissions logic is not covered by tests.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 318-318: src/Glue/glue.php#L318
Added line #L318 was not covered by tests

$permissions['users'][] = $attribute->user;
break;
case $attribute->getName() === TimeToLive::class:
/** @var TimeToLive $attribute */
$attribute = $attribute->newInstance();
$permissions['ttl'] = $attribute->timeToLive()->inNanoseconds();
/** @var TimeToLive $attribute */ $attribute = $attribute->newInstance();
$permissions['ttl'] = $attribute->timeToLive()->as(TimeUnit::Nanoseconds);
Comment on lines +322 to +323
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder: Add tests for time-to-live attribute.

The time-to-live attribute logic is not covered by tests.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 322-323: src/Glue/glue.php#L322-L323
Added lines #L322 - L323 were not covered by tests

break;
}
}
Expand Down