Some code in rake tasks can polute the global scope

This is more a meta discussion that calls for an investigation. I learned today that there are many ways we can pollute the global scope in a .rake file.

This like: include, extend are particularly problematic. Other things have unexpected behavior: Defining a constant outside a namespace, defines it in the global scope. Defining it inside a namespace, makes it available to the whole namespace, even in other files. So innocent things like CACHE_TTL or LEASE_KEY can have undesired behavior if the name exists in different rake files with different values.

Defining methods also are problematic. Outside a namespace = global scope. Inside a namespace, shared between all rake files that use the same namespace.

Few links with some useful information:


One possible strategy to fix this is to refactor existing rake tasks that define methods or constants into specific Feature::RakeHelper module, that will be called using full namespace format, ex: AwesomeFeature::RakeHelper.awesome_rake_method('with content').

The strategy above is useful for auxiliary methods. Full blown transactional operations, should better be fitted into ServiceObjects.

cc @DouweM @rymai @stanhu @mek