Skip to content

Commit

Permalink
fix: conversion timeout on first conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJoin95 committed Jul 27, 2023
1 parent 9d766fd commit e998a80
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/ign-api/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def convert_queue():
output_path = ''
response = {'success': True}
file = None
palette_name = 'Nordtheme'

if (request.files.get('file') != None):
file = request.files.get('file')
Expand All @@ -36,6 +37,9 @@ def convert_queue():
if (request.form.get('output_path') != None):
output_path = request.form.get('output_path')

if (request.form.get('palette_name') != None):
palette_name = request.form.get('palette_name')

conn.incr('conversion_count', 1)

if is_image(file.filename):
Expand All @@ -46,7 +50,7 @@ def convert_queue():
filename = now.strftime("%m%d%Y-%H%M%S")
path_to_video = os.path.join('/tmp', 'ign-video-' + filename + '.' + file.filename.rsplit('.', 1)[1])
file.save(path_to_video)
job = q.enqueue(f=convert_video, ttl=900, failure_ttl=900, job_timeout='300s', args=(go_nord, path_to_video))
job = q.enqueue(f=convert_video, ttl=900, failure_ttl=900, job_timeout='900s', args=(go_nord, palette_name, path_to_video))
else:
abort(400, 'No valid file: you can upload video in mp4, avi, webp and mov and images (up to 16MB)')

Expand All @@ -69,9 +73,9 @@ def convert_image(go_nord, image, save_path, b64_output, response):

return response

def convert_video(go_nord, path_to_video):
def convert_video(go_nord, palette_name, path_to_video):
try:
output_path = go_nord.convert_video(path_to_video, 'custom_palette')
output_path = go_nord.convert_video(path_to_video, '/tmp/' + palette_name)
finally:
os.remove(path_to_video)

Expand Down
2 changes: 1 addition & 1 deletion src/ign-frontend/src/components/Demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ export default Vue.component('Demo', {
selectedPalette(file) {
// eslint-disable-next-line
this.palette = require(`../assets/${file}`);
console.log(this.palette);
},
palette(p) {
this.selectedColor = p.colors;
Expand Down Expand Up @@ -180,6 +179,7 @@ export default Vue.component('Demo', {
// formData.append('width', this.img.width);
// formData.append('height', this.img.height);
formData.append('b64_output', true);
formData.append('palette_name', this.palette.name);
formData.append('colors', this.selectedColor.filter((c) => c).join(','));
if (this.avg_index !== 0) {
Expand Down

0 comments on commit e998a80

Please sign in to comment.