Repository: Flexget/Flexget

Issue:
Add an option to run a task for free_space, besides abort. 
<!---
Before opening an issue, verify:

- Is this a feature request? Post it on https://feathub.com/Flexget/Flexget
- Is this an issue with webui? Make an issue over on https://github.com/Flexget/webui
- Did you recently upgrade? Look at the Change Log and Upgrade Actions to make sure that you don't need to make any changes to your config https://flexget.com/ChangeLog https://flexget.com/UpgradeActions
- Are you running FlexGet as a daemon? Stop it completely and then start it again https://flexget.com/CLI/daemon
- Did you search to see if the issue already exists? https://github.com/Flexget/Flexget/issues
- Did you fill out the issue template as completely as possible?

The issue template is here because it helps to ensure you submitted all the necessary information the first time, and allows us to more quickly review issues. Please fill it out correctly and do not ignore it, no matter how irrelevant you think it may be. Thanks in advance for your help with this!
--->

### Expected behaviour:

Run the task when free_space on a given drive is getting low. 

It is useful when we clean the old seeds, movies, etc...

### Actual behaviour:

For now, it will always abort.

### Steps to reproduce:
Normal configuration.

#### Config:
```yaml
  clean.check_free_space:
    priority: 9
    free_space:
      path: /mnt/Disk1/Downloads
      space: 30000
    mock: [{title: "Check.Free.Space"}]
    accept_all: yes
    exec: echo "Check free space."
    disable: [seen]
    run_task:
      when: aborted
      task: purge.finished_seeds

  purge.finished_seeds:
    limit_new: 2
    <<: *from_transmission
    if:
      - transmission_progress != 100.0: reject
    <<: *clean_transmission
```
  
#### Log:
<details>
 <summary>(click to expand)</summary>

```
No need
```
</details>

### Additional information:

- FlexGet version: latest
- Python version: 
- Installation method: docker/wiserain
- Using daemon (yes/no):
- OS and version:
- Link to crash log:

<!---
In config and debug/crash logs, remember to redact any personal or sensitive information such as passwords, API keys, private URLs and so on.

Please verify that the following data is present before submitting your issue:

- Link to a paste service or paste above the relevant config (preferably full config, including templates if present). Please make sure the paste does not expire, if possible.
- Link to a paste service or paste above debug-level logs of the relevant task/s (use `flexget -L debug execute --tasks <Task_name>`).
- FlexGet version (use `flexget -V` to get it).
- Full Python version, for example `2.7.11` (use `python -V` to get it). 
- Installation method (pip, git install, etc).
- Whether or not you're running FlexGet as a daemon.
- OS and version.
- Attach crash log if one was generated, in addition to the debug-level log. It can be found in the directory with your config file.
--->



Discussion:

Resolving patch:
diff --git a/flexget/plugins/operate/free_space.py b/flexget/plugins/operate/free_space.py
--- a/flexget/plugins/operate/free_space.py
+++ b/flexget/plugins/operate/free_space.py
@@ -7,6 +7,9 @@
 
 logger = logger.bind(name='free_space')
 
+ABORT_BELOW = 'below'
+ABORT_ABOVE = 'above'
+
 
 def get_free_space(config, task):
     """Return folder/drive free space (in megabytes)"""
@@ -67,6 +70,11 @@ class PluginFreeSpace:
                 'type': 'object',
                 'properties': {
                     'space': {'type': 'number'},
+                    'abort_if': {
+                        'type': 'string',
+                        'enum': [ABORT_BELOW, ABORT_ABOVE],
+                        'default': ABORT_BELOW,
+                    },
                     'path': {'type': 'string'},
                     'port': {'type': 'integer', 'default': 22},
                     'host': {'type': 'string'},
@@ -88,22 +96,26 @@ def prepare_config(config, task):
         # Use config path if none is specified
         if not config.get('path'):
             config['path'] = task.manager.config_base
+
         return config
 
     @plugin.priority(plugin.PRIORITY_FIRST)
     def on_task_download(self, task, config):
         config = self.prepare_config(config, task)
-        # Only bother aborting if there were accepted entries this run.
-        if not task.accepted:
-            return
 
         free_space = get_free_space(config, task)
         space = config['space']
         path = config['path']
-        if free_space < space:
+        abort_if = config['abort_if']
+
+        if free_space < space and abort_if == ABORT_BELOW:
             logger.error('Less than {} MB of free space in {} aborting task.', space, path)
             # backlog plugin will save and restore the task content, if available
             task.abort(f"Less than {space} MB of free space in {path}")
+        elif free_space > space and abort_if == ABORT_ABOVE:
+            logger.error('Over than {} MB of free space in {} aborting task.', space, path)
+            # backlog plugin will save and restore the task content, if available
+            task.abort(f"Over than {space} MB of free space in {path}")
 
 
 @event('plugin.register')


Test patch: