// Spawns a running wasmtime instance with the given context and status
// channel. Due to the Instance type not being Send safe, all of the logic
// needs to be done within the spawned task
Spawns a running wasmtime instance with the given context and status
channel. Due to the Instance type not being Send safe, all of the logic
needs to be done within the spawned task
Spawns a running wasmtime instance with the given context and status channel . Due to the Instance type not being Send safe all of the logic needs to be done within the spawned task
async fn spawn_wasm3(
    module_bytes: Vec<u8>,
    stack_size: u32,
    status_sender: Sender<ContainerStatus>,
    _output_write: std::fs::File, //TODO: hook this up such that log output will be written to the file
) -> anyhow::Result<JoinHandle<anyhow::Result<()>>> {
    let handle = tokio::task::spawn_blocking(move || -> anyhow::Result<_> {
        let env = match Environment::new() {
            // We can't map errors here or it moves the send channel, so we
            // do it in a match
            Ok(m) => m,
            Err(e) => {
                let message = "cannot create environment";
                error!("{}: {:?}", message, e);
                send(
                    status_sender.clone(),
                    name,
                    Status::Terminated {
                        failed: true,
                        message: message.into(),
                        timestamp: chrono::Utc::now(),
                    },
                    &mut cx,
                );
                return Err(e);
            }
        }
        let rt = env.create_runtime(stack_size).expect("cannot create runtime");
        let module = Module::parse(&env, &module_bytes).expect("cannot parse module");
        let mut module = rt.load_module(module).expect("cannot load module");
        module.link_wasi().expect("cannot link WASI");
        let func = module.find_function::<(), ()>("_start").expect("cannot find function '_start' in module");
        func.call().expect("cannot call '_start' in module");
        status_sender.broadcast(ContainerStatus::Terminated {
            failed: false,
            message: "Module run completed".into(),
            timestamp: chrono::Utc::now(),
        }).expect("status should be able to send");
        Ok(())
    });
    Ok(handle)
}
async fn spawn_wasm3 ( module_bytes : Vec < u8 > , stack_size : u32 , status_sender : Sender < ContainerStatus > , _output_write : std :: fs :: File , //TODO: hook this up such that log output will be written to the file ) -> anyhow :: Result < JoinHandle < anyhow :: Result < ( ) > > > { let handle = tokio :: task :: spawn_blocking ( move | | -> anyhow :: Result < _ > { let env = match Environment :: new ( ) { // We can't map errors here or it moves the send channel, so we // do it in a match Ok ( m ) => m , Err ( e ) => { let message = " " ; error ! ( " " message e ) ; send ( status_sender . clone ( ) , name , Status :: Terminated { failed : true , message : message . into ( ) , timestamp : chrono :: Utc :: now ( ) , } , & mut cx , ) ; return Err ( e ) ; } } let rt = env . create_runtime ( stack_size ) . expect ( " " ) ; let module = Module :: parse ( & env , & module_bytes ) . expect ( " " ) ; let mut module = rt . load_module ( module ) . expect ( " " ) ; module . link_wasi ( ) . expect ( " " ) ; let func = module . find_function :: < ( ) , ( ) > ( " " ) . expect ( " " ) ; func . call ( ) . expect ( " " ) ; status_sender . broadcast ( ContainerStatus :: Terminated { failed : false , message : " " . into ( ) , timestamp : chrono :: Utc :: now ( ) , } ) . expect ( " " ) ; Ok ( ( ) ) } ) ; Ok ( handle ) }
Spawns a running wasmtime instance with the given context and status
channel.
Spawns a running wasmtime instance with the given context and status channel .
module_bytes
Vec<u8>
stack_size
u32
status_sender
Sender<ContainerStatus>
_output_write
std::fs::File