提交 fad3d0bd authored 作者: blu's avatar blu

evdameon, evcloudsvc: subsystem monitor thread and defered uploading

上级 dd6c69a2
*/5 * * * * sync; echo 1 > /proc/sys/vm/drop_caches */5 * * * * sync; echo 1 > /proc/sys/vm/drop_caches
\ No newline at end of file */30 * * * * python /root/work/opencv-pocs/opencv-motion-detect/upload_video.py
import requests, glob, os, json, socket, datetime
FILE_PATH = os.getenv('FILE_PATH', '/var/data/evsuits/failed_events')
API_ADDR=os.getenv('API_ADDR', 'http://evcloudsvc.ilabservice.cloud:10009/upload/evtvideos/')
#{"fileNames":["slices/237808840_3/20200304_124406.mp4","slices/237808840_3/20200304_124437.mp4"],"params":{"cameraId":"237808840","endTime":"1583297091","headOffset":"0","startTime":"1583297066","tailOffset":"0","type":"event"}}
def upload_file(file):
success = False
fileNames = []
try:
with open(file) as jf:
data = json.load(jf)
fileNames = ["{}{}".format(FILE_PATH, x[x.rfind('/'):]) for x in data["fileNames"]]
blob = [('files', open(f, 'rb')) for f in fileNames]
url = API_ADDR + data["params"]["cameraId"] + '?' + '&'.join(["{}={}".format(k,v) for k,v in data["params"].items()])
r = requests.post(url, files = blob)
print(file, fileNames, r.status_code, r.text)
if(r.status_code == 200 and ('code' in r.json()) and r.json()['code'] == 0):
success = True
try:
os.remove()
except:
pass
if success:
os.remove(file)
for f in fileNames:
try:
os.remove(f)
except:
pass
except requests.exceptions.ConnectionError as e:
print ("Error Connecting:",e)
except requests.exceptions.Timeout as e:
print ("Timeout Error:",e)
except requests.exceptions.RequestException as e:
print ("",e)
except IOError as e:
success = True
print(e)
except Exception as e:
print(e)
return success
def list_files(dir):
out = glob.glob("{}/*.json".format(dir))
out.sort(key=os.path.getmtime)
return out
if __name__ == "__main__":
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('localhost', 45431))
files = list_files(FILE_PATH)
for f in files:
now = datetime.datetime.now().timestamp()
mts = os.path.getmtime(f)
# defer those files may still in recording
if now - mts < 35:
continue
res = upload_file(f)
if res:
continue
else:
# TODO: report
break
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论