about summary refs log tree commit diff
path: root/app/workers/log_worker.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/workers/log_worker.rb')
-rw-r--r--app/workers/log_worker.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/app/workers/log_worker.rb b/app/workers/log_worker.rb
new file mode 100644
index 000000000..556820e16
--- /dev/null
+++ b/app/workers/log_worker.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+class LogWorker
+  include Sidekiq::Worker
+
+  sidekiq_options unique: :until_executed
+
+  def perform(log_text)
+    logger_id = ENV['LOG_USER'].to_i
+    return true if logger_id == 0
+
+    logger = Account.find_by(id: logger_id)
+    return true if logger.nil?
+
+    PostStatusService.new.call(
+      logger,
+      created_at: Time.now.utc,
+      text: log_text.strip,
+      tags: ['monsterpit.admin.log'],
+      visibility: :unlisted,
+      local_only: true,
+      content_type: 'text/plain',
+      language: 'en',
+    )
+  rescue ActiveRecord::RecordNotFound, ActiveRecord::RecordInvalid
+    true
+  end
+end