Giter Site home page Giter Site logo

Comments (12)

mtippmann avatar mtippmann commented on May 27, 2024 1

probably filesystem related issue - replacing

    new_file = file.sub(/\.(jpg|png)\z/i, "-#{Time.now.to_i}.webp")

with

    new_file = file.sub(/\.(jpg|png)\z/i, "-#{('a'..'z').to_a.shuffle[0..10].join}.webp")

creates all files - the machine is too fast and overwrites files due to the same timestamp and this likely causes the 0-byte issue. using Time.now.to_i creates less files on my machine.

from rszr.

mtgrosser avatar mtgrosser commented on May 27, 2024

Could be a threading problem caused by imlib2 internals. Maybe the implementation of the webp loader is not thread safe?

Have you tried wrapping everything that happens inside perform with a Mutex? Based on the guess that ConvertJob is an ActiveJob::Base, something along the lines of

class ConvertJob < ApplicationJob
  MUTEX = Mutex.new

  def perform(*args)
    MUTEX.synchronize do
      load_resize_and_save_your_image
    end
  end
end

from rszr.

jewe avatar jewe commented on May 27, 2024

Thank you!
Unfortunately that doesn't work. Same behaviour: the file is created but has a size of zero. No errors...
In another test with delayed_jobs instead of sidekiq everything worked async...

from rszr.

mtgrosser avatar mtgrosser commented on May 27, 2024

Tested with the following snippet and imlib2 v1.7.0-8 and could not reproduce the problem:

# test.rb
require 'sidekiq'
require 'rszr'

# Start up sidekiq via
# sidekiq -r ./test.rb
# and then you can open up an IRB session like so:
# irb -r ./test.rb
# where you can then say
# 10.times { ResizeWorker.perform_async "test.png" }

class ResizeWorker
  include Sidekiq::Worker

  def perform(file)
    image = Rszr::Image.load(file)
    new_file = file.sub(/\.(jpg|png)\z/i, "-#{Time.now.to_i}.webp")
    image.save(new_file)
    puts "Saved #{new_file}"
  end
end

Which OS, Ruby and imlib2 versions are you using?

from rszr.

jewe avatar jewe commented on May 27, 2024

Same result with your snippet.

dpkg -l | grep imlib2
ii  libimlib2:amd64                        1.6.1-1ubuntu0.1                              amd64        
ii  libimlib2-dev                          1.6.1-1ubuntu0.1                              amd64       
ruby -v
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]
lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.3 LTS
Release:	20.04
Codename:	focal

from rszr.

mtgrosser avatar mtgrosser commented on May 27, 2024

Same result meaning it works or it doesn't work on your setup?

from rszr.

jewe avatar jewe commented on May 27, 2024

Sorry - no, it doesn't work.
But in my local development environment everything works.
It is almost the same setup as vm:

dpkg -l | grep imlib2
ii  libimlib2:amd64                      1.6.1-1ubuntu0.1                  amd64       
ii  libimlib2-dev                        1.6.1-1ubuntu0.1                  amd64

ruby -v
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]

lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04 LTS
Release:        20.04
Codename:       focal

from rszr.

mtgrosser avatar mtgrosser commented on May 27, 2024

Which are the versions of libwebp?

from rszr.

jewe avatar jewe commented on May 27, 2024

not working:

dpkg -l | grep libwebp
ii  libwebp-dev:amd64                      0.6.1-2ubuntu0.20.04.1                        amd64        
ii  libwebp6:amd64                         0.6.1-2ubuntu0.20.04.1                        amd64        
ii  libwebpdemux2:amd64                    0.6.1-2ubuntu0.20.04.1                        amd64        
ii  libwebpmux3:amd64                      0.6.1-2ubuntu0.20.04.1                        amd64        

But same lib versions on my dev system.

from rszr.

mtgrosser avatar mtgrosser commented on May 27, 2024

Imlib2's webp loader has been refactored alot since your version of imlib2 1.6.1. You could try and build a more recent version of the library to see if the problem persists.

from rszr.

mtgrosser avatar mtgrosser commented on May 27, 2024

The file I used was sufficiently large for the resizing to take several seconds, but you're right, to_i in my test snippet was sort of a bad idea for a fast resizer.

from rszr.

jewe avatar jewe commented on May 27, 2024

Sorry, i have determined that the problem was caused by a misconfiguration of sidekiq. There was a timeout set, which stopped the job prematurely. So the problem was not in the rszr library.
Sorry for the confusion and thank you for the support!

from rszr.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.