Skip to content

Commit

Permalink
0.3.3 fixes server auto exit
Browse files Browse the repository at this point in the history
  • Loading branch information
rksm committed Aug 16, 2019
1 parent e14b7da commit 53eccdf
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.3.3
## bugfixes
- fix server shutdown issue

# 0.3.2
## bugfixes
- Fix regexp to match non-english timestamps (Thanks @hso!)
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION := 0.3.2
VERSION := 0.3.3

CLJ_FILES := $(shell find . -type f \
\( -path "./test/*" -o -path "./dev/*" -o -path "./src/*" \) \
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ and run it! (double click or from command line, see below). It will open a new b

*2019-08-13: MELPA package is pending, see [the melpa pull request](https://github.com/melpa/melpa/pull/6365).*

For the time being, emacs support can be enabled by downloading the [emacs package](https://github.com/rksm/clj-org-analyzer/releases/download/0.3.2/org-analyzer-for-emacs-0.3.2.tar.gz) directly, extracting it and adding it to your load path and require it:
For the time being, emacs support can be enabled by downloading the [emacs package](https://github.com/rksm/clj-org-analyzer/releases/download/0.3.3/org-analyzer-for-emacs-0.3.3.tar.gz) directly, extracting it and adding it to your load path and require it:

```elisp
(add-to-list 'load-path "/path/to/org-analyzer-0.3.2/")
(add-to-list 'load-path "/path/to/org-analyzer-0.3.3/")
(require 'org-analyzer)
```

Expand All @@ -64,12 +64,12 @@ Afterwards, you can start the tool via `M-x org-analyzer-start`.

## Commandline

Download the latest jar as described above and start it with `java -jar org-analyzer-0.3.2.jar`.
Download the latest jar as described above and start it with `java -jar org-analyzer-0.3.3.jar`.

The following command line options are available, as per `java -jar org-analyzer-0.3.2.jar --help`:
The following command line options are available, as per `java -jar org-analyzer-0.3.3.jar --help`:

```
Usage: java -jar org-analyzer-0.3.2.jar [opt*] [org-file-or-dir*]
Usage: java -jar org-analyzer-0.3.3.jar [opt*] [org-file-or-dir*]
Interactive visualization of timetracking data (org clocks).
Expand Down
2 changes: 1 addition & 1 deletion org-analyzer-el/org-analyzer-pkg.el
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(define-package
"org-analyzer"
"0.3.2"
"0.3.3"
"org-analyzer is a tool that extracts time tracking data from org files.")
4 changes: 2 additions & 2 deletions org-analyzer-el/org-analyzer.el
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
;; Author: Robert Krahn <[email protected]>
;; URL: https://github.com/rksm/clj-org-analyzer
;; Keywords: calendar
;; Version: 0.3.2
;; Version: 0.3.3
;; Package-Requires: ((emacs "24"))

;; Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down Expand Up @@ -44,7 +44,7 @@
(defvar org-analyzer-process-buffer nil
"The buffer for running the jar.")

(defvar org-analyzer-version "0.3.2"
(defvar org-analyzer-version "0.3.3"
"Version to sync with jar.")

(defvar org-analyzer-jar-file-name "org-analyzer.jar"
Expand Down
Binary file modified org-analyzer-el/org-analyzer.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>org.rksm</groupId>
<artifactId>org-analyzer</artifactId>
<packaging>jar</packaging>
<version>0.3.2</version>
<version>0.3.3</version>
<name>org-analyzer</name>
<description>An app that creates an interactive visualization of org-mode time-tracking data (org clockin).</description>
<url>http://github.com/rksm/clj-org-analyzer</url>
Expand Down
37 changes: 25 additions & 12 deletions src/org_analyzer/http_server.clj
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
(ns org-analyzer.http-server
(:require [clojure.edn :as edn]
[clojure.java.io :as io]
[clojure.pprint :refer [cl-format]]
[clojure.set :as set :refer [rename-keys]]
[clojure.string :as s]
[compojure.core :refer [routes GET POST]]
[compojure.core :refer [GET POST routes]]
[compojure.handler :as handler]
[compojure.route :as route]
[java-time :as time]
Expand All @@ -18,8 +19,7 @@
[ring.middleware.stacktrace :refer [wrap-stacktrace]]
[ring.util.response :as response])
(:import java.io.File
java.lang.Thread
[java.time LocalDateTime ZoneId]))
java.lang.Thread))

;; -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Expand Down Expand Up @@ -113,18 +113,32 @@
;; -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

(defn start-kill-countdown!
"(:opts @app-state) has two fields kill-when-client-disconnects? and
kill-remorse-period. If kill-when-client-disconnects? option is truthy, will
set (:am-i-about-to-kill-myself? @app-state) to true and start a countdown for
kill-remorse-period milliseconds. If after the
timeout (:am-i-about-to-kill-myself? @app-state) is still true, it will exit
the program.
`start-kill-countdown!` will be triggered when a client exists. If a new
client is started, it will cancel the kill countdown. This allows us to stop
servers that were started via double click and not via a terminal or other
means that would control the java process."
[app-state]
(let [{{:keys [kill-when-client-disconnects? kill-remorse-period]} :opts} @app-state]
(if-not kill-when-client-disconnects?
"Server kill is disabled"
(do (println "Client requested kill. Will stop server in 5 seconds.")
(swap! app-state assoc :am-i-about-to-kill-myself? true)
(future
(Thread/sleep (-> @app-state :opts :kill-when-client-disconnects?))
(if (-> @app-state :am-i-about-to-kill-myself?)
(System/exit 0)
(println "kill canceled")))
"OK"))))
(let [msg (cl-format nil
"Client requested kill. Will stop server in ~d second~:*~P"
(quot kill-remorse-period 1000))]
(println msg)
(swap! app-state assoc :am-i-about-to-kill-myself? true)
(future
(Thread/sleep kill-remorse-period)
(if (-> @app-state :am-i-about-to-kill-myself?)
(System/exit 0)
(println "kill canceled")))
msg))))

(defn stop-kill-countdown!
[app-state]
Expand All @@ -147,7 +161,6 @@
files (rename-keys (group-by #(.exists %) files) {false :non-existing true :existing})
response (into {} (map (fn [[key files]] [key (seq (map #(.getCanonicalPath %) files))]) files))]
(swap! app-state assoc :org-files-and-dirs (:existing files))
(prn response)
(pr-str response)))

(defn http-get-clocks [app-state from to]
Expand Down

0 comments on commit 53eccdf

Please sign in to comment.