summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriximeow <git@iximeow.net>2022-12-29 19:08:35 +0000
committeriximeow <git@iximeow.net>2022-12-29 19:08:35 +0000
commitfb64c0fb491b5a4d481e1a32efb57199f6bd89c2 (patch)
treee0c6d46e0378640ca18dccdd12a583d9e61ba287
parent0832c96c116f4c3a28bd22a0cdd287a3b0764c7b (diff)
allow goodfiles to query current time
-rw-r--r--src/lua/mod.rs11
1 files changed, 11 insertions, 0 deletions
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<String>)| {
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();