fix(nix-monitor): cancel running check if it took more than threshold
This commit is contained in:
@@ -22,8 +22,10 @@ end
|
||||
|
||||
local branch = cfg("branch")
|
||||
local updateCheckInterval = cfg("check_interval")
|
||||
local checkDurationThreshold = cfg("check_duration_threshold")
|
||||
local systemStatsCheckInterval = cfg("system_stats_check_interval")
|
||||
local completedCommands = 0
|
||||
local isInit = true
|
||||
|
||||
local localHashCmd = "nixos-version --hash 2> /dev/null | cut -c -7"
|
||||
local remoteHashCmd = "sleep 5 && git ls-remote https://github.com/NixOS/nixpkgs " .. branch .. " 2>/dev/null | cut -c 1-7"
|
||||
@@ -34,7 +36,8 @@ local hmCurrentGenCmd = "home-manager generations | grep '(current)' | awk '{pri
|
||||
local storeSizeCmd = `du -s --block-size=1GiB /nix/store | awk '\{print $1 " GiB"\}'`
|
||||
local closureSizeCmd = "nix path-info --closure-size --human-readable /run/current-system | awk '{print $2, $3}'"
|
||||
|
||||
setState("lastCheckTime", 0)
|
||||
setState("lastRunTime", os.time())
|
||||
setState("lastCheckTime", os.time())
|
||||
setState("lastCheckTimeStr", "n/a")
|
||||
setState("localHash", "n/a")
|
||||
setState("remoteHash", "n/a")
|
||||
@@ -50,10 +53,15 @@ setState("storeSize", "•••")
|
||||
setState("closureSize", "•••")
|
||||
|
||||
function update()
|
||||
if (os.time() - getState("lastCheckTime")) >= 60 * updateCheckInterval then
|
||||
if isInit or (os.time() - getState("lastCheckTime")) >= 60 * updateCheckInterval then
|
||||
isInit = false
|
||||
checkUpdate()
|
||||
end
|
||||
|
||||
if getState("isRunning") and (os.time() - getState("lastRunTime")) >= 60 * checkDurationThreshold then
|
||||
cancelCheck()
|
||||
end
|
||||
|
||||
if (os.time() - getState("lastSystemStatsCheckTime")) >= 60 * systemStatsCheckInterval then
|
||||
checkSystemStats()
|
||||
end
|
||||
@@ -64,8 +72,7 @@ function checkUpdate()
|
||||
return
|
||||
end
|
||||
|
||||
setState("lastCheckTime", os.time())
|
||||
noctalia.runAsync("date '+%Y-%m-%d %H:%M'", function(date) setState("lastCheckTimeStr", date.stdout) end)
|
||||
setState("lastRunTime", os.time())
|
||||
|
||||
if cfg("show_checking_notification") then
|
||||
noctalia.notify(tr("notification.checking_update"))
|
||||
@@ -115,18 +122,25 @@ function onHashCheckCompleted()
|
||||
noctalia.notify(tr("notification.update_check_completed"))
|
||||
end
|
||||
|
||||
setState("lastCheckTime", os.time())
|
||||
noctalia.runAsync("date '+%Y-%m-%d %H:%M'", function(date) setState("lastCheckTimeStr", date.stdout) end)
|
||||
|
||||
setState("isRunning", false)
|
||||
end
|
||||
|
||||
function cancelCheck()
|
||||
noctalia.runAsync(`kill $(ps -ef | grep "git ls-remote https://github.com/NixOS/nixpkgs" | grep -v grep | awk '\{print $2\}')`)
|
||||
setState("isRunning", false)
|
||||
completedCommands = 0
|
||||
end
|
||||
|
||||
watchState("command", function(command)
|
||||
if command == "check" then
|
||||
checkUpdate()
|
||||
end
|
||||
|
||||
if command == "cancel" then
|
||||
noctalia.runAsync(`kill $(ps -ef | grep "git ls-remote https://github.com/NixOS/nixpkgs" | grep -v grep | awk '\{print $2\}')`)
|
||||
setState("isRunning", false)
|
||||
completedCommands = 0
|
||||
cancelCheck()
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
@@ -93,6 +93,15 @@ description_key = "setting.check_interval.description"
|
||||
default = 60
|
||||
min = 10
|
||||
|
||||
[[setting]]
|
||||
key = "check_duration_threshold"
|
||||
type = "int"
|
||||
label_key = "setting.check_duration_threshold.label"
|
||||
description_key = "setting.check_duration_threshold.description"
|
||||
default = 5
|
||||
min = 1
|
||||
max = 30
|
||||
|
||||
[[setting]]
|
||||
key = "system_stats_check_interval"
|
||||
type = "int"
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
"setting.widget.unknown_color.label": "Unknown status color",
|
||||
"setting.check_interval.label": "Update check interval",
|
||||
"setting.check_interval.description": "How often to check for updates (in minutes)",
|
||||
"setting.check_duration_threshold.label": "Update check duration threshold",
|
||||
"setting.check_duration_threshold.description": "Cancel check if it took too long (in minutes)",
|
||||
"setting.system_stats_check_interval.label": "System stats check interval",
|
||||
"setting.system_stats_check_interval.description": "How often to check for system stats (in minutes)",
|
||||
"setting.checking_notification.label": "Show checking update notification",
|
||||
|
||||
Reference in New Issue
Block a user