mirror of
https://github.com/discourse/discourse.git
synced 2025-06-19 22:23:04 +08:00
FEATURE: Add automation statistics tracking to Automation (#31921)
introduces comprehensive statistics tracking for the Discourse Automation plugin, allowing users to monitor the performance and execution patterns of their automations: - Add `discourse_automation_stats` table to track execution metrics including run counts, execution times, and performance data - Create a new `Stat` model to handle tracking and retrieving automation statistics - Update the admin UI to display automation stats (runs today/this week/month and last run time) - Modernize the automation list interface using Glimmer components - Replace the older enable/disable icon with a toggle switch for better UX - Add schema annotations to existing models for better code documentation - Include extensive test coverage for the new statistics functionality This helps administrators understand how their automations are performing and identify potential bottlenecks or optimization opportunities. --------- Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com> Co-authored-by: Ted Johansson <ted@discourse.org>
This commit is contained in:
@ -17,6 +17,8 @@ module DiscourseAutomation
|
||||
dependent: :delete_all,
|
||||
foreign_key: "automation_id"
|
||||
|
||||
has_many :stats, class_name: "DiscourseAutomation::Stat", dependent: :delete_all
|
||||
|
||||
validates :script, presence: true
|
||||
validate :validate_trigger_fields
|
||||
|
||||
@ -137,8 +139,10 @@ module DiscourseAutomation
|
||||
if scriptable.background && !running_in_background
|
||||
trigger_in_background!(context)
|
||||
else
|
||||
triggerable&.on_call&.call(self, serialized_fields)
|
||||
scriptable.script.call(context, serialized_fields, self)
|
||||
Stat.log(id) do
|
||||
triggerable&.on_call&.call(self, serialized_fields)
|
||||
scriptable.script.call(context, serialized_fields, self)
|
||||
end
|
||||
end
|
||||
ensure
|
||||
DiscourseAutomation.set_active_automation(nil)
|
||||
@ -187,3 +191,17 @@ module DiscourseAutomation
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: discourse_automation_automations
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# name :string
|
||||
# script :string not null
|
||||
# enabled :boolean default(FALSE), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# last_updated_by_id :integer not null
|
||||
# trigger :string
|
||||
#
|
||||
|
Reference in New Issue
Block a user