Added scheduler support for Clean Generated Files

This commit is contained in:
David Maisonave
2024-08-13 02:19:16 -04:00
parent e64c46eac0
commit 9bfebd8435
5 changed files with 39 additions and 15 deletions

View File

@@ -1,4 +1,4 @@
# FileMonitor: Ver 0.7.9 (By David Maisonave)
# FileMonitor: Ver 0.8.0 (By David Maisonave)
FileMonitor is a [Stash](https://github.com/stashapp/stash) plugin with the following two main features:
- Updates Stash when any file changes occurs in the Stash library.
- **Task Scheduler**: Runs scheduled task based on the scheduler configuration in filemonitor_config.py.

View File

@@ -281,24 +281,41 @@ class StashPluginHelper:
# Extends class StashInterface with functions which are not yet in the class
class ExtendStashInterface(StashInterface):
def metadata_autotag(self, paths:list=[], dry_run=False):
if not paths:
return
def metadata_autotag(self, paths:list=[], performers:list=[], studios:list=[], tags:list=[]):
query = """
mutation MetadataAutoTag($input:AutoTagMetadataInput!) {
metadataAutoTag(input: $input)
}
"""
metadata_autotag_input = {
"paths": paths
"paths":paths,
"performers": performers,
"studios":studios,
"tags":tags,
}
result = self.call_GQL(query, {"input": metadata_autotag_input})
return result
def backup_database(self):
return self.call_GQL("mutation { backupDatabase(input: {download: false})}")
def optimise_database(self):
return self.call_GQL("mutation OptimiseDatabase { optimiseDatabase }")
def metadata_clean_generated(self, blobFiles=True, dryRun=False, imageThumbnails=True, markers=True, screenshots=True, sprites=True, transcodes=True):
query = """
mutation MetadataCleanGenerated($input: CleanGeneratedInput!) {
metadataCleanGenerated(input: $input)
}
"""
clean_metadata_input = {
"blobFiles": blobFiles,
"dryRun": dryRun,
"imageThumbnails": imageThumbnails,
"markers": markers,
"screenshots": screenshots,
"sprites": sprites,
"transcodes": transcodes,
}
result = self.call_GQL(query, {"input": clean_metadata_input})
return result

View File

@@ -153,6 +153,8 @@ class StashScheduler: # Stash Scheduler
return
if task['task'] == "Clean":
plugin.STASH_INTERFACE.metadata_clean(paths=stashPaths, dry_run=plugin.DRY_RUN)
elif task['task'] == "Clean Generated Files":
plugin.STASH_INTERFACE.metadata_clean_generated()
elif task['task'] == "Generate":
plugin.STASH_INTERFACE.metadata_generate()
elif task['task'] == "Backup":
@@ -165,7 +167,7 @@ class StashScheduler: # Stash Scheduler
elif task['task'] == "Scan":
plugin.STASH_INTERFACE.metadata_scan(paths=stashPaths)
elif task['task'] == "Auto Tag":
plugin.STASH_INTERFACE.metadata_autotag(paths=stashPaths, dry_run=plugin.DRY_RUN)
plugin.STASH_INTERFACE.metadata_autotag(paths=stashPaths)
elif task['task'] == "Optimise Database":
plugin.STASH_INTERFACE.optimise_database()
elif task['task'] == "python":
@@ -185,7 +187,11 @@ class StashScheduler: # Stash Scheduler
else:
# ToDo: Add code to check if plugin is installed.
plugin.Trace(f"Running plugin task pluginID={task['pluginId']}, task name = {task['task']}")
plugin.STASH_INTERFACE.run_plugin_task(plugin_id=task['pluginId'], task_name=task['task'])
try:
plugin.STASH_INTERFACE.run_plugin_task(plugin_id=task['pluginId'], task_name=task['task'])
except Exception as e:
plugin.LogOnce(f"Failed to call plugin {task['task']} with plugin-ID {task['pluginId']}. Error: {e}")
pass
def trimDbFiles(self, dbPath, maxFiles):
if not os.path.exists(dbPath):

View File

@@ -1,6 +1,6 @@
name: FileMonitor
description: Monitors the Stash library folders, and updates Stash if any changes occurs in the Stash library paths.
version: 0.7.9
version: 0.8.0
url: https://github.com/David-Maisonave/Axter-Stash/tree/main/plugins/FileMonitor
settings:
recursiveDisabled:

View File

@@ -22,12 +22,13 @@ config = {
# The frequency field can be in minutes or hours. A zero frequency value disables the task.
# For weekly and monthly task, use the syntax as done in the **Generate** and **Backup** task below.
"task_reoccurring_scheduler": [
{"task" : "Clean", "hours" : 48}, # Maintenance -> [Clean] (every 2 days)
{"task" : "Auto Tag", "hours" : 24}, # Auto Tag -> [Auto Tag] (Daily)
{"task" : "Optimise Database", "hours" : 24}, # Maintenance -> [Optimise Database] (Daily)
{"task" : "Auto Tag", "hours" : 24}, # Auto Tag -> [Auto Tag] (Daily)
{"task" : "Clean", "hours" : 48}, # Maintenance -> [Clean] (every 2 days)
{"task" : "Clean Generated Files", "hours" : 48}, # Maintenance -> [Clean Generated Files] (every 2 days)
{"task" : "Optimise Database", "hours" : 24}, # Maintenance -> [Optimise Database] (Daily)
# The following is the syntax used for plugins. A plugin task requires the plugin name for the [task] field, and the plugin-ID for the [pluginId] field.
{"task" : "Create Tags", "pluginId" : "pathParser", "hours" : 0}, # This task requires plugin [Path Parser]. To enable this task change the zero to a positive number.
{"task" : "Create Tags", "pluginId" : "pathParser", "hours" : 24}, # This task requires plugin [Path Parser]. To enable this task change the zero to a positive number.
# Note: For a weekly task use the weekday method which is more reliable. The hour section in time MUST be a two digit number, and use military time format. Example: 1PM = "13:00"
{"task" : "Generate", "weekday" : "sunday", "time" : "07:00"}, # Generated Content-> [Generate] (Every Sunday at 7AM)