Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -pr/--priority/KOMETA_PRIORITY to allow Kometa to run at lower/higher priorities #2397

Open
wants to merge 8 commits into
base: nightly
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ pcm
persistentvolumeclaim
pgid
pkkid
planetrocky
plex
plex's
plexapi
Expand All @@ -228,12 +229,14 @@ prepend
preroll
psutil
puid
pywin
qnap
radarr
razzie
razzies
readme
readwriteonce
realtime
reciperr
reddit
redheadjedi
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Requirements Update (requirements will need to be reinstalled)
Add pywin32 requirement at 308 (windows only)
Update gitpython requirement to 3.1.44
Update num2words requirement to 0.5.14
Update pathvalidate requirement to 3.2.3
Update pillow requirement to 10.4.0
Update pillow requirement to 11.1.0
Update plexapi requirement to 4.16.1
Update psutil requirement to 6.1.1
Expand All @@ -21,6 +21,7 @@ Logic added to Kometa to create `config.yml` if it does not exist from the `conf
When using `mass_poster_update`, added `ignore_locked` and `ignore_overlays` attributes which will prevent Kometa from resetting the image if the poster field is locked (i.e. a previous mass poster update) or if the item has an Overlay. This can effectively act as a differential update system.
When using `mass_background_update`, added `ignore_locked` attribute which will prevent Kometa from resetting the image if the poster field is locked (i.e. a previous mass poster update). This can effectively act as a differential update system.
Add `date` option for schedules
Added the `--low-priority/-lp` (`KOMETA_LOW_PRIORITY`) command line argument option to run the process at a lower priority. **credit to planetrocky**
Add `trakt`, `omdb_metascore`, `omdb_tomatoes` ratings sources for mass operations.
Add `trakt` ratings source for mass episode operations.
Added GitHub token validation during config validation.
Expand Down
2 changes: 1 addition & 1 deletion PART
Original file line number Diff line number Diff line change
@@ -1 +1 @@

3
28 changes: 28 additions & 0 deletions docs/kometa/environmental.md
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,34 @@ Kometa will load those environment variables when it starts up, and you don't ha
docker run -it -v "X:\Media\Kometa\config:/config:rw" kometateam/kometa --width 150
```

??? blank "Priority&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`-pr`/`--priority`&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`KOMETA_PRIORITY`<a class="headerlink" href="#priority" title="Permanent link">¶</a>"

<div id="priority" />Run the Kometa process at a lower priority. Will default to normal priority if not specified.

<hr style="margin: 0px;">

**Shell Flags:** `-priority` or `--priority` (ex. `--priority 75`)

**Environment Variable:** `KOMETA_NICE` (ex. `KOMETA_PRIORITY=75`)

**Options:**
- `25`: Below Normal
- `50`: Normal (default)
- `75`: Above Normal
- `90`: High
- `100`: Realtime

!!! example
=== "Local Environment"
```
python kometa.py --priority 25
```
=== "Docker Environment"
```
docker run -it -v "X:\Media\Kometa\config:/config:rw" kometateam/kometa --priority 25
```


??? blank "Config Secrets&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`--kometa-***`&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`KOMETA_***`<a class="headerlink" href="#kometa-vars" title="Permanent link">¶</a>"

<div id="kometa-vars" />All Run Commands that are in the format `--kometa-***` and Environment Variables that are in the
Expand Down
23 changes: 21 additions & 2 deletions kometa.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import argparse, os, platform, re, sys, time, uuid
import argparse, os, platform, re, sys, sysconfig, time, uuid
from collections import Counter
from concurrent.futures import ProcessPoolExecutor
from datetime import datetime
Expand Down Expand Up @@ -30,11 +30,12 @@
"psutil": psutil.__version__,
"python-dotenv": dotenv_version.__version__,
"python-dateutil": dateutil.__version__, # noqa
"pywin32": None,
"requests": requests.__version__,
"tenacity": None,
"ruamel.yaml": ruamel.yaml.__version__,
"schedule": None,
"setuptools": setuptools.__version__,
"tenacity": None,
"tmdbapis": tmdbapis.__version__
}

Expand Down Expand Up @@ -70,6 +71,7 @@
"read-only-config": {"args": "ro", "type": "bool", "help": "Run without writing to the config"},
"divider": {"args": "d", "type": "str", "default": "=", "help": "Character that divides the sections (Default: '=')"},
"width": {"args": "w", "type": "int", "default": 100, "help": "Screen Width (Default: 100)"},
"low-priority": {"args": "lp", "type": "bool", "help": "Run Kometa with lower priority"}
}

parser = argparse.ArgumentParser()
Expand Down Expand Up @@ -271,6 +273,22 @@ def new_send(*send_args, **kwargs):
plexapi.BASE_HEADERS["X-Plex-Client-Identifier"] = str(uuid_num)
ImageFile.LOAD_TRUNCATED_IMAGES = True

if util.windows:
import win32api, win32process
site_packages = sysconfig.get_paths()["platlib"]
with open(os.path.join(site_packages, "pywin32.version.txt")) as v:
system_versions["pywin32"] = v.read().strip()

if run_args["low-priority"]:
try:
if util.windows:
win32process.SetPriorityClass(win32api.GetCurrentProcess(), win32process.BELOW_NORMAL_PRIORITY_CLASS)
else:
os.nice(10)
except Exception as e:
logger.stacktrace()
logger.critical(f"Failed to set priority: {e}")

def process(attrs):
with ProcessPoolExecutor(max_workers=1) as executor:
executor.submit(start, *[attrs])
Expand Down Expand Up @@ -298,6 +316,7 @@ def start(attrs):
logger.info(f" Platform: {platform.platform()}")
logger.info(f" Total Memory: {round(psutil.virtual_memory().total / (1024.0 ** 3))} GB")
logger.info(f" Available Memory: {round(psutil.virtual_memory().available / (1024.0 ** 3))} GB")
logger.info(f" Process Priority: {'low' if run_args["low-priority"] else 'normal'}")
if not is_docker and not is_linuxserver:
try:
with open(os.path.abspath(os.path.join(os.path.dirname(__file__), "requirements.txt")), "r") as file:
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ PlexAPI==4.16.1
psutil==6.1.1
python-dateutil==2.9.0.post0
python-dotenv==1.0.1
pywin32==308; sys_platform == 'win32'
requests==2.32.3
ruamel.yaml==0.18.10
schedule==1.2.2
Expand Down
Loading