Browse code
feat: add basic archiver
Edward authored on 30/11/2020 01:54:20
Showing 1 changed files
Showing 1 changed files
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,33 @@ |
1 |
+ |
|
2 |
+(defun archive-article (client message group target) |
|
3 |
+ (let* ((target (parse-namestring target)) |
|
4 |
+ (group-path (merge-pathnames (make-pathname :directory (list :relative group)) |
|
5 |
+ target)) |
|
6 |
+ (article-path (merge-pathnames (make-pathname :name (princ-to-string message) |
|
7 |
+ :type "eml") |
|
8 |
+ group-path))) |
|
9 |
+ (ensure-directories-exist article-path) |
|
10 |
+ (unless (probe-file article-path) |
|
11 |
+ (with-open-file (s article-path |
|
12 |
+ :direction :output :if-exists :supersede :if-does-not-exist :create) |
|
13 |
+ (princ (cl-nntp:article client :article-number message) |
|
14 |
+ s))))) |
|
15 |
+ |
|
16 |
+(defun archiver (server group target) |
|
17 |
+ (let ((client (cl-nntp::make-client))) |
|
18 |
+ (cl-nntp:connect server 119 client) |
|
19 |
+ (cl-nntp:group group client) |
|
20 |
+ (loop for message-num = (mp:process-wait-for-event) |
|
21 |
+ until (eql message-num :quit) |
|
22 |
+ do |
|
23 |
+ (archive-article client message-num group target)))) |
|
24 |
+ |
|
25 |
+(defun start-workers (count &rest args) |
|
26 |
+ (coerce (loop repeat count |
|
27 |
+ for x from 0 |
|
28 |
+ collect (apply 'mp:process-run-function |
|
29 |
+ (format nil "archiver ~d" x) |
|
30 |
+ () |
|
31 |
+ 'archiver |
|
32 |
+ args)) |
|
33 |
+ 'vector)) |