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
Enhance and fix resumable and ajax queues #1559
Conversation
Thanks I will try to optimize this a bit. |
I did not remove all interval use. |
Yes I agree - are you working on that part? Let know... I thought I could optimize the Task manager code a bit. But maybe will wait till you confirm posting your updates. |
Yes, my bad. I will let tout know when its ready. |
Think this is ready for you to check and test. |
Thanks. I am checking this and have tried to optimize the TaskManager lib. The initial issue I am seeing is that pause and resume functionality seems broken somewhere as well as updating of the main progress bar. Will need to check and test in detail if anything else. |
There needs to be a pause and resume feature - need to check your task pool implementation - currently it has only cancel and success. |
You're right looks like there is an issue with resuming. It restarts uploading all chunks. As for the main progress bar i'm not sure what is causing this issue i tried to keep original code as much as possible. I need to check where it is updated. Checking this. |
Ok i fixed things for resume uploads. I tested resume. It seems ok to me. I noticed a bug though. When an upload starts for multiple files. I you pause, then browse and add a file. It's size is not added to |
As for tasks. It can't be paused of course as well as Ajax queries since they are promises. But undone chunks (tasks) can be re-added to the queue. This is the actual behavior. So there is no pause related code in task manager. I you want so I can squash the PR. |
Thanks - you can. |
…ng taskmanager) - changed fileManager.processed to fileManager.filesProcessed this makes more sense, for code readability this is an optional change - changed Object.keys to $h.getObjectKeys method this is an optional change https://stackoverflow.com/questions/5223/length-of-a-javascript-object - added getObjectKeys method in $h - added getObjectSize method in $h - added taskManager in $h - added $.whenAll jquery extension to handle running all chunks a once if resumableUploadOptions.maxThreads is equal to 0 I think this could be removed, since we could want chunks to always be uploaded "maxThreads" at a time. If so some code in taskManager.TasksPool.runAllTasksParallels could be remove the "// if run all at once" part with the jquery extension - ajax requests are stand alone tasks (promises) - resumable uploads are a pool of tasks foreach chunks they are runned in parrallel I wont remove the last setInterval for upload: function this is too much work, and code readability is poor in my opinion. It would benefit to be reactored using an object approach instead of a functionnal programming. There should also be a unique upload method: resumable. It would be adapted for each options. This is too much work. :( Fixed resume upload - renamed rm.filesProcessed to rm.chunksProcessed (I was misunderstanding this, my bad) - don't reset chunksProcessed on upload start - push ajax only for undone chunks - remove progress cancelled when cancelling tasks on pause
done. |
Thanks. I am not finding issues with the main progress bar updating in the new code ... can you let know - what is the issue you are facing with the main progress bar update? Will check the other parts in the meanwhile - adding a new file to a paused resumable. |
I think the task manager code in itself can be optimized to a more compressed one than it exists now. I will do it myself at the end once we get the others tested. |
My last commit fixed the main progress bar issue i had.
Sure, there is code we can pull out. For example. the jquey plugin introducing |
} | ||
|
||
// if run all at once | ||
if (!maxParallelsTaskNumber) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be removed eventually if you won't allow maxParallelsTaskNumber to be 0
* Small dependency injection for the task manager | ||
* https://gist.github.com/fearphage/4341799 | ||
*/ | ||
$.whenAll = function(array) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be removed eventually if you don't allow maxParallelsTaskNumber to be 0
rm.sendAjax(index, arr[1], deferrer); | ||
return; | ||
} else { | ||
console.log('wtf'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is one issue I am seeing on the pause and resume. When you pause it once and then resume it works fine. But when you pause and resume more than once for the same file - the code runs into an issue and enters this console.log... need to check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OKay i'll look at that.
I am seeing some issues on my project that needs to be inverstigated:
This is because hxr promise is rejected ( calling abort method ), It is not handled properly. |
Yes abort of xhr is expected in case of cancel ... to terminate the ajax requests in process..., but for pause and resume I feel the resumableManager init must not happen unlike how it happens during cancel or a fresh upload. So interestingly --- I took up your PR modification - you did on intervals ... the last updated one before you introduced the queue... I modified that code a bit for pause and resume...seems to work well for most part... only need to check the new file added during pause state... |
Yes i could make it work using interval, but it seems to me it wasn't a good solution. I feel like using promises is a more neat solution. It is up to you after all to decide what you want to use.
This should not raise |
|
I had this taught also. It happens that you are calling reset only when a fresh upload would occur. this is not really intuitive. Imao, code could be restructured in a more object oriented style. It would be easier to maintain. Maybe using coffeescript ? But this is a lot of work. |
Great. Will have a look at this. |
I have been thinking of major revamp to the library as well . Initially this library was created as a bootstrap extension for file input and upload and features kept getting added with resumable uploads coming up recently. Meanwhile, we had bootstrap versions going from 2.x, then 3.x and now bootstrap 4.x and plugin changed to cater to these releases and throughout has been also dependent on the jQuery library. If you are interested we can collaborate on a new branch or even a new repo to create a rehash of this library with latest javascript or coffeescript so that it works across all other frameworks. |
Sure I would like to collab on my free time. I am also working on my own side project ( a laravel file manager ), so working on my free time.
Which specific framework are you referring to ? I am a Php full stack dev, and I have some experience with C# and other compiled code, but I am not a professional JS dev. I would have some suggestions though. But please give us some guidelines first. In the meantime would you like to finish this PR first ? |
I meant, make it extensible to be used in other javascript frameworks beyond jQuery - e.g. react, angular etc.. (or make jQuery optional) if needed. Which means work with pure javascript - but it needs a bit of rethink. Anyway this is a separate project to take up and can be done in free time.
Yes I have taken your code and done some updates and final changes - and now it seems to work fine - but I am doing some testing on this at my end and will close the PR if all goes fine. |
Nice.
I see, removing jQuery could be done in vanilla JS of course. But as you said before if we don't want to reinvent the wheel, the question would be which browser you want to support. I guess not under ie9 or may be ie10 ? |
Enhancement done and pushed. I have taken and refactored your code and simplified / optimized the queue functionality. Have a relook from your end on your testing and let know as well. |
I think tp.run, callback method is run before sendAjax.fnError in JS queue. So the Task manager will think all task are done, but another task will be inserted just after that. It looks to be some kind of race condition. To be sure to reproduce this testing on local host, you should reduce bandwidth using firefox debugger. |
Will check in sometime on this. please share your findings in the meanwhile. |
Solved the isse with this patch, tasksCount was not updated dynamically when ajax quieries were failing and adding more tasks.
|
|
Thanks.. I will fix all of these and the filechunk events for aborted scenarios via a separate issue tracking that. |
All combined together and fixed via #1561. Please check and report anything over that issue so we can track that. Thanks. |
Scope
This pull request includes a
Changes
The following changes were made
changed fileManager.processed to fileManager.filesProcessed
this makes more sense, for code readability
this is an optional change
changed Object.keys to $h.getObjectKeys method
this is an optional change
https://stackoverflow.com/questions/5223/length-of-a-javascript-object
added getObjectKeys method in $h
added getObjectSize method in $h
added taskManager in $h
added $.whenAll jquery extension to handle running all chunks a once if
resumableUploadOptions.maxThreads is equal to 0
I think this could be removed, since we could want
chunks to always be uploaded "maxThreads" at a time.
If so some code in taskManager.TasksPool.runAllTasksParallels
could be remove the "// if run all at once" part with the jquery
extension
ajax requests are stand alone tasks (promises)
resumable uploads are a pool of tasks foreach chunks
they are runned in parrallel
I wont remove the last setInterval for upload: function
this is too much work, and code readability is poor in my opinion.
It would benefit to be reactored using an object approach
instead of a functionnal programming.
There should also be a unique upload method: resumable.
It would be adapted for each options
Related Issues
#1557