From fb64c0fb491b5a4d481e1a32efb57199f6bd89c2 Mon Sep 17 00:00:00 2001 From: iximeow Date: Thu, 29 Dec 2022 19:08:35 +0000 Subject: allow goodfiles to query current time --- src/lua/mod.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/lua/mod.rs') diff --git a/src/lua/mod.rs b/src/lua/mod.rs index f186e6b..8f14b9a 100644 --- a/src/lua/mod.rs +++ b/src/lua/mod.rs @@ -4,6 +4,7 @@ use rlua::prelude::*; use std::sync::{Arc, Mutex}; use std::path::PathBuf; +use std::time::{UNIX_EPOCH, SystemTime}; pub const DEFAULT_RUST_GOODFILE: &'static [u8] = include_bytes!("../../config/goodfiles/rust.lua"); @@ -142,6 +143,15 @@ impl BuildEnv { }) .map_err(|e| format!("problem defining metric function: {:?}", e))?; + let now_ms = lua_ctx.create_function(move |_, ()| { + let now = SystemTime::now(); + Ok(now + .duration_since(UNIX_EPOCH) + .expect("now is later than epoch") + .as_millis() as u64) + }) + .map_err(|e| format!("problem defining now_ms function: {:?}", e))?; + let job_ref = Arc::clone(&self.job); let artifact = lua_ctx.create_function(move |_, (path, name): (String, Option)| { let path: PathBuf = path.into(); @@ -214,6 +224,7 @@ impl BuildEnv { ("metric", metric), ("error", error), ("artifact", artifact), + ("now_ms", now_ms), ] ).unwrap(); build_functions.set("environment", build_environment).unwrap(); -- cgit v1.1