2011-03-18 16 views
6

के साथ कॉलबैक समस्या मैं रेलवे 3 एप्लिकेशन पर कैरियरवेव और मोन्गॉयड का उपयोग कर रहा हूं और मुझे बाद में कॉलबैक के साथ कोई समस्या है। पर विचार करें निम्नलिखितकैरियरवेव और मोंगोइड

class Video 
    include Mongoid::Document 

    field :name 

    mount_uploader :file, VideoUploader 

    after_create :enqueue_for_encoding 

    protected 

    def enqueue_for_encoding 
    // point your encoding service to where it expects the permanent file to reside 
    // in my case on s3 
    end 

end 

मेरे मुद्दा है कि मेरे enqueue_for_encoding विधि में, स्थानीय tmp निर्देशिका नहीं S3 निर्देशिका के लिए file.url अंक।

मैं अपने enqueue_for_encoding विधि को कॉल करने के लिए कैसे प्राप्त करूं जब file.url s3 को इंगित करता है?

धन्यवाद!

जोनाथन

उत्तर

0

आप मॉडल में अपने after_create कॉलबैक निकालने का प्रयास करें और अपने अपलोड करने वाले के लिए निम्न जोड़ सकते हैं:

# video_uploader.rb 

process :encode 

def encode 
    model.enqueue_for_encoding 
end 

process कॉलबैक के बाद फ़ाइल सहेजा जाता है कहा जाता है (मुझे लगता है कि) आपकी फ़ाइल S3 पर एक बार होने पर आपको हुक करने की अनुमति देनी चाहिए।

+1

टिप्पणी के लिए धन्यवाद आदमी - लेकिन यह काम नहीं करता - यहां तक ​​कि प्रक्रिया कॉलबैक temp फ़ाइल को इंगित करता है। – Jonathan

+0

अरे। यह वास्तव में कष्टप्रद है। क्या आप अपने एस 3 बाल्टी/निर्देशिका को अनप्रचारित नौकरियों के लिए स्वीप करने के लिए अपने आवेदन में क्रॉन नौकरी का उपयोग कर सकते हैं और उन्हें कतार में जोड़ सकते हैं? सुरुचिपूर्ण नहीं है, लेकिन ट्रिक विश्वसनीय रूप से करना चाहिए। – theTRON

1

ठीक है, मैंने इसे समझ लिया। कुछ हैकिंग लेने के लिए। तो वर्तमान में कैरियरवेव एक बाद के हुक का पर्दाफाश नहीं करता है, यह सब जारी रहता है और बाद में कॉलबैक में प्रसंस्करण होता है। यहाँ कोड मैं इसे हल करने के लिए प्रयोग किया जाता है:

# Video.rb 

    mount_uploader :file, VideoUploader 

    # overwrite the file setting to flag the model that we are creating rather than saving 
    def file=(obj) 
    @new_file = true 
    super(obj) 
    end 

    # chain the store_file! method to enqueue_for_encoding after storing the file AND 
    # if the file is new 
    alias_method :orig_store_file!, :store_file! 
    def store_file! 
    orig_store_file! 
    if @new_file #means dirty 
     @new_file = false 
     enqueue_for_encoding 
    end 
    true 
    end 

अद्यतन

ओह - कि काम नहीं किया। यह लगभग किया - यूआरएल सही है, लेकिन इसे स्थायी रूप से निकाल दिया जा रहा है। फ़ाइल मतलब अभी भी लोड किए जाने की प्रक्रिया में है, और पूरी तरह से संग्रहीत नहीं है जब enqueue_for_encoding कहा जाता है

1

यह है अपलोडर पर अपने enqueue_for_encoding कॉलबैक को सेट करना संभव है। लेकिन मैं इसे इस तरह से करना पसंद करता हूं:

class Video 
    # mount the uploader first: 
    mount_uploader :file, VideoUploader 
    # then add the callback: 
    after_save :enqueue_for_encoding, on: :create 
end 
संबंधित मुद्दे