Add Rust domain kernel and wire contracts
This commit is contained in:
parent
ff379fb002
commit
4da5a980ed
1 changed files with 3757 additions and 1 deletions
114
crates/remora-contracts/src/events.rs
Normal file
114
crates/remora-contracts/src/events.rs
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
use remora_domain::{JobLifecycle, JobPhase, OpaqueId};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
CursorDto, DateTimeDto, NullableDto, PositiveIntegerDto, SafeIntegerDto, SchemaVersionDto,
|
||||
wire::optional_nullable,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||
#[serde(tag = "kind", rename_all = "snake_case")]
|
||||
pub enum EventFrameDto {
|
||||
JobChanged(JobChangedDto),
|
||||
DeletionChanged(DeletionChangedDto),
|
||||
ResyncRequired(ResyncRequiredDto),
|
||||
Heartbeat(HeartbeatDto),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct JobChangedDto {
|
||||
pub schema_version: SchemaVersionDto,
|
||||
pub event_id: OpaqueId,
|
||||
pub sequence: PositiveIntegerDto,
|
||||
pub cursor: CursorDto,
|
||||
pub occurred_at: DateTimeDto,
|
||||
pub job_id: OpaqueId,
|
||||
pub job_revision: PositiveIntegerDto,
|
||||
pub phase: JobPhase,
|
||||
pub lifecycle: JobLifecycle,
|
||||
pub authoritative_attempt: NullableDto<EventAttemptDto>,
|
||||
pub progress: NullableDto<EventProgressDto>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct EventAttemptDto {
|
||||
pub attempt_id: OpaqueId,
|
||||
pub fence: PositiveIntegerDto,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct EventProgressDto {
|
||||
pub attempt_id: OpaqueId,
|
||||
pub fence: PositiveIntegerDto,
|
||||
pub completed_bytes: SafeIntegerDto,
|
||||
#[serde(
|
||||
default,
|
||||
deserialize_with = "optional_nullable",
|
||||
skip_serializing_if = "Option::is_none"
|
||||
)]
|
||||
pub total_bytes: Option<NullableDto<SafeIntegerDto>>,
|
||||
pub completed_members: SafeIntegerDto,
|
||||
#[serde(
|
||||
default,
|
||||
deserialize_with = "optional_nullable",
|
||||
skip_serializing_if = "Option::is_none"
|
||||
)]
|
||||
pub total_members: Option<NullableDto<SafeIntegerDto>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct DeletionChangedDto {
|
||||
pub schema_version: SchemaVersionDto,
|
||||
pub event_id: OpaqueId,
|
||||
pub sequence: PositiveIntegerDto,
|
||||
pub cursor: CursorDto,
|
||||
pub occurred_at: DateTimeDto,
|
||||
pub job_id: OpaqueId,
|
||||
pub operation_id: OpaqueId,
|
||||
pub state: DeletionStateDto,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum DeletionStateDto {
|
||||
Queued,
|
||||
Running,
|
||||
RetryWait,
|
||||
Blocked,
|
||||
Completed,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct ResyncRequiredDto {
|
||||
pub schema_version: SchemaVersionDto,
|
||||
pub event_id: OpaqueId,
|
||||
pub sequence: PositiveIntegerDto,
|
||||
pub cursor: CursorDto,
|
||||
pub occurred_at: DateTimeDto,
|
||||
pub reason: ResyncReasonDto,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum ResyncReasonDto {
|
||||
CursorAbsent,
|
||||
CursorInvalid,
|
||||
CursorExpired,
|
||||
AuthorizationChanged,
|
||||
HistoryUnavailable,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct HeartbeatDto {
|
||||
pub schema_version: SchemaVersionDto,
|
||||
pub event_id: OpaqueId,
|
||||
pub sequence: PositiveIntegerDto,
|
||||
pub cursor: CursorDto,
|
||||
pub occurred_at: DateTimeDto,
|
||||
}
|
||||
Loading…
Reference in a new issue