code critique?
May. 16th, 2014 05:32 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Guys, I do appreciate your opinions a lot.
What happens here: we upload until we are out of patience with a streak of bad luck, probably meaning the server is dead.
val patience = 10 case class UploadProgress(uploaded: Set[File] = Set.empty, failed: Set[Result[File]] = Set.empty, badLuckStreak: Int = 0) { def errors = Result.traverse(failed) def +(file:File) = { if (badLuckStreak > patience) this else { uploadOneFile(file) match { case Good(file) => UploadProgress(uploaded + file, failed, 0) case bad => UploadProgress(uploaded, failed + bad, badLuckStreak + 1) } } } } def uploadScheduledFiles():UploadProgress = { if (!client.isAlive) UploadProgress(Set.empty, Set(Result.error("Upload server is dead, sorry")), 0) else { (UploadProgress() /: listFilesForUpload)(_ + _) } }
What happens here: we upload until we are out of patience with a streak of bad luck, probably meaning the server is dead.
no subject
Date: 2014-05-17 04:03 am (UTC)We appreciate ours too. ;)
no subject
Date: 2014-05-17 04:29 am (UTC)no subject
Date: 2014-05-17 04:54 am (UTC)no subject
Date: 2014-05-17 05:11 am (UTC)no subject
Date: 2014-05-17 04:57 am (UTC)if not using the Akka actors.
no subject
Date: 2014-05-17 05:11 am (UTC)But actually, I was planning to just have a parallel collection; is not it enough?
Also, judging by the iq level of the server, I've abandoned the idea of sending all of them in one fell swoop, in one request.
no subject
Date: 2014-05-17 11:01 am (UTC)no subject
Date: 2014-05-17 03:23 pm (UTC)no subject
Date: 2014-05-18 12:42 am (UTC)no subject
Date: 2014-05-18 12:51 am (UTC)no subject
Date: 2014-05-18 01:42 pm (UTC)But as first draft step IMHO it isn't so bad :) Further it always can be improved more.
no subject
Date: 2014-05-17 11:07 am (UTC)So instead of create whole bunch of task it better would create some stream of chunks with them.
IMHO.
no subject
Date: 2014-05-17 08:08 am (UTC)Вот про такое место вы знаете?
http://codereview.stackexchange.com
Мне интересно читать такие посты, не подумайте, просто там заведомо шире аудитория.
no subject
Date: 2014-05-17 03:24 pm (UTC)no subject
Date: 2014-05-18 12:11 am (UTC)If there are N files to upload, start N asynchronous upload tasks; the continuation for each task should check the result and update the corresponding item in the collection of N results. After all the N tasks are started, call asynchronous wait_all/when_all for the collection of the started tasks.
Bonus point if the platform's library provides an asynchronous implementation of HTTP POST: it's naturally IO-bound so shouldn't block any threads. Double-bonus if it supports cooperative cancellation.
This pattern is first-class citizen in C#/.NET these days with full library support of asynchronous I/O functions and compiler support for automatic code rewriting into continuation-passing style for asynchrony. There should be something for Scala too (first link of https://www.google.com/search?q=async+await+scala seems relevant).
no subject
Date: 2014-05-18 12:29 am (UTC)The problem is, I have to stop them all if n report failure... well, is it a problem? Probably not.
no subject
Date: 2014-05-18 12:53 am (UTC)no subject
Date: 2014-05-18 09:27 am (UTC)no subject
Date: 2014-05-18 03:50 pm (UTC)