Skip to content

Commit

Permalink
OY-5029 Käynnistetään virusskannauksen tulosten prosessointi vain lii…
Browse files Browse the repository at this point in the history
…teri-palvelussa
  • Loading branch information
jkorri committed Jan 8, 2025
1 parent 3803739 commit 5eb1a73
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions src/liiteri/virus_scan.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
[liiteri.files.file-store :as file-store]
[liiteri.sqs-client :refer [get-sqs-client]]
[taoensso.timbre :as log]
[cheshire.core :as json])
[cheshire.core :as json]
[environ.core :refer [env]])
(:import [com.amazonaws.services.sqs.model ReceiveMessageRequest]
[java.util.concurrent Executors TimeUnit ScheduledFuture]))

Expand Down Expand Up @@ -66,26 +67,28 @@
component/Lifecycle

(start [this]
(let [sqs-request-scan-client (get-sqs-client)
sqs-poll-results-client (get-sqs-client)
request-queue-name (get-in config [:bucketav :scan-request-queue-name])
request-queue-url (-> (.getQueueUrl sqs-request-scan-client request-queue-name)
(.getQueueUrl))
result-queue-name (get-in config [:bucketav :scan-result-queue-name])
result-queue-url (-> (.getQueueUrl sqs-poll-results-client result-queue-name)
(.getQueueUrl))
poll-interval (get-in config [:bucketav :poll-interval-seconds])
s3-bucket (get-in config [:file-store :s3 :bucket])
(if (not (= "liiteri-background" (:app env)))
(let [sqs-request-scan-client (get-sqs-client)
sqs-poll-results-client (get-sqs-client)
request-queue-name (get-in config [:bucketav :scan-request-queue-name])
request-queue-url (-> (.getQueueUrl sqs-request-scan-client request-queue-name)
(.getQueueUrl))
result-queue-name (get-in config [:bucketav :scan-result-queue-name])
result-queue-url (-> (.getQueueUrl sqs-poll-results-client result-queue-name)
(.getQueueUrl))
poll-interval (get-in config [:bucketav :poll-interval-seconds])
s3-bucket (get-in config [:file-store :s3 :bucket])

scheduler (Executors/newScheduledThreadPool 1)
virus-scan #(while (< 0 (poll-scan-results sqs-poll-results-client result-queue-url db storage-engine config)))
time-unit TimeUnit/SECONDS
virus-scan-future (.scheduleAtFixedRate scheduler virus-scan 0 poll-interval time-unit)]
(log/info (str "Started virus scan results polling process, restarting at " poll-interval " " time-unit " intervals."))
(assoc this :virus-scan-future virus-scan-future
:request-queue-url request-queue-url
:sqs-request-scan-client sqs-request-scan-client
:s3-bucket s3-bucket)))
scheduler (Executors/newScheduledThreadPool 1)
virus-scan #(while (< 0 (poll-scan-results sqs-poll-results-client result-queue-url db storage-engine config)))
time-unit TimeUnit/SECONDS
virus-scan-future (.scheduleAtFixedRate scheduler virus-scan 0 poll-interval time-unit)]
(log/info (str "Started virus scan results polling process, restarting at " poll-interval " " time-unit " intervals."))
(assoc this :virus-scan-future virus-scan-future
:request-queue-url request-queue-url
:sqs-request-scan-client sqs-request-scan-client
:s3-bucket s3-bucket))
this))

(stop [this]
(when-let [^ScheduledFuture virus-scan-future (:virus-scan-future this)]
Expand Down

0 comments on commit 5eb1a73

Please sign in to comment.