evaluate task: move evaluation leg work in to another function, and just call it from the consumer implementation

This commit is contained in:
Graham Christensen 2020-03-31 17:26:15 -04:00
parent ea2f7cf474
commit 39af0ae208
No known key found for this signature in database
GPG key ID: FE918C3A98C1030F

View file

@ -83,36 +83,8 @@ impl<E: stats::SysEvents> EvaluationWorker<E> {
}
}
}
}
impl<E: stats::SysEvents + 'static> worker::SimpleWorker for EvaluationWorker<E> {
type J = evaluationjob::EvaluationJob;
fn msg_to_job(
&mut self,
_: &Deliver,
_: &BasicProperties,
body: &[u8],
) -> Result<Self::J, String> {
self.events.notify(Event::JobReceived);
match evaluationjob::from(body) {
Ok(e) => {
self.events.notify(Event::JobDecodeSuccess);
Ok(e)
}
Err(e) => {
self.events.notify(Event::JobDecodeFailure);
error!(
"Failed to decode message: {:?}, Err: {:?}",
String::from_utf8(body.to_vec()),
e
);
Err("Failed to decode message".to_owned())
}
}
}
fn consumer(&mut self, job: &evaluationjob::EvaluationJob) -> worker::Actions {
fn evaluate_job(&mut self, job: &evaluationjob::EvaluationJob) -> worker::Actions {
let mut vending_machine = self
.github_vend
.write()
@ -362,6 +334,38 @@ impl<E: stats::SysEvents + 'static> worker::SimpleWorker for EvaluationWorker<E>
}
}
impl<E: stats::SysEvents + 'static> worker::SimpleWorker for EvaluationWorker<E> {
type J = evaluationjob::EvaluationJob;
fn msg_to_job(
&mut self,
_: &Deliver,
_: &BasicProperties,
body: &[u8],
) -> Result<Self::J, String> {
self.events.notify(Event::JobReceived);
match evaluationjob::from(body) {
Ok(e) => {
self.events.notify(Event::JobDecodeSuccess);
Ok(e)
}
Err(e) => {
self.events.notify(Event::JobDecodeFailure);
error!(
"Failed to decode message: {:?}, Err: {:?}",
String::from_utf8(body.to_vec()),
e
);
Err("Failed to decode message".to_owned())
}
}
}
fn consumer(&mut self, job: &evaluationjob::EvaluationJob) -> worker::Actions {
self.evaluate_job(job)
}
}
fn send_check_statuses(checks: Vec<CheckRunOptions>, repo: &hubcaps::repositories::Repository) {
for check in checks {
match repo.checkruns().create(&check) {