Skip to content
Snippets Groups Projects
Commit b7e54f50 authored by nimrod's avatar nimrod
Browse files

Don't hang on sending notification to Nextcloud.

I tried calling curl with & at the end, but that caused output from the
notify script to spam the prompt (process XXXX has finished). Instead I
wrote a short Python script to nicely fork and silently send the message
in the background, quickly returning to the calling process (the Bash
prompt). For reference, the problem I'm trying to solve is that on
remote systems, sending the notifications and has curl waiting for the
response. This causes the prompt to hang for a few seconds which I find
irritating.
parent b94dd3fa
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
# pylint: disable=invalid-name
"""Send a notification to my notification service.
Send it in a separate process so that the calling process is not hanged.
"""
import json
import os
import sys
import urllib.request
if __name__ == "__main__":
if os.fork():
sys.exit()
message = " ".join(sys.argv[1:])
data = json.dumps({"message": message}).encode()
request = urllib.request.Request(
"https://notify.shore.co.il/send",
data=data,
method="POST",
headers={"Content-Type": "application/json"},
)
urllib.request.urlopen(request) # nosec
......@@ -16,7 +16,7 @@ notify_send () {
nextcloud () {
message="$(cat)"
curl --silent -d "$message" https://notify.shore.co.il/send > /dev/null
nc-notify "$message"
}
# Try hostname if present.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment