Skip to content

Conversation

@paulodiovani
Copy link

@paulodiovani paulodiovani commented Sep 5, 2025

Note

This replaces #1251

Summary

Introduces the ability to collect and display task outputs by optionally adding and output method. This allows to save task logs or produce results to be displayed in the UI.

The storage of this output, if any, is the responsibility of the task class.

Why This Change?

This expands the usage of maintenance tasks to allow generating outputs that can be used later, for example:

  • better visibility of task progress execution
  • inspection of data without needing to access console or database directly
  • exporting data from one environment to another

Implementation details

Database Changes

No database/schema changes.

Core Functionality

  • Include a run_data field and method available for tasks, this field includes a subset of the Run instance data available through a Proc
  • Include an output method in the MaintenanceTasks::Task class, intended to be overwritten
  • Delegates Run#output to Task#output for easier use in views

UI Changes

  • Added new _output.html.erb partial to display task output
  • Output is shown in a formatted box on the run details page
  • Only displayed when output is not nil

Usage example

This example task saves the output from each process call to a class instance variable.

module Maintenance
  class CacheOutputTask < MaintenanceTasks::Task
    @cache = {}

    class << self
      attr_accessor :cache
    end

    def collection
      [1, 2]
    end

    def process(number)
      self.output = output.to_s + "Completed number #{number}.\n"
    end

    def output=(message)
      self.class.cache[run_data.id] = message
    end

    def output
      self.class.cache[run_data.id]
    end
  end
end

Screenshot

image

Backward Compatibility

  • Feature is optional
  • No changes are required for existing tasks

- add new output task for testing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant