Skip to content

Commit 07d45f8

Browse files
committed
factor out reverse index
1 parent ef40ad6 commit 07d45f8

13 files changed

Lines changed: 220 additions & 407 deletions

File tree

golem-common/src/base_model/mod.rs

Lines changed: 0 additions & 220 deletions
Original file line numberDiff line numberDiff line change
@@ -797,226 +797,6 @@ impl FromStr for ScanCursor {
797797
Err("Invalid cursor, must have 'layer/cursor' format".to_string())
798798
}
799799
}
800-
<<<<<<< HEAD
801-
||||||| parent of f66678cfc (further cleanups)
802-
}
803-
804-
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoValue, FromValue)]
805-
#[cfg_attr(feature = "full", derive(poem_openapi::Object))]
806-
#[cfg_attr(feature = "full", oai(rename_all = "camelCase"))]
807-
#[serde(rename_all = "camelCase")]
808-
#[wit(name = "queued-card-event-card", owner = "golem:api@1.5.0/oplog")]
809-
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
810-
#[cfg_attr(feature = "full", desert(evolution()))]
811-
pub struct QueuedCardEventCard {
812-
pub card_id: CardId,
813-
#[cfg_attr(feature = "full", oai(skip))]
814-
pub card: Option<StoredCard>,
815-
}
816-
817-
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoValue, FromValue)]
818-
#[cfg_attr(feature = "full", derive(poem_openapi::Object))]
819-
#[cfg_attr(feature = "full", oai(rename_all = "camelCase"))]
820-
#[serde(rename_all = "camelCase")]
821-
#[wit(
822-
name = "public-queued-card-event-card",
823-
owner = "golem:api@1.5.0/oplog"
824-
)]
825-
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
826-
#[cfg_attr(feature = "full", desert(evolution()))]
827-
pub struct PublicQueuedCardEventCard {
828-
pub card_id: CardId,
829-
}
830-
831-
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoValue, FromValue)]
832-
#[cfg_attr(feature = "full", derive(poem_openapi::Union))]
833-
#[cfg_attr(feature = "full", oai(discriminator_name = "type", one_of = true))]
834-
#[serde(tag = "type")]
835-
#[wit(name = "queued-card-event", owner = "golem:api@1.5.0/oplog")]
836-
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
837-
#[cfg_attr(feature = "full", desert(evolution()))]
838-
pub enum QueuedCardEvent {
839-
Install(QueuedCardEventCard),
840-
Revoke(QueuedCardEventCard),
841-
}
842-
843-
impl QueuedCardEvent {
844-
pub fn card_id(&self) -> CardId {
845-
match self {
846-
Self::Install(event) | Self::Revoke(event) => event.card_id,
847-
}
848-
}
849-
850-
pub fn install(card: impl Into<StoredCard>) -> Self {
851-
let card = card.into();
852-
Self::Install(QueuedCardEventCard {
853-
card_id: card.card_id(),
854-
card: Some(card),
855-
})
856-
}
857-
858-
pub fn revoke(card_id: CardId) -> Self {
859-
Self::Revoke(QueuedCardEventCard {
860-
card_id,
861-
card: None,
862-
})
863-
}
864-
}
865-
866-
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoValue, FromValue)]
867-
#[cfg_attr(feature = "full", derive(poem_openapi::Union))]
868-
#[cfg_attr(feature = "full", oai(discriminator_name = "type", one_of = true))]
869-
#[serde(tag = "type")]
870-
#[wit(name = "public-queued-card-event", owner = "golem:api@1.5.0/oplog")]
871-
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
872-
#[cfg_attr(feature = "full", desert(evolution()))]
873-
pub enum PublicQueuedCardEvent {
874-
Install(PublicQueuedCardEventCard),
875-
Revoke(PublicQueuedCardEventCard),
876-
}
877-
878-
impl PublicQueuedCardEvent {
879-
pub fn card_id(&self) -> CardId {
880-
match self {
881-
Self::Install(event) | Self::Revoke(event) => event.card_id,
882-
}
883-
}
884-
}
885-
886-
impl From<QueuedCardEvent> for PublicQueuedCardEvent {
887-
fn from(value: QueuedCardEvent) -> Self {
888-
match value {
889-
QueuedCardEvent::Install(event) => Self::Install(PublicQueuedCardEventCard {
890-
card_id: event.card_id,
891-
}),
892-
QueuedCardEvent::Revoke(event) => Self::Revoke(PublicQueuedCardEventCard {
893-
card_id: event.card_id,
894-
}),
895-
}
896-
}
897-
}
898-
899-
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, IntoValue, FromValue)]
900-
#[cfg_attr(feature = "full", derive(poem_openapi::Enum))]
901-
#[serde(rename_all = "camelCase")]
902-
#[wit(name = "card-install-failure", owner = "golem:api@1.5.0/oplog")]
903-
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
904-
#[cfg_attr(feature = "full", desert(evolution()))]
905-
pub enum CardInstallFailure {
906-
CardRevoked,
907-
NotFound,
908-
RecipientMismatch,
909-
NotPermitted,
910-
=======
911-
}
912-
913-
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoValue, FromValue)]
914-
#[cfg_attr(feature = "full", derive(poem_openapi::Object))]
915-
#[cfg_attr(feature = "full", oai(rename_all = "camelCase"))]
916-
#[serde(rename_all = "camelCase")]
917-
#[wit(name = "queued-card-event-card", owner = "golem:api@1.5.0/oplog")]
918-
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
919-
#[cfg_attr(feature = "full", desert(evolution()))]
920-
pub struct QueuedCardEventCard {
921-
pub card_id: CardId,
922-
#[cfg_attr(feature = "full", oai(skip))]
923-
pub card: Option<StoredCard>,
924-
}
925-
926-
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoValue, FromValue)]
927-
#[cfg_attr(feature = "full", derive(poem_openapi::Object))]
928-
#[cfg_attr(feature = "full", oai(rename_all = "camelCase"))]
929-
#[serde(rename_all = "camelCase")]
930-
#[wit(
931-
name = "public-queued-card-event-card",
932-
owner = "golem:api@1.5.0/oplog"
933-
)]
934-
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
935-
#[cfg_attr(feature = "full", desert(evolution()))]
936-
pub struct PublicQueuedCardEventCard {
937-
pub card_id: CardId,
938-
}
939-
940-
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoValue, FromValue)]
941-
#[cfg_attr(feature = "full", derive(poem_openapi::Union))]
942-
#[cfg_attr(feature = "full", oai(discriminator_name = "type", one_of = true))]
943-
#[serde(tag = "type")]
944-
#[wit(name = "queued-card-event", owner = "golem:api@1.5.0/oplog")]
945-
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
946-
#[cfg_attr(feature = "full", desert(evolution()))]
947-
pub enum QueuedCardEvent {
948-
Install(QueuedCardEventCard),
949-
Revoke(QueuedCardEventCard),
950-
}
951-
952-
impl QueuedCardEvent {
953-
pub fn card_id(&self) -> CardId {
954-
match self {
955-
Self::Install(event) | Self::Revoke(event) => event.card_id,
956-
}
957-
}
958-
959-
pub fn install(card: impl Into<StoredCard>) -> Self {
960-
let card = card.into();
961-
Self::Install(QueuedCardEventCard {
962-
card_id: card.card_id(),
963-
card: Some(card),
964-
})
965-
}
966-
967-
pub fn revoke(card_id: CardId) -> Self {
968-
Self::Revoke(QueuedCardEventCard {
969-
card_id,
970-
card: None,
971-
})
972-
}
973-
}
974-
975-
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, IntoValue, FromValue)]
976-
#[cfg_attr(feature = "full", derive(poem_openapi::Union))]
977-
#[cfg_attr(feature = "full", oai(discriminator_name = "type", one_of = true))]
978-
#[serde(tag = "type")]
979-
#[wit(name = "public-queued-card-event", owner = "golem:api@1.5.0/oplog")]
980-
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
981-
#[cfg_attr(feature = "full", desert(evolution()))]
982-
pub enum PublicQueuedCardEvent {
983-
Install(PublicQueuedCardEventCard),
984-
Revoke(PublicQueuedCardEventCard),
985-
}
986-
987-
impl PublicQueuedCardEvent {
988-
pub fn card_id(&self) -> CardId {
989-
match self {
990-
Self::Install(event) | Self::Revoke(event) => event.card_id,
991-
}
992-
}
993-
}
994-
995-
impl From<QueuedCardEvent> for PublicQueuedCardEvent {
996-
fn from(value: QueuedCardEvent) -> Self {
997-
match value {
998-
QueuedCardEvent::Install(event) => Self::Install(PublicQueuedCardEventCard {
999-
card_id: event.card_id,
1000-
}),
1001-
QueuedCardEvent::Revoke(event) => Self::Revoke(PublicQueuedCardEventCard {
1002-
card_id: event.card_id,
1003-
}),
1004-
}
1005-
}
1006-
}
1007-
1008-
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, IntoValue, FromValue)]
1009-
#[cfg_attr(feature = "full", derive(poem_openapi::Enum))]
1010-
#[serde(rename_all = "camelCase")]
1011-
#[wit(name = "card-install-failure", owner = "golem:api@1.5.0/oplog")]
1012-
#[cfg_attr(feature = "full", derive(desert_rust::BinaryCodec))]
1013-
#[cfg_attr(feature = "full", desert(evolution()))]
1014-
pub enum CardInstallFailure {
1015-
CardRevoked,
1016-
NotFound,
1017-
RecipientMismatch,
1018-
NotPermitted,
1019-
>>>>>>> f66678cfc (further cleanups)
1020800
}
1021801

1022802
#[cfg(feature = "full")]

golem-debugging-service/src/debug_context.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ use golem_worker_executor::services::agent_types::AgentTypesService;
5050
use golem_worker_executor::services::agent_webhooks::AgentWebhooksService;
5151
use golem_worker_executor::services::blob_store::BlobStoreService;
5252
use golem_worker_executor::services::card::CardService;
53+
use golem_worker_executor::services::card_interest::CardInterestIndex;
5354
use golem_worker_executor::services::component::ComponentService;
5455
use golem_worker_executor::services::environment_state::EnvironmentStateService;
5556
use golem_worker_executor::services::file_loader::FileLoader;
@@ -564,6 +565,7 @@ impl WorkerCtx for DebugContext {
564565
rpc: Arc<dyn Rpc>,
565566
worker_proxy: Arc<dyn WorkerProxy>,
566567
card_service: Arc<dyn CardService>,
568+
card_interest_index: Arc<CardInterestIndex>,
567569
component_service: Arc<dyn ComponentService>,
568570
_extra_deps: Self::ExtraDeps,
569571
config: Arc<GolemConfig>,
@@ -607,6 +609,7 @@ impl WorkerCtx for DebugContext {
607609
rpc,
608610
worker_proxy,
609611
card_service,
612+
card_interest_index,
610613
component_service,
611614
account_resource_limits,
612615
config,

golem-worker-executor-test-utils/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ use golem_worker_executor::services::blob_store::{
9090
BlobStoreError, BlobStoreService, DefaultBlobStoreService,
9191
};
9292
use golem_worker_executor::services::card::{CardService, NoopCardService};
93+
use golem_worker_executor::services::card_interest::CardInterestIndex;
9394
use golem_worker_executor::services::component::ComponentService;
9495
use golem_worker_executor::services::direct_invocation_auth::{
9596
DirectInvocationAuthService, NoOpDirectInvocationAuthService,
@@ -1484,6 +1485,7 @@ impl WorkerCtx for TestWorkerCtx {
14841485
rpc: Arc<dyn Rpc>,
14851486
worker_proxy: Arc<dyn WorkerProxy>,
14861487
card_service: Arc<dyn CardService>,
1488+
card_interest_index: Arc<CardInterestIndex>,
14871489
component_service: Arc<dyn ComponentService>,
14881490
extra_deps: Self::ExtraDeps,
14891491
config: Arc<GolemConfig>,
@@ -1537,6 +1539,7 @@ impl WorkerCtx for TestWorkerCtx {
15371539
rpc,
15381540
worker_proxy,
15391541
card_service,
1542+
card_interest_index,
15401543
component_service,
15411544
account_resource_limits,
15421545
config,
@@ -1851,7 +1854,6 @@ impl Bootstrap<TestWorkerCtx> for TestServerBootstrap {
18511854
fn create_active_workers(
18521855
&self,
18531856
golem_config: &GolemConfig,
1854-
card_service: Arc<dyn CardService>,
18551857
shutdown_token: tokio_util::sync::CancellationToken,
18561858
) -> Arc<ActiveWorkers<TestWorkerCtx>> {
18571859
// The in-process test harness shares its process (and RSS) with the test
@@ -1868,14 +1870,12 @@ impl Bootstrap<TestWorkerCtx> for TestServerBootstrap {
18681870
&golem_config.memory,
18691871
&golem_config.filesystem_storage,
18701872
&golem_config.agent_status_flush,
1871-
card_service,
18721873
shutdown_token,
18731874
)),
18741875
None => Arc::new(ActiveWorkers::new(
18751876
&golem_config.memory,
18761877
&golem_config.filesystem_storage,
18771878
&golem_config.agent_status_flush,
1878-
card_service,
18791879
shutdown_token,
18801880
)),
18811881
}

golem-worker-executor/src/durable_host/mod.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ use crate::services::agent_types::AgentTypesService;
5252
use crate::services::agent_webhooks::AgentWebhooksService;
5353
use crate::services::blob_store::BlobStoreService;
5454
use crate::services::card::{CardService, CardState};
55+
use crate::services::card_interest::CardInterestIndex;
5556
use crate::services::component::ComponentService;
5657
use crate::services::environment_state::EnvironmentStateService;
5758
use crate::services::file_loader::{FileLoader, FileUseToken};
@@ -390,6 +391,7 @@ impl<Ctx: WorkerCtx> DurableWorkerCtx<Ctx> {
390391
rpc: Arc<dyn Rpc>,
391392
worker_proxy: Arc<dyn WorkerProxy>,
392393
card_service: Arc<dyn CardService>,
394+
card_interest_index: Arc<CardInterestIndex>,
393395
component_service: Arc<dyn ComponentService>,
394396
resource_limits: Arc<AtomicResourceEntry>,
395397
config: Arc<GolemConfig>,
@@ -556,6 +558,7 @@ impl<Ctx: WorkerCtx> DurableWorkerCtx<Ctx> {
556558
rdbms_service,
557559
quota_service,
558560
card_service,
561+
card_interest_index,
559562
component_service,
560563
agent_types_service,
561564
environment_state_service,
@@ -769,7 +772,7 @@ impl<Ctx: WorkerCtx> DurableWorkerCtx<Ctx> {
769772
candidate_wallet_card_ids.push(card_id);
770773
}
771774
self.state
772-
.card_service
775+
.card_interest_index
773776
.set_card_interest(self.owned_agent_id.clone(), &candidate_wallet_card_ids)
774777
.await;
775778

@@ -788,7 +791,7 @@ impl<Ctx: WorkerCtx> DurableWorkerCtx<Ctx> {
788791
.copied()
789792
.collect::<Vec<_>>();
790793
self.state
791-
.card_service
794+
.card_interest_index
792795
.set_card_interest(self.owned_agent_id.clone(), &wallet_card_ids)
793796
.await;
794797

@@ -818,7 +821,7 @@ impl<Ctx: WorkerCtx> DurableWorkerCtx<Ctx> {
818821
.copied()
819822
.collect::<Vec<_>>();
820823
self.state
821-
.card_service
824+
.card_interest_index
822825
.set_card_interest(self.owned_agent_id.clone(), &wallet_card_ids)
823826
.await;
824827

@@ -850,7 +853,7 @@ impl<Ctx: WorkerCtx> DurableWorkerCtx<Ctx> {
850853
.copied()
851854
.collect::<Vec<_>>();
852855
self.state
853-
.card_service
856+
.card_interest_index
854857
.set_card_interest(self.owned_agent_id.clone(), &wallet_card_ids)
855858
.await;
856859

@@ -2671,7 +2674,7 @@ impl<Ctx: WorkerCtx> DurableWorkerCtx<Ctx> {
26712674
.copied()
26722675
.collect::<Vec<_>>();
26732676
self.state
2674-
.card_service
2677+
.card_interest_index
26752678
.set_card_interest(self.owned_agent_id.clone(), &wallet_card_ids)
26762679
.await;
26772680

@@ -4654,6 +4657,7 @@ struct PrivateDurableWorkerState {
46544657
rdbms_service: Arc<dyn RdbmsService>,
46554658
quota_service: Arc<dyn QuotaService>,
46564659
card_service: Arc<dyn CardService>,
4660+
card_interest_index: Arc<CardInterestIndex>,
46574661
component_service: Arc<dyn ComponentService>,
46584662
agent_types_service: Arc<dyn AgentTypesService>,
46594663
agent_webhooks_service: Arc<AgentWebhooksService>,
@@ -4837,6 +4841,7 @@ impl PrivateDurableWorkerState {
48374841
rdbms_service: Arc<dyn RdbmsService>,
48384842
quota_service: Arc<dyn QuotaService>,
48394843
card_service: Arc<dyn CardService>,
4844+
card_interest_index: Arc<CardInterestIndex>,
48404845
component_service: Arc<dyn ComponentService>,
48414846
agent_types_service: Arc<dyn AgentTypesService>,
48424847
environment_state_service: Arc<dyn EnvironmentStateService>,
@@ -4907,6 +4912,7 @@ impl PrivateDurableWorkerState {
49074912
rdbms_service,
49084913
quota_service,
49094914
card_service,
4915+
card_interest_index,
49104916
component_service,
49114917
agent_types_service,
49124918
environment_state_service,

0 commit comments

Comments
 (0)