Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attachment queueing? #96

Open
hotmeteor opened this issue Nov 9, 2014 · 13 comments
Open

Attachment queueing? #96

hotmeteor opened this issue Nov 9, 2014 · 13 comments

Comments

@hotmeteor
Copy link

Is queueing built into the attachment processing? A case study in mind:

  1. Select an image to be attached to an Item
  2. The image is large, and requires a few different sizes to be generated
  3. A config determines the size to generate first (perhaps a thumbnail) and then the rest of the processing is passed off to a queue so the user doesn't have to wait

I'm not sure if anything like this exists in the current package. Thanks for any insight.

@tabennett
Copy link
Contributor

There's no support for queueing in the current package. Gosh I would love to have it though. I've scratched a few ideas around about how to do this, but I haven't implemented anything as of yet.

@tomvo
Copy link

tomvo commented Dec 16, 2014

I'd also be interested in this

@tomvo
Copy link

tomvo commented Dec 30, 2014

I'm hitting this problem now more often since I'm converting my images into 5 different versions on the fly and I allow users to upload 20 or so files at once. This results in very slow performance when waiting for the resize and then the upload to S3, sometimes even hitting the max_execution_time. How would you go about this?

@hotmeteor
Copy link
Author

I've not done multiple files, but the way I've handled this is basically the following:

  1. Upload the original file(s) with Stapler
  2. Optionally create one thumbnail to indicate the image was uploaded (on the next screen or something)
  3. Queue up some processes to go "reprocess" those files using a different config than the original upload config

It's basically queuing outside of Stapler instead of inside.

@jorenvanhee
Copy link
Contributor

I made a rough version of Stapler with queueing that I'm using in a project. Most of the queueing stuff is done in laravel-stapler. I would like to share and explain my code if you're interested.

@tomvo
Copy link

tomvo commented Dec 4, 2015

I would be interested, still something on my todo list for one of our products that uses stapler intensively.

@jorenvanhee
Copy link
Contributor

Ok, this is what I'm working on right now.

stapler

defer & defer_all_except options

$this->hasAttachedFile('picture', [
  'styles' => [/* your styles */],
  'defer' => [/* styles you don't want to process immediately */],
  'defer_all_except' => [/* opposite of 'defer' option */]
]);

reprocess specific styles

$attachment->reprocess($styles = []);

process deferred styles

Still have to add a method to process only the deferred styles. Will use the reprocess method.

laravel-stapler

ProcessDeferredAttachmentStyles Job

This job processes the deferred attachment styles.

QueueingEloquentTrait

QueueingEloquentTrait will automatically dispatch the ProcessDeferredAttachmentStyles when needed.


Let me know what you think.

@tomvo
Copy link

tomvo commented May 26, 2016

@jorenvanhee have you managed to get your queuing solution working?

@jorenvanhee
Copy link
Contributor

@tomvo Yep, got it working. I'm using my own forks now. But I would be happy to clean it up, document it, and submit a PR (if there's interest).

Here's my fork of stapler and laravel-stapler.

The word queue was already used in the codebase, so I used "defer". You'll see it in my commits.

@tomvo
Copy link

tomvo commented May 27, 2016

@jorenvanhee I checked your code and it actually looks pretty solid. The changes are actually not even that big. However it's Laravel 5 only. Unfortunately my legacy codebase is based on L4 so I wouldn't be able to help you out right away with testing it. I could adapt it to L4 though.

@tabennett
Copy link
Contributor

I'm working on a 2.0 release of Stapler that's php7 and laravel 5.1 only. It's got some new features:

  • Flysystem for file abstraction (Local, S3, Rackspace, and Azure Cloud File storage)
  • Easy image naming/renaming
  • Dynamic style creation: $image->picture->url('medium', '150x150')
  • Possibly more drivers/traits (Cakephp, Doctrine, Analogue, Yii, etc), however this is stretch goal.
  • More examples (example applications, etc) and better documentation
  • Better/more test coverage
  • Several bug fixes, etc.

I'm going to release one more minor release from the 1x branch and back port as much of this stuff as possible to, but after that It's going to be bug fixes only for that branch. I'd really like to figure out a clean way to do attachment queueing that (works nicely/elegantly with this package) and get that into the new release for sure. I took a look at that code and it looks pretty clean, but there will more than likely have to be changes/tweaks to make it work consistently with the rest of the package. If you guys want to work on something bounce ideas around I think we could get it done.

@tomvo
Copy link

tomvo commented May 27, 2016

Great that you're working on v2 of the library. I guess it wouldn't make much sense for the package to add queuing support for L4. @jorenvanhee if you don't mind i'm going to use your stapler fork and use your ideas on the laravel fork and port it to a L4 version. I'll share it back here when done for anybody else who might benefit from this.

@jorenvanhee
Copy link
Contributor

@tomvo Great, go ahead!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants