linera_base/
task_processor.rs

1// Copyright (c) Facebook, Inc. and its affiliates.
2// Copyright (c) Zefchain Labs, Inc.
3// SPDX-License-Identifier: Apache-2.0
4
5//! Types related to the task processor features in the node service.
6
7use async_graphql::scalar;
8use serde::{Deserialize, Serialize};
9
10use crate::data_types::Timestamp;
11
12/// The off-chain actions requested by the service of an on-chain application.
13///
14/// On-chain applications should be ready to respond to GraphQL queries of the form:
15/// ```ignore
16/// query {
17///   nextActions(lastRequestedCallback: Timestamp, now: Timestamp!): ProcessorActions!
18/// }
19///
20/// query {
21///   processTaskOutcome(outcome: TaskOutcome!)
22/// }
23/// ```
24#[derive(Default, Debug, Serialize, Deserialize)]
25pub struct ProcessorActions {
26    /// The application is requesting to be called back no later than the given timestamp.
27    pub request_callback: Option<Timestamp>,
28    /// An optional cursor for the task processor to store and pass to the application
29    /// upon the next query for actions.
30    pub set_cursor: Option<String>,
31    /// The application is requesting the execution of the given tasks.
32    pub execute_tasks: Vec<Task>,
33}
34
35scalar!(ProcessorActions);
36
37/// An off-chain task requested by an on-chain application.
38#[derive(Debug, Serialize, Deserialize)]
39pub struct Task {
40    /// The operator handling the task.
41    pub operator: String,
42    /// The input argument in JSON.
43    pub input: String,
44}
45
46/// The result of executing an off-chain operator.
47#[derive(Debug, Serialize, Deserialize)]
48pub struct TaskOutcome {
49    /// The operator handling the task.
50    pub operator: String,
51    /// The JSON output.
52    pub output: String,
53}
54
55scalar!(TaskOutcome);