-
Notifications
You must be signed in to change notification settings - Fork 101
Feature: Add optional output to maintenance task to display output #1251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
scotttam
wants to merge
1
commit into
main
Choose a base branch
from
add_output_column
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+224
−6
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <% if output.present? %> | ||
| <div class="content"> | ||
| <h6 class="title is-6">Task Output</h6> | ||
| <pre class="box has-background-light"><%= output %></pre> | ||
| </div> | ||
| <hr> | ||
| <% end %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
db/migrate/20250117000000_add_output_to_maintenance_tasks_runs.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class AddOutputToMaintenanceTasksRuns < ActiveRecord::Migration[7.0] | ||
| def change | ||
| add_column(:maintenance_tasks_runs, :output, :text) | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Maintenance | ||
| class OutputTestTask < MaintenanceTasks::Task | ||
| def collection | ||
| (1..5).to_a | ||
| end | ||
|
|
||
| def process(element) | ||
| log_output("Processing element #{element}") | ||
| log_output("Square of #{element} is #{element * element}") | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "test_helper" | ||
|
|
||
| module MaintenanceTasks | ||
| class TaskOutputTest < ActiveSupport::TestCase | ||
| class TestTaskWithOutput < Task | ||
| def collection | ||
| [1, 2, 3] | ||
| end | ||
|
|
||
| def process(item) | ||
| log_output("Processing item #{item}") | ||
| log_output("Item #{item} squared is #{item * item}") | ||
| end | ||
| end | ||
|
|
||
| class NoCollectionTaskWithOutput < Task | ||
| no_collection | ||
|
|
||
| def process | ||
| log_output("Starting task") | ||
| log_output("Task completed") | ||
| end | ||
| end | ||
|
|
||
| test "task logs output during processing" do | ||
| run = Run.create!(task_name: "MaintenanceTasks::TaskOutputTest::TestTaskWithOutput") | ||
| task = TestTaskWithOutput.new | ||
| task.instance_variable_set(:@run, run) | ||
|
|
||
| task.process(5) | ||
| run.reload | ||
|
|
||
| assert_equal "Processing item 5\nItem 5 squared is 25", run.output | ||
| end | ||
|
|
||
| test "output accumulates across multiple process calls" do | ||
| run = Run.create!(task_name: "MaintenanceTasks::TaskOutputTest::TestTaskWithOutput") | ||
| task = TestTaskWithOutput.new | ||
| task.instance_variable_set(:@run, run) | ||
|
|
||
| task.process(1) | ||
| task.process(2) | ||
| run.reload | ||
|
|
||
| expected_output = "Processing item 1\nItem 1 squared is 1\n" \ | ||
| "Processing item 2\nItem 2 squared is 4" | ||
| assert_equal expected_output, run.output | ||
| end | ||
|
|
||
| test "no collection task can log output" do | ||
| run = Run.create!(task_name: "MaintenanceTasks::TaskOutputTest::NoCollectionTaskWithOutput") | ||
| task = NoCollectionTaskWithOutput.new | ||
| task.instance_variable_set(:@run, run) | ||
|
|
||
| task.process | ||
| run.reload | ||
|
|
||
| assert_equal "Starting task\nTask completed", run.output | ||
| end | ||
|
|
||
| test "log_output does nothing when run is not set" do | ||
| task = TestTaskWithOutput.new | ||
|
|
||
| # Should not raise error | ||
| assert_nothing_raised do | ||
| task.process(1) | ||
| end | ||
| end | ||
|
|
||
| test "run appends output correctly" do | ||
| run = Run.create!(task_name: "MaintenanceTasks::TaskOutputTest::TestTaskWithOutput") | ||
|
|
||
| run.append_output("First line") | ||
| run.reload | ||
| assert_equal "First line", run.output | ||
|
|
||
| run.append_output("Second line") | ||
| run.reload | ||
| assert_equal "First line\nSecond line", run.output | ||
| end | ||
|
|
||
| test "output persists across run status changes" do | ||
| run = Run.create!(task_name: "MaintenanceTasks::TaskOutputTest::TestTaskWithOutput") | ||
|
|
||
| run.append_output("Test output content") | ||
| assert_equal "Test output content", run.reload.output | ||
|
|
||
| run.running! | ||
| assert_equal "Test output content", run.reload.output | ||
|
|
||
| run.succeeded! | ||
| assert_equal "Test output content", run.reload.output | ||
| end | ||
|
|
||
| test "append_output handles nil output column gracefully" do | ||
| # Simulate missing output column by stubbing column_names | ||
| columns_without_output = Run.column_names.dup - ["output"] | ||
| Run.stubs(:column_names).returns(columns_without_output) | ||
| run = Run.create!(task_name: "MaintenanceTasks::TaskOutputTest::TestTaskWithOutput") | ||
|
|
||
| # Should not raise error | ||
| assert_nothing_raised do | ||
| run.append_output("Test") | ||
| end | ||
| ensure | ||
| Run.unstub(:column_names) | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately I don't think we can afford adding a feature like that to the framework. It may work okay for smaller applications but for large applications with a lot of rows to iterate over the approach of transferring large chunks for data back-and-forth doesn't scale well