Automation script Schedule PM with Data Explorer results not sending PMs

Discourse のホストインスタンスを使用しており、提供されている Automation プラグインのスクリプトとトリガーの範囲を利用していますが、「Schedule PM with data explorer results」スクリプトからの PM の受信に問題があります。

Automation トリガーは機能しており、Data Explorer クエリも実行されているように見えます (このクエリは手動で実行すると機能し、結果も生成されます)。しかし、これに続く PM は受信していません。受信者として自分自身、または「Admin」グループを試しましたが、どちらの場合も PM は受信されませんでした。

何か明白なことを見落としているのかわかりませんが、どんな助けでも感謝します。

「いいね!」 1

こんにちは、クリスチャンさん :wave:

/logs に関連するものは何か見えますか?

「いいね!」 2

同様の現象が発生していると思われます。

データエクスプローラーのクエリは実行されたようですが、

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'

これを 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_idt.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 は、一部の列のみが追加のレンダリングデータを提供する場合に null を含むため、packed ではなく sparse であるはずです。

正しいチェックはおそらく unless colrender[col_index].nil? になるでしょう。

また、このコードは、ActiveRecord クラスではないため、urlreltime、および html のレンダリングタイプを無視しているようです。

「いいね!」 6

私の方では、データエクスプローラーのクエリが何であれ、この自動化スクリプトを正常にトリガーできないようです。たとえば:

SELECT username from users
LIMIT 10

自動化から手動でトリガーするとエラー500が発生します:

メッセージ(3件報告あり)

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'

バックトレース

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'

環境

HTTP HOSTS: discourse.canapin.dev

これらの問題は、このPRで修正されるはずです。

「いいね!」 4

このトピックは2日後に自動的に閉じられました。返信はもう受け付けられません。