Skip to content

Commit

Permalink
Make BatchHandle::add return option of old bid as serde_json::Value
Browse files Browse the repository at this point in the history
  • Loading branch information
rustworthy committed Feb 4, 2024
1 parent d10ceee commit ff3fd5f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
11 changes: 5 additions & 6 deletions src/proto/batch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,13 @@ impl<'a, S: Read + Write> BatchHandle<'a, S> {

/// Add the given job to the batch.
///
/// Should the submitted job - for whatever reason - already have a `bid` (batch ID) specified
/// in its custom hash, this value will be overwritten by the ID of the batch this job is being added to
/// with the old value returned as `Some(<old value here>)`.
pub fn add(&mut self, mut job: Job) -> Result<Option<String>, Error> {
/// Should the submitted job - for whatever reason - already have a `bid` key present in its custom hash,
/// this value will be overwritten by the ID of the batch this job is being added to with the old value
/// returned as `Some(<old value here>)`.
pub fn add(&mut self, mut job: Job) -> Result<Option<serde_json::Value>, Error> {
let bid = job
.custom
.insert("bid".into(), self.bid.clone().into())
.map(|bid| bid.to_string());
.insert("bid".into(), self.bid.clone().into());
self.prod.enqueue(job).map(|_| bid)
}

Check warning on line 232 in src/proto/batch/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/proto/batch/mod.rs#L227-L232

Added lines #L227 - L232 were not covered by tests

Expand Down
2 changes: 1 addition & 1 deletion tests/real/enterprise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ fn test_batch_of_jobs_can_be_initiated() {

assert!(b.add(job_1).unwrap().is_none());
assert!(b.add(job_2).unwrap().is_none());
assert_eq!(b.add(job_3).unwrap().unwrap(), "check-check");
assert_eq!(b.add(job_3).unwrap().unwrap(), Value::from("check-check"));
b.commit().unwrap();

// The batch has been committed, let's see its status:
Expand Down

0 comments on commit ff3fd5f

Please sign in to comment.