14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
;;======================================================================
;; Methodology
;;
;; Connect to the server, the server delays the appropriate time (if
;; any) and then launch the task.
;;
(use nanomsg posix regex)
(define req (nn-socket 'req))
;; get needed stuff from commandline
;;
(define hostport #f)
(define cmd '())
|
|
|
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
;;======================================================================
;; Methodology
;;
;; Connect to the server, the server delays the appropriate time (if
;; any) and then launch the task.
;;
(use nanomsg posix regex message-digest md5)
(define req (nn-socket 'req))
;; get needed stuff from commandline
;;
(define hostport #f)
(define cmd '())
|
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
(nn-connect req (conc "tcp://" hostport)) ;; xena:22022")
(define (client-send-receive soc msg)
(nn-send soc msg)
(nn-recv soc))
;; (define ((talk-to-server soc))
;; (let loop ((cnt 200000))
;; (let ((name (list-ref '("Matt" "Tom" "Bob" "Jill" "James" "Jane")(random 6))))
;; ;; (print "Sending " name)
;; ;; (print
;; (client-send-receive req name) ;; )
;; (if (> cnt 0)(loop (- cnt 1)))))
;; (print (client-send-receive req "quit"))
;; (nn-close req)
;; (exit))
;;
(thread-start! (lambda ()
(thread-sleep! 60)
(print "Give up on waiting for the server")
(nn-close req)
;; (exit)
))
(thread-join! (thread-start! (lambda ()
(print (client-send-receive req (conc (current-user-name) "@" (get-host-name)))))))
(process-execute (car cmd) (cdr cmd))
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
|
>
>
>
>
|
|
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
(nn-connect req (conc "tcp://" hostport)) ;; xena:22022")
(define (client-send-receive soc msg)
(nn-send soc msg)
(nn-recv soc))
;; Generate a unique signature for this client location
;;
(define (make-signature)
(message-digest-string (md5-primitive)
(with-output-to-string
(lambda ()
(write (current-directory))))))
;; (define ((talk-to-server soc))
;; (let loop ((cnt 200000))
;; (let ((name (list-ref '("Matt" "Tom" "Bob" "Jill" "James" "Jane")(random 6))))
;; ;; (print "Sending " name)
;; ;; (print
;; (client-send-receive req name) ;; )
;; (if (> cnt 0)(loop (- cnt 1)))))
;; (print (client-send-receive req "quit"))
;; (nn-close req)
;; (exit))
;;
(define (get-delay signature)
(let* ((full-msg (client-send-receive req (conc (current-user-name) "@" (get-host-name) ":" signature))))
(print "Got " full-msg)
(let* ((reply-msg (string-match "^([\\d\\.]+)\\s+(.*)$" full-msg))
(delay-time (if (> (length reply-msg) 2)
(string->number (cadr reply-msg))
1)) ;; fall back to one sec delay
(msg (if (> (length reply-msg) 2)
(caddr reply-msg)
full-msg)))
(values delay-time msg))))
(let ((signature (make-signature)))
(thread-start! (lambda ()
(thread-sleep! 60)
(print "Give up on waiting for the server")
(nn-close req)
;; (exit)
))
(thread-join! (thread-start! (lambda ()
(let-values
(((delay-time msg)(get-delay signature)))
(print "INFO: sleeping " delay-time " seconds per request of queuefeeder server")
(thread-sleep! delay-time)
(print "INFO: done waiting, now executing requested task."))))))
(process-execute (car cmd) (cdr cmd))
|