Skip to main content

dvm_api/
execution.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{Run, Sandbox, SandboxCommand, SandboxId, SandboxSpec};
4
5/// A sandbox's execution, `GET /api/executions/{id}`: what it ran, one log
6/// from its start to its end, under its sandbox's id. Its spec, its seed
7/// among it; its run, how and when it ended, and its log's size; each
8/// command it was sent, as it ran; and its replays.
9#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
10#[cfg_attr(feature = "typescript", derive(ts_rs::TS))]
11#[cfg_attr(feature = "typescript", ts(export_to = "controller-api.ts"))]
12pub struct Execution {
13    pub id: SandboxId,
14    /// Its owner's GitHub login; none for one made before users signed in,
15    /// which only admins see.
16    pub owner: Option<String>,
17    pub spec: SandboxSpec,
18    pub run: Run,
19    /// Oldest first.
20    pub commands: Vec<SandboxCommand>,
21    /// Oldest first.
22    pub replays: Vec<Run>,
23}
24
25impl Execution {
26    /// The execution of `sandbox`, which ran `commands`.
27    pub fn of(sandbox: Sandbox, commands: Vec<SandboxCommand>) -> Self {
28        Self {
29            id: sandbox.id,
30            owner: sandbox.owner,
31            spec: sandbox.spec,
32            run: sandbox.run,
33            commands,
34            replays: sandbox.replays,
35        }
36    }
37}