3ad455fe206c705f4858ea2bc42af8cd6da2553a — Cadence Ember 9 months ago 788ab28
add counter restart feature
2 files changed, 21 insertions(+), 3 deletions(-)

M run.fish
M utils/helpers.fish
M run.fish => run.fish +10 -3
@@ 24,6 24,13 @@ end

set pull_interval 10m
set update_applied false
set should_auto_restart (count $argv[1] >/dev/null; and echo true; or echo false)
set auto_restart_cycles $argv[1]
set auto_restart_countdown $auto_restart_cycles

function do_restart_countdown
	$should_auto_restart; and test (quick_math auto_restart_countdown - 1) -le 0

cd bibliogram/src/site

@@ 37,15 44,15 @@ while true
	set update_applied false

	echo '' | node server.js &
	set -l b_pid (jobs -p)

	while not $update_applied
		sleep $pull_interval

		if do_update
		if do_update; or do_restart_countdown
			npm install --no-optional
			set update_applied true
			kill $b_pid
			set auto_restart_countdown $auto_restart_cycles
			kill (jobs -p)
			echo '[ ] ['(date +%H%M%S)'] [UPD] No updates available yet.'

M utils/helpers.fish => utils/helpers.fish +11 -0
@@ 36,3 36,14 @@ function update_origin_url
		git fetch --quiet; or return 1

# Alter a variable with math.
# argv[1]: the variable to alter.
# argv[2...]: arguments to math.
# text: the new value of the variable.
function quick_math
	set -l variable $argv[1]
	set -l math_args $argv[2..-1]
	set $variable (math $$variable $math_args)
	echo $$variable