Function holochain::core::queue_consumer::spawn_queue_consumer_tasks
source · pub async fn spawn_queue_consumer_tasks(
cell_id: CellId,
network: HolochainP2pDna,
space: &Space,
conductor_handle: ConductorHandle,
task_sender: Sender<ManagedTaskAdd>,
stop: Sender<()>
) -> (QueueTriggers, InitialQueueTriggers)
Expand description
Spawns several long-running tasks which are responsible for processing work which shows up on various databases.
Waits for the initial loop to complete before returning, to prevent causing a race condition by trying to run a workflow too soon after cell creation.
Examples found in repository?
src/conductor/cell.rs (lines 135-142)
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
pub async fn create(
id: CellId,
conductor_handle: ConductorHandle,
space: Space,
holochain_p2p_cell: holochain_p2p::HolochainP2pDna,
managed_task_add_sender: sync::mpsc::Sender<ManagedTaskAdd>,
managed_task_stop_broadcaster: sync::broadcast::Sender<()>,
) -> CellResult<(Self, InitialQueueTriggers)> {
let conductor_api = Arc::new(CellConductorApi::new(conductor_handle.clone(), id.clone()));
// check if genesis has been run
let has_genesis = {
// check if genesis ran.
GenesisWorkspace::new(space.authored_db.clone(), space.dht_db.clone())?
.has_genesis(id.agent_pubkey().clone())
.await?
};
if has_genesis {
let (queue_triggers, initial_queue_triggers) = spawn_queue_consumer_tasks(
id.clone(),
holochain_p2p_cell.clone(),
&space,
conductor_handle.clone(),
managed_task_add_sender,
managed_task_stop_broadcaster,
)
.await;
Ok((
Self {
id,
conductor_api,
conductor_handle,
space,
holochain_p2p_cell,
queue_triggers,
init_mutex: Default::default(),
},
initial_queue_triggers,
))
} else {
Err(CellError::CellWithoutGenesis(id))
}
}