-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathwebhook
executable file
·63 lines (56 loc) · 1.91 KB
/
webhook
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env -S python3 -u
# -S allows for arguments
# -u unbuffered output
import sys
import logging
import subprocess
import os
from datetime import datetime
print("Content-type: text/plain\n")
print("starting")
logging.basicConfig(
# This process is run as user nvdal10n, which does not have write permissions for
# /var/log/uwsgi/app/ so instead of writing to file, write to stderr.
# stderr is logged to /var/log/uwsgi/app/nvdal10n.log by nginx/fastcgi
level=logging.DEBUG,
stream=sys.stderr,
)
startDate = datetime.now().strftime("%Y-%b-%d %H:%M:%S")
logging.info(f"Webhook starting: {startDate}")
SCRIPTS_PATH = os.path.abspath('../mr/scripts')
def executeScriptsWebhook():
cmd = (os.path.join(SCRIPTS_PATH, "webhook"))
logging.debug(f"Running: {cmd}")
proc: subprocess.Popen = subprocess.Popen(
cmd,
cwd=SCRIPTS_PATH,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
errors="UTF-8",
encoding="UTF-8",
bufsize=0,
)
logging.info(f"Proc pid: {proc.pid}")
logging.debug("Start logging output from proc")
# https://docs.python.org/3.7/library/subprocess.html#subprocess.Popen.stderr
# If the encoding or errors arguments were specified or the universal_newlines argument was True,
# the stream is a text stream, otherwise it is a byte stream. If the stderr argument was not PIPE,
# this attribute is None.
for stdout_line in proc.stdout:
logging.debug( stdout_line)
logging.debug("No more stdout")
proc.stdout.close()
logging.debug("waiting for proc")
return_code = proc.wait()
if return_code:
logging.debug("Called Process Error")
raise subprocess.CalledProcessError(return_code, cmd)
try:
logging.debug(f"starting scripts\\webHook")
executeScriptsWebhook()
except Exception as e:
logging.error(f"Error running scripts\\webhook process: {e}")
logging.debug(f"finished scripts\\webhook")
endDate = datetime.now().strftime("%Y-%b-%d %H:%M:%S")
logging.info(f"Webhook finished: {endDate}")
print("ok")