use super::error::{WasmtimePluginRuntimeError, WasmtimeWorkspaceObserveTaskEnqueueError};
use crate::plugin::{
PluginHostOwnerBatches, PluginHostOwnerDiscardReport, PluginIdentity, PluginOperationalEvent,
PluginRevocationReport, PluginWorkspaceObserveTaskCancellationReport,
PluginWorkspaceObserveTaskDiscardReport, PluginWorkspaceObserveTaskEnqueueReport,
SealedPluginEffectBatch, SealedPluginWorkspaceIoBatch,
};
use std::fmt::{Debug, Formatter};
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct WasmtimePluginRevocationCleanup {
pub(super) revocation: PluginRevocationReport,
pub(super) workspace_observe_tasks: PluginWorkspaceObserveTaskCancellationReport,
}
impl WasmtimePluginRevocationCleanup {
#[must_use]
pub fn identity(&self) -> &str {
self.revocation.identity()
}
#[must_use]
pub const fn identity_proof(&self) -> &PluginIdentity {
self.revocation.identity_proof()
}
#[must_use]
pub const fn revocation(&self) -> &PluginRevocationReport {
&self.revocation
}
#[must_use]
pub const fn workspace_observe_tasks(&self) -> &PluginWorkspaceObserveTaskCancellationReport {
&self.workspace_observe_tasks
}
#[must_use]
pub fn into_parts(self) -> WasmtimePluginRevocationCleanupParts {
WasmtimePluginRevocationCleanupParts {
revocation: self.revocation,
workspace_observe_tasks: self.workspace_observe_tasks,
}
}
}
pub struct WasmtimePluginRevocationCleanupParts {
pub revocation: PluginRevocationReport,
pub workspace_observe_tasks: PluginWorkspaceObserveTaskCancellationReport,
}
pub struct WasmtimePluginScheduledUpdate {
owner_batches: PluginHostOwnerBatches,
scheduled_workspace_observe_tasks: PluginWorkspaceObserveTaskEnqueueReport,
}
pub struct WasmtimePluginScheduledUpdateParts {
pub owner_batches: PluginHostOwnerBatches,
pub scheduled_workspace_observe_tasks: PluginWorkspaceObserveTaskEnqueueReport,
}
impl WasmtimePluginScheduledUpdate {
pub(super) fn new(
owner_batches: PluginHostOwnerBatches,
scheduled_workspace_observe_tasks: PluginWorkspaceObserveTaskEnqueueReport,
) -> Self {
assert_eq!(
owner_batches.identity_proof(),
scheduled_workspace_observe_tasks.identity_proof(),
"scheduled Wasmtime update must share one plugin identity",
);
Self {
owner_batches,
scheduled_workspace_observe_tasks,
}
}
#[must_use]
pub fn identity(&self) -> &str {
self.owner_batches.identity()
}
#[must_use]
pub const fn identity_proof(&self) -> &PluginIdentity {
self.owner_batches.identity_proof()
}
#[must_use]
pub const fn effects(&self) -> &SealedPluginEffectBatch {
self.owner_batches.effects()
}
#[must_use]
pub const fn workspace_io(&self) -> &SealedPluginWorkspaceIoBatch {
self.owner_batches.workspace_io()
}
#[must_use]
pub const fn scheduled_workspace_observe_tasks(
&self,
) -> &PluginWorkspaceObserveTaskEnqueueReport {
&self.scheduled_workspace_observe_tasks
}
#[must_use]
pub const fn owner_batches(&self) -> &PluginHostOwnerBatches {
&self.owner_batches
}
#[must_use]
pub fn into_parts(self) -> WasmtimePluginScheduledUpdateParts {
WasmtimePluginScheduledUpdateParts {
owner_batches: self.owner_batches,
scheduled_workspace_observe_tasks: self.scheduled_workspace_observe_tasks,
}
}
}
impl Debug for WasmtimePluginScheduledUpdate {
fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
formatter
.debug_struct("WasmtimePluginScheduledUpdate")
.field("identity", self.identity_proof())
.field("effect_count", &self.owner_batches.effects().effect_count())
.field(
"workspace_io_request_count",
&self.owner_batches.workspace_io().request_count(),
)
.field(
"scheduled_workspace_observe_task_count",
&self.scheduled_workspace_observe_tasks.task_count(),
)
.finish()
}
}
#[derive(thiserror::Error)]
#[error("plugin workspace observe task scheduling failed: {source}")]
pub struct WasmtimeWorkspaceObserveTaskScheduleError {
owner_batches: Box<PluginHostOwnerBatches>,
#[source]
source: Box<WasmtimeWorkspaceObserveTaskEnqueueError>,
}
pub struct WasmtimeWorkspaceObserveTaskScheduleErrorParts {
pub owner_batches: PluginHostOwnerBatches,
pub enqueue_error: WasmtimeWorkspaceObserveTaskEnqueueError,
}
impl WasmtimeWorkspaceObserveTaskScheduleError {
pub(super) fn new(
owner_batches: PluginHostOwnerBatches,
source: WasmtimeWorkspaceObserveTaskEnqueueError,
) -> Self {
assert_eq!(
owner_batches.identity_proof(),
source.batch().identity_proof(),
"Wasmtime observe-task schedule error must share one plugin identity",
);
Self {
owner_batches: Box::new(owner_batches),
source: Box::new(source),
}
}
#[must_use]
pub fn identity(&self) -> &str {
self.owner_batches.identity()
}
#[must_use]
pub const fn identity_proof(&self) -> &PluginIdentity {
self.owner_batches.identity_proof()
}
#[must_use]
pub fn effects(&self) -> &SealedPluginEffectBatch {
self.owner_batches.effects()
}
#[must_use]
pub fn workspace_io(&self) -> &SealedPluginWorkspaceIoBatch {
self.owner_batches.workspace_io()
}
#[must_use]
pub fn owner_batches(&self) -> &PluginHostOwnerBatches {
&self.owner_batches
}
#[must_use]
pub fn enqueue_error(&self) -> &WasmtimeWorkspaceObserveTaskEnqueueError {
&self.source
}
#[must_use]
pub fn operational_event(&self) -> Option<PluginOperationalEvent> {
self.source.operational_event()
}
#[must_use]
pub fn into_parts(self) -> WasmtimeWorkspaceObserveTaskScheduleErrorParts {
WasmtimeWorkspaceObserveTaskScheduleErrorParts {
owner_batches: *self.owner_batches,
enqueue_error: *self.source,
}
}
#[must_use]
pub fn discard(self) -> WasmtimeWorkspaceObserveTaskScheduleDiscardReport {
let WasmtimeWorkspaceObserveTaskScheduleErrorParts {
owner_batches,
enqueue_error,
} = self.into_parts();
WasmtimeWorkspaceObserveTaskScheduleDiscardReport::new(
owner_batches.discard(),
enqueue_error.discard_batch(),
)
}
}
impl Debug for WasmtimeWorkspaceObserveTaskScheduleError {
fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
formatter
.debug_struct("WasmtimeWorkspaceObserveTaskScheduleError")
.field("identity", self.identity_proof())
.field("effect_count", &self.owner_batches.effects().effect_count())
.field(
"workspace_io_request_count",
&self.owner_batches.workspace_io().request_count(),
)
.field("enqueue_error_kind", &self.source.kind())
.field(
"workspace_observe_task_count",
&self.source.batch().task_count(),
)
.finish()
}
}
#[derive(Eq, PartialEq)]
pub struct WasmtimeWorkspaceObserveTaskScheduleDiscardReport {
owner_work: PluginHostOwnerDiscardReport,
workspace_observe_tasks: PluginWorkspaceObserveTaskDiscardReport,
}
pub struct WasmtimeWorkspaceObserveTaskScheduleDiscardReportParts {
pub owner_work: PluginHostOwnerDiscardReport,
pub workspace_observe_tasks: PluginWorkspaceObserveTaskDiscardReport,
}
impl WasmtimeWorkspaceObserveTaskScheduleDiscardReport {
pub(super) fn new(
owner_work: PluginHostOwnerDiscardReport,
workspace_observe_tasks: PluginWorkspaceObserveTaskDiscardReport,
) -> Self {
assert_eq!(
owner_work.identity_proof(),
workspace_observe_tasks.identity_proof(),
"Wasmtime observe-task schedule discard report must share one plugin identity",
);
Self {
owner_work,
workspace_observe_tasks,
}
}
#[must_use]
pub fn identity(&self) -> &str {
self.identity_proof().as_str()
}
#[must_use]
pub const fn identity_proof(&self) -> &PluginIdentity {
self.owner_work.identity_proof()
}
#[must_use]
pub const fn owner_work(&self) -> &PluginHostOwnerDiscardReport {
&self.owner_work
}
#[must_use]
pub const fn workspace_observe_tasks(&self) -> &PluginWorkspaceObserveTaskDiscardReport {
&self.workspace_observe_tasks
}
#[must_use]
pub fn into_parts(self) -> WasmtimeWorkspaceObserveTaskScheduleDiscardReportParts {
WasmtimeWorkspaceObserveTaskScheduleDiscardReportParts {
owner_work: self.owner_work,
workspace_observe_tasks: self.workspace_observe_tasks,
}
}
}
impl Debug for WasmtimeWorkspaceObserveTaskScheduleDiscardReport {
fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
formatter
.debug_struct("WasmtimeWorkspaceObserveTaskScheduleDiscardReport")
.field("identity", self.identity_proof())
.field(
"discarded_effect_count",
&self.owner_work.effects().discarded_effects(),
)
.field(
"discarded_workspace_io_request_count",
&self.owner_work.workspace_io().discarded_requests(),
)
.field(
"discarded_workspace_observe_task_count",
&self.workspace_observe_tasks.discarded_tasks(),
)
.finish()
}
}
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum WasmtimePluginUpdateScheduleError {
#[error(transparent)]
Update(#[from] WasmtimePluginRuntimeError),
#[error(transparent)]
WorkspaceObserveTasks(#[from] WasmtimeWorkspaceObserveTaskScheduleError),
}
impl WasmtimePluginUpdateScheduleError {
#[must_use]
pub const fn update_error(&self) -> Option<&WasmtimePluginRuntimeError> {
match self {
Self::Update(source) => Some(source),
Self::WorkspaceObserveTasks(_) => None,
}
}
#[must_use]
pub const fn workspace_observe_task_schedule_error(
&self,
) -> Option<&WasmtimeWorkspaceObserveTaskScheduleError> {
match self {
Self::WorkspaceObserveTasks(source) => Some(source),
Self::Update(_) => None,
}
}
#[must_use]
pub fn workspace_observe_task_enqueue_error(
&self,
) -> Option<&WasmtimeWorkspaceObserveTaskEnqueueError> {
match self {
Self::WorkspaceObserveTasks(source) => Some(source.enqueue_error()),
Self::Update(_) => None,
}
}
#[must_use]
pub fn operational_event(&self) -> Option<PluginOperationalEvent> {
match self {
Self::Update(source) => source.operational_event(),
Self::WorkspaceObserveTasks(source) => source.operational_event(),
}
}
#[must_use]
pub fn into_workspace_observe_task_schedule_error(
self,
) -> Option<WasmtimeWorkspaceObserveTaskScheduleError> {
match self {
Self::WorkspaceObserveTasks(source) => Some(source),
Self::Update(_) => None,
}
}
}