diff --git a/backend/resources/log4j2.xml b/backend/resources/log4j2.xml index 5033f4726..3a0d04e3f 100644 --- a/backend/resources/log4j2.xml +++ b/backend/resources/log4j2.xml @@ -11,14 +11,7 @@ - - - - - - - - + diff --git a/backend/src/app/config.clj b/backend/src/app/config.clj index a09efb92e..5bb0119b2 100644 --- a/backend/src/app/config.clj +++ b/backend/src/app/config.clj @@ -308,6 +308,7 @@ (def default-flags [:enable-backend-api-doc + :enable-backend-worker :enable-secure-session-cookies]) (defn- parse-flags diff --git a/backend/src/app/main.clj b/backend/src/app/main.clj index d02a91d60..7700c8985 100644 --- a/backend/src/app/main.clj +++ b/backend/src/app/main.clj @@ -234,50 +234,6 @@ :app.rpc/routes {:methods (ig/ref :app.rpc/methods)} - :app.worker/worker - {:executor (ig/ref [::worker :app.worker/executor]) - :tasks (ig/ref :app.worker/registry) - :metrics (ig/ref :app.metrics/metrics) - :pool (ig/ref :app.db/pool)} - - :app.worker/cron - {:executor (ig/ref [::worker :app.worker/executor]) - :scheduler (ig/ref :app.worker/scheduler) - :tasks (ig/ref :app.worker/registry) - :pool (ig/ref :app.db/pool) - :entries - [{:cron #app/cron "0 0 0 * * ?" ;; daily - :task :file-gc} - - {:cron #app/cron "0 0 * * * ?" ;; hourly - :task :file-xlog-gc} - - {:cron #app/cron "0 0 0 * * ?" ;; daily - :task :storage-gc-deleted} - - {:cron #app/cron "0 0 0 * * ?" ;; daily - :task :storage-gc-touched} - - {:cron #app/cron "0 0 0 * * ?" ;; daily - :task :session-gc} - - {:cron #app/cron "0 0 0 * * ?" ;; daily - :task :objects-gc} - - {:cron #app/cron "0 0 0 * * ?" ;; daily - :task :tasks-gc} - - {:cron #app/cron "0 30 */3,23 * * ?" - :task :telemetry} - - (when (contains? cf/flags :audit-log-archive) - {:cron #app/cron "0 */5 * * * ?" ;; every 5m - :task :audit-log-archive}) - - (when (contains? cf/flags :audit-log-gc) - {:cron #app/cron "0 0 0 * * ?" ;; daily - :task :audit-log-gc})]} - :app.worker/registry {:metrics (ig/ref :app.metrics/metrics) :tasks @@ -394,14 +350,62 @@ {:directory (cf/get :storage-assets-fs-directory)} }) + +(def worker-config + { :app.worker/cron + {:executor (ig/ref [::worker :app.worker/executor]) + :scheduler (ig/ref :app.worker/scheduler) + :tasks (ig/ref :app.worker/registry) + :pool (ig/ref :app.db/pool) + :entries + [{:cron #app/cron "0 0 0 * * ?" ;; daily + :task :file-gc} + + {:cron #app/cron "0 0 * * * ?" ;; hourly + :task :file-xlog-gc} + + {:cron #app/cron "0 0 0 * * ?" ;; daily + :task :storage-gc-deleted} + + {:cron #app/cron "0 0 0 * * ?" ;; daily + :task :storage-gc-touched} + + {:cron #app/cron "0 0 0 * * ?" ;; daily + :task :session-gc} + + {:cron #app/cron "0 0 0 * * ?" ;; daily + :task :objects-gc} + + {:cron #app/cron "0 0 0 * * ?" ;; daily + :task :tasks-gc} + + {:cron #app/cron "0 30 */3,23 * * ?" + :task :telemetry} + + (when (contains? cf/flags :audit-log-archive) + {:cron #app/cron "0 */5 * * * ?" ;; every 5m + :task :audit-log-archive}) + + (when (contains? cf/flags :audit-log-gc) + {:cron #app/cron "0 0 0 * * ?" ;; daily + :task :audit-log-gc})]} + + :app.worker/worker + {:executor (ig/ref [::worker :app.worker/executor]) + :tasks (ig/ref :app.worker/registry) + :metrics (ig/ref :app.metrics/metrics) + :pool (ig/ref :app.db/pool)}}) + (def system nil) (defn start [] - (ig/load-namespaces system-config) + (ig/load-namespaces (merge system-config worker-config)) (alter-var-root #'system (fn [sys] (when sys (ig/halt! sys)) (-> system-config + (cond-> (contains? cf/flags :backend-worker) + (merge worker-config)) (ig/prep) (ig/init)))) (l/info :msg "welcome to penpot" diff --git a/backend/src/app/rpc.clj b/backend/src/app/rpc.clj index 477b0a633..804a62412 100644 --- a/backend/src/app/rpc.clj +++ b/backend/src/app/rpc.clj @@ -186,7 +186,7 @@ spec (or (::sv/spec mdata) (s/spec any?)) auth? (:auth mdata true)] - (l/trace :action "register" :name (::sv/name mdata)) + (l/debug :hint "register method" :name (::sv/name mdata)) (with-meta (fn [{:keys [::request] :as params}] ;; Raise authentication error when rpc method requires auth but diff --git a/backend/src/app/worker.clj b/backend/src/app/worker.clj index 52ce5ddd4..c7259b24a 100644 --- a/backend/src/app/worker.clj +++ b/backend/src/app/worker.clj @@ -224,7 +224,7 @@ :name (d/name name) :queue (d/name queue)) (do - (l/info :hint "worker started" + (l/info :hint "worker initialized" :name (d/name name) :queue (d/name queue)) (event-loop cfg))) @@ -565,7 +565,7 @@ (l/info :hint "registry initialized" :tasks (count tasks)) (reduce-kv (fn [res k v] (let [tname (name k)] - (l/trace :hint "register task" :name tname) + (l/debug :hint "register task" :name tname) (assoc res k (wrap-task-handler metrics tname v)))) {} tasks)) diff --git a/backend/test/app/test_helpers.clj b/backend/test/app/test_helpers.clj index 8849ac3cc..92642d171 100644 --- a/backend/test/app/test_helpers.clj +++ b/backend/test/app/test_helpers.clj @@ -51,6 +51,7 @@ (defn state-init [next] (let [config (-> main/system-config + (merge main/worker-config) (assoc-in [:app.msgbus/msgbus :redis-uri] (:redis-uri config)) (assoc-in [:app.db/pool :uri] (:database-uri config)) (assoc-in [:app.db/pool :username] (:database-username config)) @@ -75,9 +76,7 @@ :app.loggers.database/reporter :app.loggers.zmq/receiver :app.worker/cron - :app.worker/worker) - (d/deep-merge - {:app.tasks.file-gc/handler {:max-age (dt/duration 300)}})) + :app.worker/worker)) _ (ig/load-namespaces config) system (-> (ig/prep config) (ig/init))]