diff --git a/src/proto/single/mod.rs b/src/proto/single/mod.rs index 69e75bf8..704e9122 100644 --- a/src/proto/single/mod.rs +++ b/src/proto/single/mod.rs @@ -180,28 +180,19 @@ impl JobBuilder { } /// Builds a new [`Job`] from the parameters of this builder. - pub fn build(&self) -> Job { + /// + /// For Enterprise edition of Faktory builds a new _trackable_ `Job`. + /// In Enterprise Faktory, a progress update can be sent and received only for the jobs + /// that have been explicitly marked as trackable via `"track":1` in the job's custom hash. + /// In case you have a reason to opt out of tracking, either unset (remove) the "track" on + /// the resulted job's [`custom`](Job::custom) hash or set to 0. + pub fn build(&mut self) -> Job { + if cfg!(feature = "ent") { + self.add_to_custom_data("track", 1); + } self.try_build() .expect("All required fields have been set.") } - - /// Builds a new _trackable_ `Job``. - /// - /// Progress update can be sent and received only for the jobs that have - /// been explicitly marked as trackable via `"track":1` in the job's - /// custom hash. - /// ``` - /// use faktory::JobBuilder; - /// - /// let _job = JobBuilder::new("order") - /// .args(vec!["ISBN-13:9781718501850"]) - /// .build_trackable(); - /// ``` - #[cfg(feature = "ent")] - pub fn build_trackable(&mut self) -> Job { - self.add_to_custom_data("track", 1); - self.build() - } } #[derive(Serialize, Deserialize, Debug, Clone)] diff --git a/tests/real/enterprise.rs b/tests/real/enterprise.rs index 99a18ac8..c0c9f402 100644 --- a/tests/real/enterprise.rs +++ b/tests/real/enterprise.rs @@ -415,12 +415,14 @@ fn test_tracker_can_send_and_retrieve_job_execution_progress() { let job_tackable = JobBuilder::new("order") .args(vec![Value::from("ISBN-13:9781718501850")]) .queue("test_tracker_can_send_progress_update") - .build_trackable(); + .build(); - let job_ordinary = JobBuilder::new("order") + let mut job_ordinary = JobBuilder::new("order") .args(vec![Value::from("ISBN-13:9781718501850")]) .queue("test_tracker_can_send_progress_update") .build(); + // NB! Jobs are trackable by default, so we need to unset the "track" flag. + assert_eq!(job_ordinary.custom.remove("track"), Some(Value::from(1))); // let's remember this job's id: let job_id = job_tackable.id().to_owned(); @@ -514,9 +516,6 @@ fn test_tracker_can_send_and_retrieve_job_execution_progress() { assert!(t.lock().unwrap().set_progress(upd).is_ok()) } - // NB! The following should be failing if we decide to make all the jobs - // trackable by default in the Ent Faltory. - // What about 'ordinary' job ? let job_id = job_ordinary.id().to_owned().clone();