Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Video AG Infrastruktur
jobmanager
Commits
8d0b85cc
Commit
8d0b85cc
authored
Feb 06, 2017
by
Andreas Valder
Browse files
working thumbnail generator
parent
5bbbcd46
Changes
2
Hide whitespace changes
Inline
Side-by-side
README.md
0 → 100644
View file @
8d0b85cc
Dependencies:
python3
python-psutil
worker.py
View file @
8d0b85cc
...
...
@@ -6,6 +6,10 @@ import sched
import
random
import
traceback
import
configparser
import
psutil
import
os
import
json
import
shlex
config
=
configparser
.
ConfigParser
()
config
.
read
(
'config.ini'
)
...
...
@@ -36,14 +40,27 @@ threading.Thread(target=run_scheduler, daemon=True).start()
@
sched_func
(
5
)
def
ping_website
():
r
=
requests
.
post
(
config
[
'API'
][
'BASE'
]
+
'/jobs/api/ping'
,
params
=
{
'apikey'
:
config
[
'API'
][
'KEY'
]
,
'host'
:
config
[
'MAIN'
][
'HOST'
]
})
r
=
requests
.
post
(
config
[
'API'
][
'BASE'
]
+
'/jobs/api/
worker/'
+
config
[
'MAIN'
][
'HOST'
]
+
'/
ping'
,
params
=
{
'apikey'
:
config
[
'API'
][
'KEY'
]})
if
not
r
.
status_code
==
200
:
print
(
"Error sending ping: "
,
r
)
@
sched_func
(
10
)
def
get_jobs
():
r
=
requests
.
post
(
config
[
'API'
][
'BASE'
]
+
'/jobs/api/schedule'
,
json
=
{
'apikey'
:
config
[
'API'
][
'KEY'
],
'host'
:
config
[
'MAIN'
][
'HOST'
],
'jobtypes'
:
'thumbnail'
})
print
(
r
.
text
)
if
psutil
.
cpu_percent
(
interval
=
3
)
<
70
:
r
=
requests
.
post
(
config
[
'API'
][
'BASE'
]
+
'/jobs/api/worker/'
+
config
[
'MAIN'
][
'HOST'
]
+
'/schedule'
,
json
=
{
'apikey'
:
config
[
'API'
][
'KEY'
],
'jobtypes'
:
'thumbnail'
})
if
r
.
status_code
==
200
:
threading
.
Thread
(
target
=
executejob
,
daemon
=
True
,
kwargs
=
{
'data'
:
r
.
json
()}).
start
()
def
executejob
(
data
):
print
(
data
)
param
=
json
.
loads
(
data
[
'data'
])
if
(
data
[
'type'
]
==
'thumbnail'
):
inputfile
=
'/mnt/sshfs/video-main/'
+
param
[
'path'
]
outputfile
=
'/tmp/l_'
+
str
(
param
[
'lectureid'
])
+
'.png'
r
=
requests
.
post
(
config
[
'API'
][
'BASE'
]
+
'/jobs/api/job/'
+
str
(
data
[
'id'
])
+
'/ping'
,
params
=
{
'apikey'
:
config
[
'API'
][
'KEY'
],
'host'
:
config
[
'MAIN'
][
'HOST'
],
'state'
:
'running'
,
'status'
:
'{}'
})
os
.
system
(
"ffmpeg -loglevel error -i '"
+
shlex
.
quote
(
inputfile
)
+
"' -ss '10:00' -vf 'scale=640:360' -frames:v 1 '"
+
shlex
.
quote
(
outputfile
)
+
"'"
)
r
=
requests
.
post
(
config
[
'API'
][
'BASE'
]
+
'/jobs/api/job/'
+
str
(
data
[
'id'
])
+
'/finished'
,
json
=
{
'apikey'
:
config
[
'API'
][
'KEY'
],
'status'
:
'{}'
})
print
(
r
)
while
True
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment