I'm not experienced, but the goal is to make parallel request to the engine script, wich becomes independant.
Maybe the solution is here : HTTP Parallel Request Library
Thus media_derivatives_start_encode() call the engine script in a specific file (media_derivatives_start_encode.php) with a non-blocking http_request, and sends the derivative object or any information required. This script creates a database entry with process status, then starts transfer/encoding/creation of derivative. Once completed, the script calls media_derivatives_derivative_finished() and update the database entry.
I've never used functions like that and i don't know if it's the right way, but this issue is here to discuss this subject.
Comment | File | Size | Author |
---|---|---|---|
#12 | 1323430_set_progress_information_12.patch | 1023 bytes | slashrsm |
#4 | 1323430_background_process_4.patch | 3.16 KB | slashrsm |
#3 | background_process-1323430.patch | 593 bytes | camdarley |
Comments
Comment #1
slashrsm CreditAttribution: slashrsm commentedI took a look at HTTP Parallel Request Library and I do not exactly see how to use it for this use case. media_derivatives itself do not call any http requests, so we could not use this module.
I also took a look at core's Batch API, but as I understand we cannot use it without default progress page. I think we do not need this progres, since we want to run processes in background, without any UI.
Searching further I found Background Process, which allows us to run processes in background. Processes can be accessed later, so we could build a UI list of currently active processes. It think this could be implemented as a recommended only dependency. media_derivatives could check if this module exists and use it. Current behaviour could be kept if there will be this module missing. Do you think this is right behaviour or should be make it a dependency?
Comment #2
camdarley CreditAttribution: camdarley commentedYou're right, i didn't know about Background Process but it seems to be exactly what we need.
You're right too about implement it as a recommended only dependency, although, in my opinion, all the engines take a long time to generate their derivatives. But as Background Process has its own dependencies, it may do a lot of modules to install, and it's better to let it optional.
I think the best would be creating a scheduler: 'Runs derivation in a background process' (with a modification of media_derivatives_schedule_derivative() to handle it) which is only accessible when Background Process is installed.
Comment #3
camdarley CreditAttribution: camdarley commentedI made a patch to implement Background Process.
I made a few test and it's working.
Maybe it could be better to have an option to activate or not...
Comment #4
slashrsm CreditAttribution: slashrsm commentedI added an option to enable/disable this. Can you check it a bit?
Comment #5
camdarley CreditAttribution: camdarley commentedPatch work fine for me. Thanks. Ready to be committed.
Background process provide a page to see all jobs processing. I'll dive into the code to see if it's possible to have a "derivatives only" similar page.
Also in the future, it might be useful to have a per preset option... what do you think about this?
Comment #6
slashrsm CreditAttribution: slashrsm commentedThat sounds reasonable. I could try to implement this in the following days and we could commit it together with this patch.
What do you think?
Comment #7
camdarley CreditAttribution: camdarley commentedI agree.
About the derivatives' background processes' page, here are my first thought:
If the first point could be easily committed, the second one need more investigation to find the right way.
I'm not actually a developer. I try to do my best but I lack some concepts of code.
Comment #8
slashrsm CreditAttribution: slashrsm commentedCommited: http://drupalcode.org/project/media_derivatives.git/commit/fad70fd
Thanks for that. I'm sorry because it took so long.
Renaming this issue to indicate what still needs to be done (comment #5).
Comment #9
gielfeldt CreditAttribution: gielfeldt commentedHi
To update the progress, this must be done from within the background process. Somewhere inside media_derivatives_start_encode() or one of its sub-functions you can do something like this:
Comment #10
slashrsm CreditAttribution: slashrsm commentedI think this should be done in encoding function itself, as those can determine, if even possible, how much work has been done.
Derivatives could implement API function that would wrap your code. Encoding function would then just call something like this:
Comment #11
gielfeldt CreditAttribution: gielfeldt commentedSounds reasonable. I was also thinking of creating a background_process_set_progress() function to take care of the handle check, but that might be overkill/unnecessary.
Comment #12
slashrsm CreditAttribution: slashrsm commentedHere is the patch. Can you check it?
Comment #13
gielfeldt CreditAttribution: gielfeldt commentedWithout having tested it, I think it looks fine.
Comment #14
slashrsm CreditAttribution: slashrsm commentedCommited to 7.x-1.x: http://drupalcode.org/project/media_derivatives.git/commit/a2c6578
I also added some info to api.php to inform engine developers about existence of this function.
Switching back to active since we solve original issue purpose.