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

Log instantiation failures #134

Merged
merged 10 commits into from Mar 18, 2018
Merged

Log instantiation failures #134

merged 10 commits into from Mar 18, 2018

Conversation

grahamc
Copy link
Member

@grahamc grahamc commented Mar 18, 2018

No description provided.

@grahamc
Copy link
Member Author

grahamc commented Mar 18, 2018

Bug: the snippet log isn't being sent when no attempt is made.

Copy link
Member

@Ekleog Ekleog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly style points, as I'm not used enough with ofborg's codebase (yet?) to make actually useful points 👍

@@ -94,6 +96,10 @@ impl<'a, 'b> JobActions<'a, 'b> {
};
}

pub fn log_snippet(&self) -> VecDeque<String> {
self.snippet_log.clone()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about returning a &VecDeque<String> (with &self.snippet_log), so that the caller can clone() if need be?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had actually already changed this to return a Vec to be easier to pass to the build-result message.

@@ -55,6 +55,7 @@ pub struct JobActions<'a, 'b> {
receiver: &'a mut notifyworker::NotificationReceiver,
job: &'b buildjob::BuildJob,
line_counter: u64,
snippet_log: VecDeque<String>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A ring buffer would likely make more sense, both from a performance and a code simplicity standpoint, but maybe the added dependency isn't worth it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, a ring buffer would be nice here... perhaps an easy thing for a newbie to contribute (cc @LnL7)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm spending most of my time on ZHF right now, but that sounds like a fun distraction 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://doc.rust-lang.org/std/collections/vec_deque/
This queue has O(1) amortized inserts and removals from both ends of the container.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the main reason for wanting a ring buffer is it means it'd allow to avoid having to manually maintain the invariant by hand, not performance (which, if I remember correctly how deques are implemented, should still be better in the constant, thanks to not allocating/deallocating memory frequently)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

println!("----->8-----");

let last10lines: Vec<String> = snippet_log.into_iter().collect::<Vec<String>>();
let last10lines: Vec<String> = actions.log_snippet().into_iter().collect::<Vec<String>>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If following my above-mentioned advice of returning an &VecDeque<_> from log_snippet(), this should just become .iter(), so that the returned value isn't consumed. Also, the ::<Vec<String>> isn't required if there's the : Vec<String> type annotation on the variable declaration, only one is needed for type inference to work, usually (and here I'd guess none is actually needed, as the last10lines variable is then passed to a function, thus forcing its type).

Vec<Result<String, (String, Vec<String>)>>,
Vec<Result<String, (String, Vec<String>)>>) = attr_instantiations
.into_iter()
.partition(|x| x.is_ok());
Copy link
Member

@Ekleog Ekleog Mar 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be shortened (simplified?) into let (ok, err): (Vec<_>, Vec<_>) = attr_instantiations.into_iter().partition(|x| x.is_ok());
EDIT: actually, see below, this may not be actually a useful point to make if this part is to be deleted anyway.

return (
ok_ret,
err_ret
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I think it'd be cleaner (and likely much faster, though that's not the point) to just not try using iterators, and have let mut ok_ret; let mut err_ret;, do a big for look on the attrs, and just push to both vectors.

Something like (untested & typed in the github comment box):

let mut ok = Vec::new();
let mut err = Vec::new();
for attr in attr_instantiations.into_iter() {
    match self.safely_instantiate_attrs(nixpkgs, file, vec![attr.clone()]) {
        Ok(_) => { ok.push(attr); }
        Err(f) => { err.push((attr, lines_from_file(f))); }
    }
}
(ok, err)

(also, it's standard practice to omit the return keyword where possible)

@grahamc grahamc merged commit 41da488 into next Mar 18, 2018
@grahamc grahamc deleted the log-instantiation-failures branch March 18, 2018 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants