[2] add new_version to webhooks

pull/811/head
meisnate12 3 years ago
parent 2b16c7cc67
commit 85b5e0185c

@ -1 +1 @@
1.16.2-develop1 1.16.2-develop2

@ -81,6 +81,7 @@ The Run Start notification will be sent at the beginning of every run.
```yaml ```yaml
{ {
"start_time": str, // Time Run is started Format "YY-mm-dd HH:MM:SS" "start_time": str, // Time Run is started Format "YY-mm-dd HH:MM:SS"
"new_version": str // New Version or null if version is current
} }
``` ```
@ -95,6 +96,7 @@ The Run End notification will be sent at the end of every run with statistics.
"start_time": str, // Time Run started Format "YY-mm-dd HH:MM:SS" "start_time": str, // Time Run started Format "YY-mm-dd HH:MM:SS"
"end_time": str, // Time Run ended Format "YY-mm-dd HH:MM:SS" "end_time": str, // Time Run ended Format "YY-mm-dd HH:MM:SS"
"run_time": str, // Time Run took to complete Format "HH:MM" "run_time": str, // Time Run took to complete Format "HH:MM"
"new_version": str, // New Version or null if version is current
"collections_created": int, // Number of Collections/Playlists Created "collections_created": int, // Number of Collections/Playlists Created
"collections_modified": int, // Number of Collections/Playlists Modified "collections_modified": int, // Number of Collections/Playlists Modified
"collections_deleted": int, // Number of Collections/Playlists Removed "collections_deleted": int, // Number of Collections/Playlists Removed

@ -63,6 +63,7 @@ class ConfigFile:
self.default_dir = default_dir self.default_dir = default_dir
self.read_only = attrs["read_only"] if "read_only" in attrs else False self.read_only = attrs["read_only"] if "read_only" in attrs else False
self.new_version = attrs["new_version"] if "new_version" in attrs else None
self.test_mode = attrs["test"] if "test" in attrs else False self.test_mode = attrs["test"] if "test" in attrs else False
self.trace_mode = attrs["trace"] if "trace" in attrs else False self.trace_mode = attrs["trace"] if "trace" in attrs else False
self.delete_collections = attrs["delete"] if "delete" in attrs else False self.delete_collections = attrs["delete"] if "delete" in attrs else False
@ -355,7 +356,7 @@ class ConfigFile:
self.Webhooks = Webhooks(self, self.webhooks, notifiarr=self.NotifiarrFactory) self.Webhooks = Webhooks(self, self.webhooks, notifiarr=self.NotifiarrFactory)
try: try:
self.Webhooks.start_time_hooks(self.start_time) self.Webhooks.start_time_hooks(self.start_time, self.new_version)
except Failed as e: except Failed as e:
logger.stacktrace() logger.stacktrace()
logger.error(f"Webhooks Error: {e}") logger.error(f"Webhooks Error: {e}")

@ -44,16 +44,20 @@ class Webhooks:
if response.status_code >= 400: if response.status_code >= 400:
raise Failed(f"({response.status_code} [{response.reason}])") raise Failed(f"({response.status_code} [{response.reason}])")
def start_time_hooks(self, start_time): def start_time_hooks(self, start_time, version):
if self.run_start_webhooks: if self.run_start_webhooks:
self._request(self.run_start_webhooks, {"start_time": start_time.strftime("%Y-%m-%d %H:%M:%S")}) self._request(self.run_start_webhooks, {
"start_time": start_time.strftime("%Y-%m-%d %H:%M:%S"),
"new_version": version
})
def end_time_hooks(self, start_time, end_time, run_time, stats): def end_time_hooks(self, start_time, end_time, run_time, stats, version):
if self.run_end_webhooks: if self.run_end_webhooks:
self._request(self.run_end_webhooks, { self._request(self.run_end_webhooks, {
"start_time": start_time.strftime("%Y-%m-%d %H:%M:%S"), "start_time": start_time.strftime("%Y-%m-%d %H:%M:%S"),
"end_time": end_time.strftime("%Y-%m-%d %H:%M:%S"), "end_time": end_time.strftime("%Y-%m-%d %H:%M:%S"),
"run_time": run_time, "run_time": run_time,
"new_version": version,
"collections_created": stats["created"], "collections_created": stats["created"],
"collections_modified": stats["modified"], "collections_modified": stats["modified"],
"collections_deleted": stats["deleted"], "collections_deleted": stats["deleted"],

@ -149,6 +149,7 @@ def start(attrs):
attrs["time"] = start_time.strftime("%H:%M") attrs["time"] = start_time.strftime("%H:%M")
attrs["time_obj"] = start_time attrs["time_obj"] = start_time
attrs["read_only"] = read_only_config attrs["read_only"] = read_only_config
attrs["new_version"] = new_version
logger.separator(debug=True) logger.separator(debug=True)
logger.debug(f"--config (PMM_CONFIG): {config_file}") logger.debug(f"--config (PMM_CONFIG): {config_file}")
logger.debug(f"--time (PMM_TIME): {times}") logger.debug(f"--time (PMM_TIME): {times}")
@ -192,7 +193,7 @@ def start(attrs):
run_time = str(end_time - start_time).split('.')[0] run_time = str(end_time - start_time).split('.')[0]
if config: if config:
try: try:
config.Webhooks.end_time_hooks(start_time, end_time, run_time, stats) config.Webhooks.end_time_hooks(start_time, end_time, run_time, stats, new_version)
except Failed as e: except Failed as e:
logger.stacktrace() logger.stacktrace()
logger.error(f"Webhooks Error: {e}") logger.error(f"Webhooks Error: {e}")

Loading…
Cancel
Save