pub struct ManagedTaskAdd { /* private fields */ }
Expand description

A message sent to the TaskManager, registering an ManagedTask of a given kind.

Implementations§

You just want the task in the task manager but don’t want to react to an error

Examples found in repository?
src/conductor/conductor.rs (lines 421-424)
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
        pub(crate) async fn add_admin_interfaces(
            self: Arc<Self>,
            configs: Vec<AdminInterfaceConfig>,
        ) -> ConductorResult<()> {
            let admin_api = RealAdminInterfaceApi::new(self.clone());
            let stop_tx = self.task_manager.share_ref(|tm| {
                tm.as_ref()
                    .expect("Task manager not started yet")
                    .task_stop_broadcaster()
                    .clone()
            });

            // Closure to process each admin config item
            let spawn_from_config = |AdminInterfaceConfig { driver, .. }| {
                let admin_api = admin_api.clone();
                let stop_tx = stop_tx.clone();
                async move {
                    match driver {
                        InterfaceDriver::Websocket { port } => {
                            let (listener_handle, listener) =
                                spawn_websocket_listener(port).await?;
                            let port = listener_handle.local_addr().port().unwrap_or(port);
                            let handle: ManagedTaskHandle = spawn_admin_interface_task(
                                listener_handle,
                                listener,
                                admin_api.clone(),
                                stop_tx.subscribe(),
                            )?;
                            InterfaceResult::Ok((port, handle))
                        }
                    }
                }
            };

            // spawn interface tasks, collect their JoinHandles,
            // panic on errors.
            let handles: Result<Vec<_>, _> =
                future::join_all(configs.into_iter().map(spawn_from_config))
                    .await
                    .into_iter()
                    .collect();
            // Exit if the admin interfaces fail to be created
            let handles = handles.map_err(Box::new)?;

            {
                let mut ports = Vec::new();

                // First, register the keepalive task, to ensure the conductor doesn't shut down
                // in the absence of other "real" tasks
                self.manage_task(ManagedTaskAdd::ignore(
                    tokio::spawn(keep_alive_task(stop_tx.subscribe())),
                    "keepalive task",
                ))
                .await?;

                // Now that tasks are spawned, register them with the TaskManager
                for (port, handle) in handles {
                    ports.push(port);
                    self.manage_task(ManagedTaskAdd::ignore(
                        handle,
                        &format!("admin interface, port {}", port),
                    ))
                    .await?
                }
                for p in ports {
                    self.add_admin_port(p);
                }
            }
            Ok(())
        }

        /// Spawn a new app interface task, register it with the TaskManager,
        /// and modify the conductor accordingly, based on the config passed in
        /// which is just a networking port number (or 0 to auto-select one).
        /// Returns the given or auto-chosen port number if giving an Ok Result
        pub async fn add_app_interface(
            self: Arc<Self>,
            port: either::Either<u16, AppInterfaceId>,
        ) -> ConductorResult<u16> {
            let interface_id = match port {
                either::Either::Left(port) => AppInterfaceId::new(port),
                either::Either::Right(id) => id,
            };
            let port = interface_id.port();
            tracing::debug!("Attaching interface {}", port);
            let app_api = RealAppInterfaceApi::new(self.clone());
            // This receiver is thrown away because we can produce infinite new
            // receivers from the Sender
            let (signal_tx, _r) = tokio::sync::broadcast::channel(SIGNAL_BUFFER_SIZE);
            let stop_rx = self.task_manager.share_ref(|tm| {
                tm.as_ref()
                    .expect("Task manager not initialized")
                    .task_stop_broadcaster()
                    .subscribe()
            });
            let (port, task) = spawn_app_interface_task(port, app_api, signal_tx.clone(), stop_rx)
                .await
                .map_err(Box::new)?;
            // TODO: RELIABILITY: Handle this task by restarting it if it fails and log the error
            self.manage_task(ManagedTaskAdd::ignore(
                task,
                &format!("app interface, port {}", port),
            ))
            .await?;
            let interface = AppInterfaceRuntime::Websocket { signal_tx };

            self.app_interfaces.share_mut(|app_interfaces| {
                if app_interfaces.contains_key(&interface_id) {
                    return Err(ConductorError::AppInterfaceIdCollision(
                        interface_id.clone(),
                    ));
                }

                app_interfaces.insert(interface_id.clone(), interface);
                Ok(())
            })?;
            let config = AppInterfaceConfig::websocket(port);
            self.update_state(|mut state| {
                state.app_interfaces.insert(interface_id, config);
                Ok(state)
            })
            .await?;
            tracing::debug!("App interface added at port: {}", port);
            Ok(port)
        }

If this task fails, the entire conductor must be shut down

If this task fails, only the Cell which it runs under must be stopped

Examples found in repository?
src/core/queue_consumer.rs (lines 105-109)
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
pub async fn spawn_queue_consumer_tasks(
    cell_id: CellId,
    network: HolochainP2pDna,
    space: &Space,
    conductor_handle: ConductorHandle,
    task_sender: sync::mpsc::Sender<ManagedTaskAdd>,
    stop: sync::broadcast::Sender<()>,
) -> (QueueTriggers, InitialQueueTriggers) {
    let Space {
        authored_db,
        dht_db,
        cache_db: cache,
        dht_query_cache,
        ..
    } = space;

    let keystore = conductor_handle.keystore().clone();
    let dna_hash = Arc::new(cell_id.dna_hash().clone());
    let queue_consumer_map = conductor_handle.get_queue_consumer_workflows();

    // Publish
    let (tx_publish, handle) = spawn_publish_dht_ops_consumer(
        cell_id.agent_pubkey().clone(),
        authored_db.clone(),
        conductor_handle.clone(),
        stop.subscribe(),
        Box::new(network.clone()),
    );
    task_sender
        .send(ManagedTaskAdd::cell_critical(
            handle,
            cell_id.clone(),
            "publish_dht_ops_consumer",
        ))
        .await
        .expect("Failed to manage workflow handle");

    // Validation Receipt
    // One per space.
    let (tx_receipt, handle) =
        queue_consumer_map.spawn_once_validation_receipt(dna_hash.clone(), || {
            spawn_validation_receipt_consumer(
                dna_hash.clone(),
                dht_db.clone(),
                conductor_handle.clone(),
                stop.subscribe(),
                network.clone(),
            )
        });

    if let Some(handle) = handle {
        task_sender
            .send(ManagedTaskAdd::cell_critical(
                handle,
                cell_id.clone(),
                "validation_receipt_consumer",
            ))
            .await
            .expect("Failed to manage workflow handle");
    }

    // Integration
    // One per space.
    let (tx_integration, handle) =
        queue_consumer_map.spawn_once_integration(dna_hash.clone(), || {
            spawn_integrate_dht_ops_consumer(
                dna_hash.clone(),
                dht_db.clone(),
                dht_query_cache.clone(),
                stop.subscribe(),
                tx_receipt.clone(),
                network.clone(),
            )
        });

    if let Some(handle) = handle {
        task_sender
            .send(ManagedTaskAdd::cell_critical(
                handle,
                cell_id.clone(),
                "integrate_dht_ops_consumer",
            ))
            .await
            .expect("Failed to manage workflow handle");
    }

    let dna_def = conductor_handle
        .get_dna_def(&*dna_hash)
        .expect("Dna must be in store");

    // App validation
    // One per space.
    let (tx_app, handle) = queue_consumer_map.spawn_once_app_validation(dna_hash.clone(), || {
        spawn_app_validation_consumer(
            dna_hash.clone(),
            AppValidationWorkspace::new(
                authored_db.clone().into(),
                dht_db.clone(),
                space.dht_query_cache.clone(),
                cache.clone(),
                keystore.clone(),
                Arc::new(dna_def),
            ),
            conductor_handle.clone(),
            stop.subscribe(),
            tx_integration.clone(),
            network.clone(),
            dht_query_cache.clone(),
        )
    });
    if let Some(handle) = handle {
        task_sender
            .send(ManagedTaskAdd::cell_critical(
                handle,
                cell_id.clone(),
                "app_validation_consumer",
            ))
            .await
            .expect("Failed to manage workflow handle");
    }

    let dna_def = conductor_handle
        .get_dna_def(&*dna_hash)
        .expect("Dna must be in store");

    // Sys validation
    // One per space.
    let (tx_sys, handle) = queue_consumer_map.spawn_once_sys_validation(dna_hash.clone(), || {
        spawn_sys_validation_consumer(
            SysValidationWorkspace::new(
                authored_db.clone().into(),
                dht_db.clone().into(),
                dht_query_cache.clone(),
                cache.clone(),
                Arc::new(dna_def),
            ),
            space.clone(),
            conductor_handle.clone(),
            stop.subscribe(),
            tx_app.clone(),
            network.clone(),
        )
    });

    if let Some(handle) = handle {
        task_sender
            .send(ManagedTaskAdd::cell_critical(
                handle,
                cell_id.clone(),
                "sys_validation_consumer",
            ))
            .await
            .expect("Failed to manage workflow handle");
    }

    let (tx_cs, handle) = queue_consumer_map.spawn_once_countersigning(dna_hash.clone(), || {
        spawn_countersigning_consumer(
            space.clone(),
            stop.subscribe(),
            network.clone(),
            tx_sys.clone(),
        )
    });
    if let Some(handle) = handle {
        task_sender
            .send(ManagedTaskAdd::cell_critical(
                handle,
                cell_id.clone(),
                "countersigning_consumer",
            ))
            .await
            .expect("Failed to manage workflow handle");
    }

    (
        QueueTriggers {
            sys_validation: tx_sys.clone(),
            publish_dht_ops: tx_publish.clone(),
            countersigning: tx_cs,
            integrate_dht_ops: tx_integration.clone(),
        },
        InitialQueueTriggers::new(tx_sys, tx_publish, tx_app, tx_integration, tx_receipt),
    )
}

If this task fails, only the Cells with this DnaHash must be stopped

Handle a task’s completion with a generic callback

Trait Implementations§

Formats the value using the given formatter. Read more
The type of value produced on completion.
Attempt to resolve the future to a final value, registering the current task for wakeup if the value is not yet available. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
TODO: once 1.33.0 is the minimum supported compiler version, remove Any::type_id_compat and use StdAny::type_id instead. https://github.com/rust-lang/rust/issues/27745
The archived version of the pointer metadata for this type.
Converts some archived metadata to the pointer metadata for itself.
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Deserializes using the given deserializer

Returns the argument unchanged.

Map this future’s output to a different type, returning a new future of the resulting type. Read more
Map this future’s output to a different type, returning a new future of the resulting type. Read more
Chain on a computation for when a future finished, passing the result of the future to the provided closure f. Read more
Wrap this future in an Either future, making it the left-hand variant of that Either. Read more
Wrap this future in an Either future, making it the right-hand variant of that Either. Read more
Convert this future into a single element stream. Read more
Flatten the execution of this future when the output of this future is itself another future. Read more
Flatten the execution of this future when the successful result of this future is a stream. Read more
Fuse a future such that poll will never again be called once it has completed. This method can be used to turn any Future into a FusedFuture. Read more
Do something with the output of a future before passing it on. Read more
Catches unwinding panics while polling the future. Read more
Create a cloneable handle to this future where all handles will resolve to the same result. Read more
Turn this future into a future that yields () on completion and sends its output to another future on a separate task. Read more
Wrap the future in a Box, pinning it. Read more
Wrap the future in a Box, pinning it. Read more
A convenience for calling Future::poll on Unpin future types.
Evaluates and consumes the future, returning the resulting output if the future is ready after the first call to Future::poll. Read more
Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Attaches the current Context to this type, returning a WithContext wrapper. Read more
Returns a Future that delays execution for a specified time. Read more
Flatten out the execution of this future when the result itself can be converted into another future. Read more
Waits for one of two similarly-typed futures to complete. Read more
Waits for one of two similarly-typed fallible futures to complete. Read more
Waits for two similarly-typed futures to complete. Read more
Waits for two similarly-typed fallible futures to complete. Read more
Waits for both the future and a timeout, if the timeout completes before the future, it returns a TimeoutError. Read more
A convenience for calling Future::poll() on !Unpin types.
Returns the result of self or other future, preferring self if both are ready. Read more
Returns the result of self or other future, with no preference if both are ready. Read more
Catches panics while polling the future. Read more
Boxes the future and changes its type to dyn Future + Send + 'a. Read more
Boxes the future and changes its type to dyn Future + 'a. Read more
Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The output that the future will produce on completion.
Which kind of future are we turning this into?
Creates a future from a value. Read more
The type of value produced on completion.
Which kind of future are we turning this into?
Create a future from a value
Convert this raw future into a MustBoxFuture
The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
The type for metadata in pointers and references to Self.
Should always be Self
The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Checks if self is actually part of its subset T (and can be converted to it).
Use with care! Same as self.to_subset but without any property checks. Always succeeds.
The inclusion map: converts self to the equivalent element of its superset.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
upcast ref
upcast mut ref
upcast boxed dyn
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more