자동화 스크립트: Data Explorer 결과로 예약된 PM이 전송되지 않음

저희는 Discourse 호스팅 인스턴스를 사용하며, 제공되는 Automation 플러그인의 다양한 스크립트와 트리거를 활용하고 있습니다. 그러나 ‘Schedule PM with data explorer results’ 스크립트를 통해 개인 메시지(PM)를 받는 데 문제가 발생하고 있습니다.
Automation 트리거는 정상 작동하는 것으로 보이며, Data explorer 쿼리도 실행되고 있습니다(이 쿼리는 수동으로 실행하면 결과가 정상적으로 생성됩니다). 하지만 이 과정 이후에는 개인 메시지가 전혀 도착하지 않습니다. 수신자로 저 자신과 ‘Admin’ 그룹을 모두 시도해 보았지만, 두 경우 모두 개인 메시지가 수신되지 않았습니다.

무언가 명백한 부분을 놓치고 있는 것 같지만, 도움을 주시면 감사하겠습니다.

1개의 좋아요

안녕하세요, Christian :wave:

/logs에서 관련 항목이 보이나요?

2개의 좋아요

비슷한 현상을 겪고 있는 것 같습니다:

데이터 탐색기(Data Explorer) 쿼리가 실행된 것으로 보입니다:

하지만 개인 메시지(PM)가 전달되지 않습니다.

/logs에서 이 에러를 확인할 수 있습니다:

Message (5 copies reported)

Job exception: undefined method `to_sym' for nil:NilClass


Backtrace

/var/www/discourse/plugins/discourse-data-explorer/lib/result_to_markdown.rb:20:in `block (2 levels) in convert'
/var/www/discourse/plugins/discourse-data-explorer/lib/result_to_markdown.rb:18:in `each'
/var/www/discourse/plugins/discourse-data-explorer/lib/result_to_markdown.rb:18:in `each_with_index'
/var/www/discourse/plugins/discourse-data-explorer/lib/result_to_markdown.rb:18:in `block in convert'
/var/www/discourse/plugins/discourse-data-explorer/lib/result_to_markdown.rb:15:in `each'
/var/www/discourse/plugins/discourse-data-explorer/lib/result_to_markdown.rb:15:in `convert'
/var/www/discourse/plugins/discourse-data-explorer/lib/report_generator.rb:20:in `generate'
/var/www/discourse/plugins/discourse-data-explorer/plugin.rb:117:in `block (4 levels) in activate!'
/var/www/discourse/plugins/discourse-automation/app/models/discourse_automation/automation.rb:83:in `trigger!'
/var/www/discourse/plugins/discourse-automation/app/jobs/scheduled/discourse_automation_tracker.rb:36:in `run_pending_automation'

자동화를 수동으로 트리거하려고 하면 ‘500’ 에러가 발생하고, 로그에는 (약간 다른) 이 에러가 표시됩니다:

Message (4 copies reported)

NoMethodError (undefined method `to_sym' for nil:NilClass)
app/controllers/application_controller.rb:418:in `block in with_resolved_locale'
app/controllers/application_controller.rb:418:in `with_resolved_locale'
lib/middleware/omniauth_bypass_middleware.rb:74:in `call'
lib/content_security_policy/middleware.rb:12:in `call'
lib/middleware/anonymous_cache.rb:369:in `call'
config/initializers/100-quiet_logger.rb:20:in `call'
config/initializers/100-silence_logger.rb:29:in `call'
lib/middleware/enforce_hostname.rb:24:in `call'
lib/middleware/request_tracker.rb:228:in `call'

Backtrace

plugins/discourse-data-explorer/lib/result_to_markdown.rb:20:in `block (2 levels) in convert'
plugins/discourse-data-explorer/lib/result_to_markdown.rb:18:in `each'
plugins/discourse-data-explorer/lib/result_to_markdown.rb:18:in `each_with_index'
plugins/discourse-data-explorer/lib/result_to_markdown.rb:18:in `block in convert'
plugins/discourse-data-explorer/lib/result_to_markdown.rb:15:in `each'
plugins/discourse-data-explorer/lib/result_to_markdown.rb:15:in `convert'
plugins/discourse-data-explorer/lib/report_generator.rb:20:in `generate'
plugins/discourse-data-explorer/plugin.rb:117:in `block (4 levels) in activate!'
plugins/discourse-automation/app/models/discourse_automation/automation.rb:83:in `trigger!'
plugins/discourse-automation/app/controllers/discourse_automation/automations_controller.rb:10:in `trigger'

Contribute > Bug 채널로 넘겨서 누군가 살펴볼 수 있도록 해봅시다. :+1:

2개의 좋아요

조금 더 조사해 본 결과, 실행하려는 쿼리의 유형과 관련이 있을 것 같습니다. 아주 간단한 쿼리로 시도해 보니 실행하고 개인 메시지를 보내는 데 성공했습니다. 쿼리 내용을 공유해 주시겠어요?

1개의 좋아요

확인해 주셔서 감사합니다.
쿼리가 완전히 단순하지는 않고, 다음과 같은 형태입니다:

WITH
ua AS (
  SELECT target_topic_id, COUNT(id) FROM user_actions
  WHERE action_type = 15
  GROUP BY target_topic_id
)
SELECT 
  t.id, 
  t.title, 
  t.created_at, 
  t.last_posted_at, 
  t.views, 
  t.posts_count, 
  t.user_id, 
  t.last_post_user_id
FROM topics t
INNER JOIN users us ON us.id = t.user_id
LEFT JOIN ua ON ua.target_topic_id = t.id
WHERE t.deleted_at IS NULL
  AND t.closed = false
  AND t.archived = false
  AND t.visible = true
  AND ua.target_topic_id IS NULL
  AND us.username_lower != 'system'
  AND t.created_at > now() - INTERVAL '7' DAY
ORDER BY created_at DESC

말씀드린 대로, 수동으로 실행하면 결과가 정상적으로 생성됩니다.

1개의 좋아요

수동으로 실행한다는 것은 데이터 탐색기에서 쿼리를 트리거하는 것을 의미하는지, 아니면 자동화 플러그인에서 스크립트를 트리거하는 것을 의미하는 건가요?

1개의 좋아요

데이터 탐색기에서 가져온 정보입니다.

1개의 좋아요

데이터 탐색기가 맨 ID를 사용 가능한 링크로 변환할 때 수행하는 user_id 스타일의 마법 같은 것과 관련이 있는 것 같습니다. 리포트를 그대로 실행하면 여러분이 보고 계신 것과 동일한 오류가 발생하지만, SELECT에서 t.user_id와 t.last_post_user_id를 모두 제거하면 정상적으로 작동합니다.

해당 필드를 일반 사용자 이름으로 변환하면 자동화를 통해 정상적으로 작동하는 것 같습니다:


WITH
ua AS (
  SELECT target_topic_id, COUNT(id) FROM user_actions
  WHERE action_type = 15
  GROUP BY target_topic_id
)
SELECT 
  t.id, 
  t.title, 
  t.created_at, 
  t.last_posted_at, 
  t.views, 
  t.posts_count, 
  us.username, 
  u2.username
FROM topics t
INNER JOIN users us ON us.id = t.user_id
LEFT JOIN ua ON ua.target_topic_id = t.id
JOIN users u2 ON u2.id = t.last_post_user_id
WHERE t.deleted_at IS NULL
  AND t.closed = false
  AND t.archived = false
  AND t.visible = true
  AND ua.target_topic_id IS NULL
  AND us.username_lower != 'system'
  AND t.created_at > now() - INTERVAL '7' DAY
ORDER BY created_at DESC

다만, 더 전문적인 분에게 연락하여 자세히 살펴봐 달라고 요청했습니다. :+1: :slight_smile:


별개로, 여러분의 쿼리가 원하는 대로 작동하는지 확신이 서지 않습니다. 결과에 개인 메시지(PM)가 많이 표시되고 있는데, ‘Solution’(해결책) 관련 설정과 어떤 연관이 있는 건가요?

3개의 좋아요

감사합니다. 사용자 ID를 수정해서 시도해 보겠습니다.

이 쿼리는 제가 처음 작성한 것이 아니라서, 원하시는 결과를 실제로 반환하는지 아직 확인하지 못했습니다. 그래서 아마도 다시 작성할 것 같습니다.

2개의 좋아요

문제는 이 줄입니다: https://github.com/discourse/discourse-data-explorer/blob/705753216cc632b4f6505d2000926ab3b73d8628/lib/result_to_markdown.rb#L20

related = relations.dig(colrender[col_index].to_sym) if col_index < colrender.size

끝부분의 if 조건이 올바르지 않습니다: colrender는 packed(밀집)형이 아니라 sparse(희소)형이어야 합니다. 일부 컬럼만 추가 렌더링 데이터를 제공하는 경우 null을 포함하게 됩니다.

올바른 확인 조건은 아마도 unless colrender[col_index].nil?일 것입니다.

또한, 이 코드는 url, reltime, html 렌더링 유형이 ActiveRecord 클래스가 아니기 때문에 이를 무시하고 있는 것으로 보입니다.

6개의 좋아요

저의 경우, 데이터 탐색기 쿼리가 무엇이든 이 자동화 스크립트를 성공적으로 트리거할 수 없는 것 같습니다. 예를 들어:

SELECT username from users
LIMIT 10

자동화에서 수동으로 트리거할 때 500 오류 발생:

Message (3 copies reported)

TypeError (Nil is not a valid JSON source.)
app/controllers/application_controller.rb:418:in `block in with_resolved_locale'
app/controllers/application_controller.rb:418:in `with_resolved_locale'
lib/middleware/omniauth_bypass_middleware.rb:74:in `call'
lib/content_security_policy/middleware.rb:12:in `call'
lib/middleware/anonymous_cache.rb:369:in `call'
config/initializers/100-quiet_logger.rb:20:in `call'
config/initializers/100-silence_logger.rb:29:in `call'
lib/middleware/enforce_hostname.rb:24:in `call'
lib/middleware/request_tracker.rb:228:in `call'

Backtrace

plugins/discourse-data-explorer/lib/report_generator.rb:42:in `parse'
plugins/discourse-data-explorer/lib/report_generator.rb:42:in `params_to_hash'
plugins/discourse-data-explorer/lib/report_generator.rb:15:in `generate'
plugins/discourse-data-explorer/plugin.rb:117:in `block (4 levels) in activate!'
plugins/discourse-automation/app/models/discourse_automation/automation.rb:83:in `trigger!'
plugins/discourse-automation/app/controllers/discourse_automation/automations_controller.rb:10:in `trigger'
actionpack (7.0.4.3) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
actionpack (7.0.4.3) lib/abstract_controller/base.rb:215:in `process_action'
actionpack (7.0.4.3) lib/action_controller/metal/rendering.rb:53:in `process_action'
actionpack (7.0.4.3) lib/abstract_controller/callbacks.rb:234:in `block in process_action'

Env

HTTP HOSTS: discourse.canapin.dev

이러한 문제들은 이 PR을 통해 수정되어야 합니다:

4개의 좋아요

이 주제는 2일 후 자동으로 닫혔습니다. 더 이상 답변이 허용되지 않습니다.