(import chicken scheme)
(use posix srfi-19)

(define (log* msg)
  (display (conc "[" (date->string (current-date) "~D ~T") "] " msg "\n")
           (current-error-port)))

(let ((cmd "./feeds"))
  (let loop ()
    (log* "running")
    (let loop2 ((pid (process-run cmd)))
      (sleep 300) ; 5 minutes
      (when (= (process-wait pid #t) 0)
        (log* "killing")
        (process-signal pid signal/kill)
        (log* "sent kill sigal")
        (process-wait pid)
        (log* "killed and rerunning")
        (loop2 (process-run cmd))))
    (log* "done")
    (sleep 540) ; 9 minutes
    (loop)))
