Skip to content

MBS-10402: Add async report generation#169

Open
PM84 wants to merge 5 commits intomoodleou:mainfrom
bycs-lp:MBS-10402_Report_async_execution
Open

MBS-10402: Add async report generation#169
PM84 wants to merge 5 commits intomoodleou:mainfrom
bycs-lp:MBS-10402_Report_async_execution

Conversation

@PM84
Copy link

@PM84 PM84 commented Oct 19, 2025

Fixes #168
And does LOTS of coding style fixes to fit the new moodle coding styles

This PR consists of two commits.

  1. Fixing coding styles because of new moodle CS.
  2. Implementing new functionality manual_async

The manual_async runable mode enables administrators to execute resource-intensive SQL queries asynchronously without blocking the web interface, improving user experience for long-running reports.

User workflow:

  1. User triggers report execution via "Run in background" action
  2. System creates an execution record with pending status
  3. Adhoc task is queued for processing
  4. User receives immediate confirmation with link to executions overview
  5. Background task executes query and stores results as CSV
  6. User receives notification upon completion
  7. Results are downloaded via file storage API

Technical implementation

Core components:

Adhoc task: \report_customsql\task\execute_query_adhoc handles query execution
Execution manager: \report_customsql\local\execution_manager manages lifecycle and status transitions
Executions table: \report_customsql\table\executions_table provides filterable overview of all executions
File storage: Results stored in Moodle file API using report_customsql component and execution filearea

Key features:

  • Streaming CSV output for memory efficiency
  • Row-by-row processing to handle large result sets
  • Capability-based access control (report/customsql:executebackground)
  • Cancellation support with graceful shutdown
  • Automated cleanup task for retention management
  • Notifications API integration

New Capabilities required

  • report/customsql:executebackground - Trigger background execution
  • report/customsql:viewallexecutions - View all users' executions (optional)

Configuration

Administrators can configure via plugin settings:

  • Maximum execution retention period
  • Maximum concurrent executions
  • File storage limits

Testing

  • Extensive phpunit tests included
  • Extensive behat tests included

Comparison: manual vs manual_async

Aspect manual manual_async
Execution Synchronous Asynchronous
UI blocking Yes No
Result delivery Immediate Queued notification
Memory usage Limited by PHP Streaming (scalable)
Timeout risk High None
User experience Wait on page Continue working

@PM84 PM84 force-pushed the MBS-10402_Report_async_execution branch from 82470a3 to a07186e Compare October 19, 2025 20:26
@PM84 PM84 force-pushed the MBS-10402_Report_async_execution branch 5 times, most recently from 8bc5ab7 to 79309c0 Compare October 21, 2025 21:26
@PM84 PM84 force-pushed the MBS-10402_Report_async_execution branch from 79309c0 to 93433b0 Compare October 22, 2025 06:41
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.

Background/Async Query Execution with File Storage

1 participant