Skip to content

Commit

Permalink
Make jobs trackable by deafult
Browse files Browse the repository at this point in the history
  • Loading branch information
rustworthy committed Feb 2, 2024
1 parent 120978b commit 01fd744
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
29 changes: 10 additions & 19 deletions src/proto/single/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
9 changes: 4 additions & 5 deletions tests/real/enterprise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 01fd744

Please sign in to comment.