Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
I
ils-common-video
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
提交
议题看板
打开侧边栏
OpsTeam
ils-common-video
Commits
77a8949e
提交
77a8949e
authored
8月 04, 2021
作者:
zw.wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: [filter] 修复filter处理文件时间较长时,RABBITMQ 连接断开的问题
上级
0402a325
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
41 行增加
和
18 行删除
+41
-18
filter.py
ils_common_video/video_filter/filter.py
+41
-18
没有找到文件。
ils_common_video/video_filter/filter.py
浏览文件 @
77a8949e
import
os
import
os
import
time
import
time
import
json
import
json
import
threading
import
functools
from
datetime
import
timedelta
from
datetime
import
timedelta
from
intelab_python_sdk.ffmpeg.ffmpeg_prune
import
prune
from
intelab_python_sdk.ffmpeg.ffmpeg_prune
import
prune
...
@@ -14,6 +16,7 @@ from ils_common_video.const import UNVERIFIED_EVENT_QUEUE
...
@@ -14,6 +16,7 @@ from ils_common_video.const import UNVERIFIED_EVENT_QUEUE
from
ils_common_video.capability.movement_verify
import
file_filter
from
ils_common_video.capability.movement_verify
import
file_filter
from
ils_common_video.utils.aliyun_oss
import
oss_upload_file
,
oss_download_file
,
oss_delete_file
from
ils_common_video.utils.aliyun_oss
import
oss_upload_file
,
oss_download_file
,
oss_delete_file
from
ils_common_video.utils.video_file
import
VideoFile
from
ils_common_video.utils.video_file
import
VideoFile
from
ils_common_video.utils.alarm_utils
import
send_alarm_to_developer
class
VideoFilterProcess
:
class
VideoFilterProcess
:
...
@@ -33,31 +36,48 @@ class VideoFilterProcess:
...
@@ -33,31 +36,48 @@ class VideoFilterProcess:
# self.connection.call_later(5, lambda: self.channel.stop_consuming())
# self.connection.call_later(5, lambda: self.channel.stop_consuming())
self
.
channel
.
queue_declare
(
queue
=
self
.
queue_name
,
durable
=
True
)
self
.
channel
.
queue_declare
(
queue
=
self
.
queue_name
,
durable
=
True
)
def
callback
(
ch
,
method
,
properties
,
body
):
def
ack_message
(
ch
,
delivery_tag
):
log
.
info
(
'received MQ message {}'
.
format
(
body
))
"""Note that `ch` must be the same pika channel instance via which
the message being ACKed was retrieved (AMQP protocol constraint).
"""
if
ch
.
is_open
:
ch
.
basic_ack
(
delivery_tag
)
else
:
# Channel is already closed, so we can't ACK this message;
# log and/or do something that makes sense for your app in this case.
pass
def
do_work
(
conn
,
ch
,
delivery_tag
,
body
):
thread_id
=
threading
.
get_ident
()
log
.
info
(
'Thread id:
%
s Delivery tag:
%
s Message body:
%
s'
,
thread_id
,
delivery_tag
,
body
)
try
:
try
:
body
=
json
.
loads
(
body
)
self
.
process_message
(
json
.
loads
(
body
))
try
:
ret
=
self
.
process_message
(
body
)
except
Exception
as
e
:
log
.
error
(
'视频文件
%
s分析过程出错'
,
body
[
'full_path'
])
log
.
exception
(
e
)
ret
=
False
if
ret
:
log
.
info
(
'finished processing MQ message'
)
ch
.
basic_ack
(
delivery_tag
=
method
.
delivery_tag
)
else
:
ch
.
basic_nack
(
delivery_tag
=
method
.
delivery_tag
)
except
Exception
as
e
:
except
Exception
as
e
:
log
.
exception
(
e
)
log
.
exception
(
e
)
log
.
error
(
'finished processing MQ message, error'
)
send_alarm_to_developer
(
'common-filter'
,
e
)
cb
=
functools
.
partial
(
ack_message
,
ch
,
delivery_tag
)
conn
.
add_callback_threadsafe
(
cb
)
log
.
info
(
'finished processing MQ message'
)
def
on_message
(
ch
,
method_frame
,
_header_frame
,
body
,
args
):
(
conn
,
thrds
)
=
args
delivery_tag
=
method_frame
.
delivery_tag
t
=
threading
.
Thread
(
target
=
do_work
,
args
=
(
conn
,
ch
,
delivery_tag
,
body
))
t
.
start
()
thrds
.
append
(
t
)
threads
=
[]
on_message_callback
=
functools
.
partial
(
on_message
,
args
=
(
self
.
connection
,
threads
))
self
.
channel
.
basic_qos
(
prefetch_count
=
1
)
self
.
channel
.
basic_qos
(
prefetch_count
=
1
)
self
.
channel
.
basic_consume
(
on_message_callback
=
callback
,
self
.
channel
.
basic_consume
(
on_message_callback
=
on_message_
callback
,
queue
=
self
.
queue_name
)
queue
=
self
.
queue_name
)
log
.
info
(
'
[*] Waiting for messages. To exit press CTRL+C'
)
log
.
info
(
'[*] Waiting for messages. To exit press CTRL+C'
)
try
:
try
:
self
.
channel
.
start_consuming
()
self
.
channel
.
start_consuming
()
except
KeyboardInterrupt
:
except
KeyboardInterrupt
:
...
@@ -66,6 +86,9 @@ class VideoFilterProcess:
...
@@ -66,6 +86,9 @@ class VideoFilterProcess:
log
.
exception
(
'MQ connection closed unexpectedly.
%
s'
,
e
)
log
.
exception
(
'MQ connection closed unexpectedly.
%
s'
,
e
)
raise
raise
for
thread
in
threads
:
thread
.
join
()
self
.
connection
.
close
()
self
.
connection
.
close
()
@staticmethod
@staticmethod
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论