Skip to content

Migrate Memory::Watchdog to BackgroundTask class

Matthias Käppler requested to merge 367861-watchdog-bgtask into master

What does this MR do and why?

In !92561 (merged) we added a new helper class BackgroundTask that aims to supersede Daemon.

In this MR I started moving one of the more recent Daemon implementations (Gitlab::Memory::Watchdog) to BackgroundTask.

This makes Watchdog a "normal" Ruby object with all threading-related concerns removed that were previously inherited from Daemon. Instead of implementing template methods inherited from a superclass, we now provide a duck-typed interface via two methods call and start that the BackgroundTask wrapper will dispatch to.

The logic has not changed at all. But tests changed quite a bit: we don't need to sleep anymore because we don't have to wait for threads to run or stop. The main complication left was that call enters a loop, so I had to get "clever" a little in the way I stub out the loop sleep to terminate the task after a given number of iterations. Open for suggestions how that could be improved further to make this more testable.

Screenshots or screen recordings

These are strongly recommended to assist reviewers and reduce the time to merge your change.

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #367861 (closed)

Edited by Matthias Käppler

Merge request reports