Extension:MassMessage/Progress tracking

From mediawiki.org

When people send out a mass message, they have an interest in tracking the progress of their delivery to make sure it actually goes out. Currently this is a manual process, you need to check the account's contributions yourself as well as any errors. For cross-wiki deliveries this is an even more exhausting task. Previously the job queue gave some insight into how many jobs were queued, but that was always an estimate at best and now with the EventBus based system, it's totally useless.

The goal of this project will be to use a database table to keep track of the progress of a delivery and then send a notification when it's done. As a side-effect, we will also use this tracker to eliminate the biggest issue in MassMessage today: double posting.

Database schema[edit]

Two new database tables will be added:

  • massmessage_deliveries: Each delivery gets one row here, with subject and pagelist, plus the origin wiki, with a bool for finished or not, and success and error count values. Maybe should also have a list of wikis where the errors happened?
  • massmessage_targets: For each delivery, each target (page name, wiki) will get one row, linked to the deliveries table. There will be a bool for finished or not, and a result which might be success or some error message.
    • Targets for deliveries that have fully completed should be periodically deleted from the table to prevent it from growing too large.

Code flow[edit]

When MassMessageSubmitJob runs, it will create a single row in message_deliveries. If this row already exists, the job will abort. It will then create a row per page in massmessage_targets when queuing jobs for each page. It will also a schedule an instance of MassMessageOnCompletionJob (described below) to be run 5 minutes in the future using the jobReleaseTimestamp attribute (possible extension: scale based on size of target list).

Each MassMessageJob will check the massmessage_target row, if it's already marked as finished, abort (avoid double posting). Otherwise, it will process the delivery and update the database row on whether the target was successful or finished with an error.

When MassMessageOnCompletionJob is run, it will check whether all of the targets have finished (succeeded or failed). If not, it will just schedule itself to be run again in another 5 minutes. If all targets have finished, it will deliver an Echo notification with the final result on the wiki the job was originally submitted from, and perform any other work we may need to run on delivery completion.

We will also provide an API module for getting the progress of a delivery for scripting. One possible idea would be to have the "Your message has been queued for delivery" message on Special:MassMessage have an AJAX script poll that API, updating a progress bar.

Every day, a cron job will run and delete rows from massmessage_targets for deliveries older than 7 days.