Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alexander Artemenko
committed
Sep 30, 2019
1 parent
2fea1b4
commit 199c96c
Showing
8 changed files
with
311 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/quicklisp/ | ||
/.qlot/ | ||
/src/bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,12 @@ | ||
(defsystem progressor | ||
:class :package-inferred-system | ||
:version "0.1.0" | ||
:description "A client/server to store long running jobs progress state." | ||
:homepage "https://github.com/40ants/progressor" | ||
:pathname "src" | ||
:depends-on ("progressor/server")) | ||
:defsystem-depends-on (:deploy) | ||
:build-operation "deploy-op" | ||
:build-pathname "progressor" | ||
:entry-point "progressor/cli/main:main" | ||
:depends-on ("progressor/server" | ||
"progressor/cli/main")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
(defpackage #:progressor/cli/main | ||
(:use #:cl #:defmain) | ||
(:import-from #:progressor/client | ||
#:list-progresses) | ||
(:import-from #:progressor/models | ||
#:get-description | ||
#:print-progress) | ||
(:shadow #:list) | ||
(:export | ||
#:main)) | ||
(in-package progressor/cli/main) | ||
|
||
|
||
(defcommand (main list) () | ||
(handler-case | ||
(let ((progresses (list-progresses))) | ||
(cond | ||
(progresses | ||
(loop for progress in progresses | ||
do (format *standard-output* | ||
"~A~%" | ||
(get-description progress)) | ||
(print-progress progress :stream *standard-output*) | ||
(format *standard-output* | ||
"~%"))) | ||
(t (format t "No jobs.~%")))) | ||
(usocket:connection-refused-error () | ||
(format *error-output* "Unable to connect to the server.") | ||
(values 1)))) | ||
|
||
|
||
(defcommand (main server) () | ||
(format t "TODO: implement a server command.")) | ||
|
||
|
||
(defmain main (&subcommand)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
(defpackage #:progressor/client | ||
(:use #:cl) | ||
(:import-from #:jsonrpc | ||
#:client-connect | ||
#:make-client) | ||
(:export | ||
#:create-progress | ||
#:list-progresses)) | ||
(in-package progressor/client) | ||
|
||
|
||
(defun restore-lisp-object (type obj) | ||
(apply #'make-instance | ||
type | ||
(loop for key being the hash-keys in obj | ||
using (hash-value value) | ||
appending | ||
(list (alexandria:make-keyword (string-upcase key)) | ||
value)))) | ||
|
||
|
||
(defun make-call (method &rest args) | ||
"Makes an RPC call with keyword arguments." | ||
(let ((client (make-client))) | ||
(client-connect client | ||
:url "http://localhost:7890" | ||
:mode :tcp) | ||
(jsonrpc:call client method (alexandria:plist-hash-table | ||
(loop for (key value) on args by #'cddr | ||
appending (list (symbol-name key) | ||
value)))))) | ||
|
||
|
||
(defun create-progress (id &key total | ||
(current 0) | ||
description) | ||
(check-type id string) | ||
|
||
(when (string= id "") | ||
(error "Id should be a non empty string")) | ||
|
||
(restore-lisp-object | ||
'progressor/models:progress | ||
(make-call "create" | ||
:id id | ||
:total total | ||
:current current | ||
:description description))) | ||
|
||
|
||
(defun increment-progress (id &optional (value 1)) | ||
(check-type id string) | ||
|
||
(when (string= id "") | ||
(error "Id should be a non empty string")) | ||
|
||
(restore-lisp-object | ||
'progressor/models:progress | ||
(make-call "increment" | ||
:id id | ||
:value value))) | ||
|
||
(defun delete-progress (id) | ||
(check-type id string) | ||
|
||
(when (string= id "") | ||
(error "Id should be a non empty string")) | ||
|
||
(make-call "delete" | ||
:id id)) | ||
|
||
|
||
(defun list-progresses () | ||
(mapcar (alexandria:curry #'restore-lisp-object | ||
'progressor/models:progress) | ||
(make-call "list"))) | ||
|
||
|
||
(defun clear-progresses () | ||
(make-call "clear")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.