Skip to content

Commit dc0a5f7

Browse files
committed
fix some stuff
Signed-off-by: Robert Landers <landers.robert@gmail.com>
1 parent e88c56b commit dc0a5f7

6 files changed

Lines changed: 23 additions & 70 deletions

File tree

cli/ext/build/ext.c

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -110,29 +110,6 @@ PHP_METHOD(Bottledcode_DurablePhp_Ext_Worker, __construct) {
110110
fflush(stderr);
111111
}
112112

113-
114-
PHP_METHOD(Bottledcode_DurablePhp_Ext_Worker, startEventLoop) {
115-
ext_object *intern = ext_object_from_obj(Z_OBJ_P(ZEND_THIS));
116-
117-
VALIDATE_GO_HANDLE(intern);
118-
zend_string *kind = NULL;
119-
120-
ZEND_PARSE_PARAMETERS_START(1, 1)
121-
Z_PARAM_STR(kind)
122-
ZEND_PARSE_PARAMETERS_END();
123-
124-
startEventLoop_wrapper(intern->go_handle, kind);
125-
}
126-
127-
PHP_METHOD(Bottledcode_DurablePhp_Ext_Worker, drainEventLoop) {
128-
ext_object *intern = ext_object_from_obj(Z_OBJ_P(ZEND_THIS));
129-
130-
VALIDATE_GO_HANDLE(intern);
131-
ZEND_PARSE_PARAMETERS_NONE();
132-
133-
drainEventLoop_wrapper(intern->go_handle);
134-
}
135-
136113
PHP_METHOD(Bottledcode_DurablePhp_Ext_Worker, __destruct) {
137114
ext_object *intern = ext_object_from_obj(Z_OBJ_P(ZEND_THIS));
138115

cli/ext/build/ext.go

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type LocalMessage struct {
4545
type worker struct {
4646
requestChan chan jetstream.Msg // Channel for NATS messages
4747
localMessageChan chan *LocalMessage // Channel for local synchronous requests
48+
running bool
4849
}
4950

5051
var globalWorkerInstance *worker
@@ -366,7 +367,7 @@ func Authorize(ctx context.Context, ev *glue.EventMessage, from *ids.StateId, pr
366367
rm := auth.GetResourceManager(ctx, helpers.Js)
367368
r, err := rm.DiscoverResource(ctx, ids.ParseStateId(ev.Destination), from, helpers.Logger, preventCreation)
368369
if err != nil {
369-
helpers.Logger.Error("AUTHORIZATION FAILURE: Request blocked during resource discovery",
370+
helpers.Logger.Error("AUTHORIZATION FAILURE: Request blocked during resource discovery",
370371
zap.String("error", err.Error()),
371372
zap.String("destination", ev.Destination),
372373
zap.String("phase", "resource-discovery"),
@@ -378,7 +379,7 @@ func Authorize(ctx context.Context, ev *glue.EventMessage, from *ids.StateId, pr
378379
}
379380

380381
if !r.WantTo(operation, ctx) {
381-
helpers.Logger.Error("AUTHORIZATION FAILURE: Operation not permitted",
382+
helpers.Logger.Error("AUTHORIZATION FAILURE: Operation not permitted",
382383
zap.String("operation", string(operation)),
383384
zap.String("destination", ev.Destination),
384385
zap.String("phase", "operation-check"),
@@ -896,26 +897,6 @@ func (w *Worker) emitEvent(event *C.zval) {
896897

897898
func (w *Worker) delete() {}
898899

899-
//export startEventLoop_wrapper
900-
func startEventLoop_wrapper(handle C.uintptr_t, kind *C.zend_string) {
901-
obj := getGoObject(handle)
902-
if obj == nil {
903-
return
904-
}
905-
structObj := obj.(*Worker)
906-
structObj.startEventLoop(kind)
907-
}
908-
909-
//export drainEventLoop_wrapper
910-
func drainEventLoop_wrapper(handle C.uintptr_t) {
911-
obj := getGoObject(handle)
912-
if obj == nil {
913-
return
914-
}
915-
structObj := obj.(*Worker)
916-
structObj.drainEventLoop()
917-
}
918-
919900
//export __destruct_wrapper
920901
func __destruct_wrapper(handle C.uintptr_t) {
921902
obj := getGoObject(handle)

cli/ext/build/ext.stub.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,8 @@ public function __construct() {}
1212

1313
public static function GetCurrent(): ?Worker {}
1414

15-
public function startEventLoop(string $kind): void {}
16-
17-
public function drainEventLoop(): void {}
18-
1915
public function __destruct() {}
2016

21-
2217
public function queryState(string $stateId): array {}
2318

2419
public function getUser(): ?array {}

cli/ext/build/ext_arginfo.h

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 2cbfd4f7ba4303080cd46416ca0c29baf5b625f2 */
2+
* Stub hash: ad9b266d342856e3f582dcae9b4f25192cc52140 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_Bottledcode_DurablePhp_Ext_emit_event, 0, 3, IS_LONG, 0)
55
ZEND_ARG_TYPE_INFO(0, userContext, IS_ARRAY, 1)
@@ -13,13 +13,6 @@ ZEND_END_ARG_INFO()
1313
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Bottledcode_DurablePhp_Ext_Worker_GetCurrent, 0, 0, Bottledcode\\DurablePhp\\Ext\\Worker, 1)
1414
ZEND_END_ARG_INFO()
1515

16-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Bottledcode_DurablePhp_Ext_Worker_startEventLoop, 0, 1, IS_VOID, 0)
17-
ZEND_ARG_TYPE_INFO(0, kind, IS_STRING, 0)
18-
ZEND_END_ARG_INFO()
19-
20-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Bottledcode_DurablePhp_Ext_Worker_drainEventLoop, 0, 0, IS_VOID, 0)
21-
ZEND_END_ARG_INFO()
22-
2316
#define arginfo_class_Bottledcode_DurablePhp_Ext_Worker___destruct arginfo_class_Bottledcode_DurablePhp_Ext_Worker___construct
2417

2518
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Bottledcode_DurablePhp_Ext_Worker_queryState, 0, 1, IS_ARRAY, 0)
@@ -46,13 +39,12 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Bottledcode_DurablePhp_Ext
4639
ZEND_ARG_TYPE_INFO(0, eventDescription, IS_ARRAY, 0)
4740
ZEND_END_ARG_INFO()
4841

49-
#define arginfo_class_Bottledcode_DurablePhp_Ext_Worker_delete arginfo_class_Bottledcode_DurablePhp_Ext_Worker_drainEventLoop
42+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Bottledcode_DurablePhp_Ext_Worker_delete, 0, 0, IS_VOID, 0)
43+
ZEND_END_ARG_INFO()
5044

5145
ZEND_FUNCTION(Bottledcode_DurablePhp_Ext_emit_event);
5246
ZEND_METHOD(Bottledcode_DurablePhp_Ext_Worker, __construct);
5347
ZEND_METHOD(Bottledcode_DurablePhp_Ext_Worker, GetCurrent);
54-
ZEND_METHOD(Bottledcode_DurablePhp_Ext_Worker, startEventLoop);
55-
ZEND_METHOD(Bottledcode_DurablePhp_Ext_Worker, drainEventLoop);
5648
ZEND_METHOD(Bottledcode_DurablePhp_Ext_Worker, __destruct);
5749
ZEND_METHOD(Bottledcode_DurablePhp_Ext_Worker, queryState);
5850
ZEND_METHOD(Bottledcode_DurablePhp_Ext_Worker, getUser);
@@ -72,8 +64,6 @@ static const zend_function_entry ext_functions[] = {
7264
static const zend_function_entry class_Bottledcode_DurablePhp_Ext_Worker_methods[] = {
7365
ZEND_ME(Bottledcode_DurablePhp_Ext_Worker, __construct, arginfo_class_Bottledcode_DurablePhp_Ext_Worker___construct, ZEND_ACC_PUBLIC)
7466
ZEND_ME(Bottledcode_DurablePhp_Ext_Worker, GetCurrent, arginfo_class_Bottledcode_DurablePhp_Ext_Worker_GetCurrent, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
75-
ZEND_ME(Bottledcode_DurablePhp_Ext_Worker, startEventLoop, arginfo_class_Bottledcode_DurablePhp_Ext_Worker_startEventLoop, ZEND_ACC_PUBLIC)
76-
ZEND_ME(Bottledcode_DurablePhp_Ext_Worker, drainEventLoop, arginfo_class_Bottledcode_DurablePhp_Ext_Worker_drainEventLoop, ZEND_ACC_PUBLIC)
7767
ZEND_ME(Bottledcode_DurablePhp_Ext_Worker, __destruct, arginfo_class_Bottledcode_DurablePhp_Ext_Worker___destruct, ZEND_ACC_PUBLIC)
7868
ZEND_ME(Bottledcode_DurablePhp_Ext_Worker, queryState, arginfo_class_Bottledcode_DurablePhp_Ext_Worker_queryState, ZEND_ACC_PUBLIC)
7969
ZEND_ME(Bottledcode_DurablePhp_Ext_Worker, getUser, arginfo_class_Bottledcode_DurablePhp_Ext_Worker_getUser, ZEND_ACC_PUBLIC)

src/LocalEntityClient.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Bottledcode\DurablePhp\Events\EventDescription;
2828
use Bottledcode\DurablePhp\Events\RaiseEvent;
2929
use Bottledcode\DurablePhp\Events\Shares\Operation;
30+
use Bottledcode\DurablePhp\Events\WithDelay;
3031
use Bottledcode\DurablePhp\Events\WithEntity;
3132
use Bottledcode\DurablePhp\Glue\Provenance;
3233
use Bottledcode\DurablePhp\Proxy\SpyException;
@@ -99,9 +100,13 @@ public function signalEntity(
99100
): void {
100101
$event = WithEntity::forInstance(
101102
StateId::fromEntityId($entityId),
102-
RaiseEvent::forSignal($operationName, SerializedArray::fromArray($input), $scheduledTime),
103+
RaiseEvent::forOperation($operationName, $input),
103104
);
104105

106+
if ($scheduledTime) {
107+
$event = WithDelay::forEvent($scheduledTime, $event);
108+
}
109+
105110
$eventDescription = new EventDescription($event);
106111
$userArray = $this->userContext ? Serializer::serialize($this->userContext) : null;
107112

@@ -117,7 +122,7 @@ public function getEntitySnapshot(EntityId $entityId): ?EntityState
117122
#[Override]
118123
public function withAuth(Provenance|string|null $token): void
119124
{
120-
$this->setUserContext($token);
125+
$this->setUserContext($token instanceof Provenance ? $token : null);
121126
}
122127

123128
public function setUserContext(?Provenance $userContext): void

src/LocalOrchestrationClient.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Bottledcode\DurablePhp\Events\EventDescription;
2828
use Bottledcode\DurablePhp\Events\RaiseEvent;
2929
use Bottledcode\DurablePhp\Events\Shares\Operation;
30+
use Bottledcode\DurablePhp\Events\StartExecution;
3031
use Bottledcode\DurablePhp\Events\StartOrchestration;
3132
use Bottledcode\DurablePhp\Events\WithOrchestration;
3233
use Bottledcode\DurablePhp\Glue\Provenance;
@@ -97,20 +98,24 @@ public function resume(OrchestrationInstance $instance, string $reason): void
9798
#[Override]
9899
public function startNew(string $name, array $args = [], ?string $id = null): OrchestrationInstance
99100
{
100-
$orchestrationId = OrchestrationId($name, $id ?? Uuid::uuid4()->toString());
101-
$stateId = StateId::fromOrchestrationId($orchestrationId);
101+
$orchestrationId = \Bottledcode\DurablePhp\OrchestrationInstance($name, $id ?? Uuid::uuid4()->toString());
102+
$stateId = StateId::fromInstance($orchestrationId);
102103

103104
$event = WithOrchestration::forInstance(
104105
$stateId,
105-
StartOrchestration::fromArray(SerializedArray::fromArray($args)),
106+
StartOrchestration::forInstance($orchestrationId),
106107
);
107108

108109
$eventDescription = new EventDescription($event);
109110
$userArray = $this->userContext ? Serializer::serialize($this->userContext) : null;
110111

111112
$sequence = emit_event($userArray, $eventDescription->toArray(), $stateId->id);
112113

113-
return $orchestrationId->toOrchestrationInstance();
114+
$event = WithOrchestration::forInstance($stateId, StartExecution::asParent($args, []));
115+
$eventDescription = new EventDescription($event);
116+
emit_event($userArray, $eventDescription->toArray(), $sequence);
117+
118+
return $orchestrationId;
114119
}
115120

116121
#[Override]
@@ -134,7 +139,7 @@ public function waitForCompletion(OrchestrationInstance $instance): void
134139
#[Override]
135140
public function withAuth(Provenance|string|null $token): void
136141
{
137-
$this->setUserContext($token);
142+
$this->setUserContext($token instanceof Provenance ? $token : null);
138143
}
139144

140145
public function setUserContext(?Provenance $userContext): void

0 commit comments

Comments
 (0)