Skip to content

Commit

Permalink
catch up
Browse files Browse the repository at this point in the history
  • Loading branch information
DGAlexandru committed Nov 6, 2024
1 parent c2fab37 commit a9b2356
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 268 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ build/
.vscode/

/backend/lib/res/NoCloud.openapi.schema.json
/backend/lib/res/build_metadata.json

/docs/vendor
/docs/_site
28 changes: 18 additions & 10 deletions backend/lib/scheduler/Scheduler.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const Logger = require("../Logger");
const Tools = require("../utils/Tools");
const NoCloudFanSpeedControlTimerPreAction = require("./pre_actions/NoCloudFanSpeedControlTimerPreAction");
const NoCloudFullCleanupTimerAction = require("./actions/NoCloudFullCleanupTimerAction");
const NoCloudNTPClientDisabledState = require("../entities/core/ntpClient/NoCloudNTPClientDisabledState");
const NoCloudNTPClientSyncedState = require("../entities/core/ntpClient/NoCloudNTPClientSyncedState");
const NoCloudOperationModeControlTimerPreAction = require("./pre_actions/NoCloudOperationModeControlTimerPreAction");
const NoCloudSegmentCleanupTimerAction = require("./actions/NoCloudSegmentCleanupTimerAction");
Expand Down Expand Up @@ -32,15 +32,23 @@ class Scheduler {
}

evaluateTimers() {
if (
!(
this.ntpClient.state instanceof NoCloudNTPClientSyncedState ||
this.ntpClient.state instanceof NoCloudNTPClientDisabledState
) && this.config.get("embedded") === true
) {
// Since some robots have no rtc, we absolutely require a synced time when embedded
// Therefore, we're aborting without it unless you explicitly disable the NTPClient
// In that case you're on your own to provide the correct time to the robot
const NTPClientStateIsValid = this.ntpClient.state instanceof NoCloudNTPClientSyncedState;
const isEmbedded = this.config.get("embedded") === true;
const hasBuildTimestamp = Tools.GET_BUILD_TIMESTAMP() > new Date(-1);
const timeIsPlausible = Tools.GET_BUILD_TIMESTAMP() < new Date();

let shouldEvaluateTimers;
if (isEmbedded) {
shouldEvaluateTimers = NTPClientStateIsValid || (hasBuildTimestamp && timeIsPlausible);
} else {
if (hasBuildTimestamp) {
shouldEvaluateTimers = timeIsPlausible;
} else { // Probably dev env
shouldEvaluateTimers = true;
}
}

if (!shouldEvaluateTimers) {
return;
}

Expand Down
39 changes: 16 additions & 23 deletions backend/lib/utils/Tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const LinuxTools = require("./LinuxTools");
const {sleep} = require("./misc");

let SYSTEM_ID;
let BUILD_METADATA;

class Tools {
static MK_DIR_PATH(filepath) {
Expand Down Expand Up @@ -41,38 +42,30 @@ class Tools {
return Buffer.isBuffer(buf) && buf[0] === 0x1f && buf[1] === 0x8b;
}

static GET_NoCloud_VERSION() {
let NoCloudVersion = "unknown";
static READ_BUILD_METADATA() {
if (BUILD_METADATA) {
return BUILD_METADATA;
}

try {
const rootDirectory = path.resolve(__dirname, "../../..");
const packageContent = fs.readFileSync(rootDirectory + "/package.json", {"encoding": "utf-8"});

if (packageContent) {
NoCloudVersion = JSON.parse(packageContent.toString()).version;
}
BUILD_METADATA = JSON.parse(fs.readFileSync(path.join(__dirname, "../res/build_metadata.json")).toString());
} catch (e) {
//intentional
return null;
}

return NoCloudVersion;
return BUILD_METADATA;
}

static GET_COMMIT_ID() {
let commitId = "unknown";

try {
const rootDirectory = path.resolve(__dirname, "../../..");
commitId = fs.readFileSync(rootDirectory + "/.git/HEAD", {"encoding": "utf-8"}).trim();
static GET_NoCloud_VERSION() {
return Tools.READ_BUILD_METADATA()?.version ?? "unknown";
}

if (commitId.match(/^ref: refs\/heads\/master$/) !== null) {
commitId = fs.readFileSync(rootDirectory + "/.git/refs/heads/master", {"encoding": "utf-8"}).trim();
}
} catch (e) {
//intentional
}
static GET_COMMIT_ID() {
return Tools.READ_BUILD_METADATA()?.commit ?? "unknown";
}

return commitId;
static GET_BUILD_TIMESTAMP() {
return new Date(Tools.READ_BUILD_METADATA()?.buildTimestamp ?? 0);
}

static GET_FREE_SYSTEM_MEMORY() {
Expand Down
11 changes: 5 additions & 6 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
},
"pkg": {
"assets": [
"../.git/HEAD",
"../.git/refs/heads/master",
"../frontend/build",
"../package.json",
"../build_metadata.json",
"../node_modules/swagger-ui-dist/swagger-ui.css",
"./node_modules/swagger-ui-dist/swagger-ui.css"
]
Expand All @@ -26,10 +24,11 @@
"ts-check": "tsc --noEmit",
"test": "mocha \"test/**/*_spec.js\"",
"prepare_commit": "npm run lint_fix && npm run ts-check && npm run test",
"pre_build": "node ../util/generate_build_metadata.js",
"build": "npm run build_aarch64 && npm run build_armv7 && npm run build_armv7_lowmem",
"build_armv7": "cross-env PKG_CACHE_PATH=../build_dependencies/pkg pkg --targets node20-linuxstatic-armv7 --compress Brotli --no-bytecode --public-packages \"*\" --options \"expose-gc,max-heap-size=42\" . --output ../build/armv7/NoCloud",
"build_aarch64": "cross-env PKG_CACHE_PATH=../build_dependencies/pkg pkg --targets node20-linuxstatic-arm64 --compress Brotli --no-bytecode --public-packages \"*\" --options \"expose-gc,max-heap-size=64\" . --output ../build/aarch64/NoCloud",
"build_armv7_lowmem": "cross-env PKG_CACHE_PATH=../build_dependencies/pkg pkg --targets node20-linuxstatic-armv7 --compress Brotli --no-bytecode --public-packages \"*\" --options \"expose-gc,max-heap-size=34,optimize-for-size,lite-mode,no-regexp-tier-up,no-expose-wasm\" . --output ../build/armv7/NoCloud-lowmem"
"build_armv7": "npm run pre_build && cross-env PKG_CACHE_PATH=../build_dependencies/pkg pkg --targets node20-linuxstatic-armv7 --compress Brotli --no-bytecode --public-packages \"*\" --options \"expose-gc,max-heap-size=42\" . --output ../build/armv7/NoCloud",
"build_aarch64": "npm run pre_build && cross-env PKG_CACHE_PATH=../build_dependencies/pkg pkg --targets node20-linuxstatic-arm64 --compress Brotli --no-bytecode --public-packages \"*\" --options \"expose-gc,max-heap-size=64\" . --output ../build/aarch64/NoCloud",
"build_armv7_lowmem": "npm run pre_build && cross-env PKG_CACHE_PATH=../build_dependencies/pkg pkg --targets node20-linuxstatic-armv7 --compress Brotli --no-bytecode --public-packages \"*\" --options \"expose-gc,max-heap-size=34,optimize-for-size,lite-mode,no-regexp-tier-up,no-expose-wasm\" . --output ../build/armv7/NoCloud-lowmem"
},
"author": "",
"dependencies": {
Expand Down
Loading

0 comments on commit a9b2356

Please sign in to comment.