pub struct Task { /* private fields */ }Expand description
A task is a specific tracked operation. It has:
- A Name
- A unique ID
- A creation time
- The current progress of the task (in “elements”), the ‘counter’.
- An (optional) maximum number of elements.
- A time the task was “started”
- The estimated amount of time the task has remaining
- A time the task has “ended”
- A list of any “Child Tasks” that this task can spawn.
Implementations§
Source§impl Task
impl Task
Sourcepub fn new(id: u64, name: String, max_elements: u64) -> Task
pub fn new(id: u64, name: String, max_elements: u64) -> Task
Creates a new finite, named task with the specified ID.
Sourcepub fn new_infinite(id: u64, name: String) -> Task
pub fn new_infinite(id: u64, name: String) -> Task
Creates a new infinite, named task with a specific ID.
Sourcepub fn new_infinite_named(name: String) -> Task
pub fn new_infinite_named(name: String) -> Task
Creates a new infinite, named task with a random ID
Sourcepub fn new_named(name: String, max_elements: u64) -> Task
pub fn new_named(name: String, max_elements: u64) -> Task
Creates a new finite, named task with a random ID.
Sourcepub fn current_progress_count(&self) -> u64
pub fn current_progress_count(&self) -> u64
Returns the number of elements completed in the range 0..=max_elements
Sourcepub fn set_current_progress_count(&self, current_progress: u64)
pub fn set_current_progress_count(&self, current_progress: u64)
Updates the current progress counter to be the specified value
Sourcepub fn max_elements(&self) -> u64
pub fn max_elements(&self) -> u64
Returns the maximum number of elements of this task
pub fn set_max_elements(&self, max_elements: u64)
Sourcepub fn current_progress_frac(&self) -> f64
pub fn current_progress_frac(&self) -> f64
Returns the current progress as a fraction in the range 0..=1
Sourcepub fn get_created(&self) -> UnixTimestamp
pub fn get_created(&self) -> UnixTimestamp
Returns the time this task was created
Sourcepub fn get_started(&self) -> Option<&UnixTimestamp>
pub fn get_started(&self) -> Option<&UnixTimestamp>
Returns the time at which this task started, or None if the task hasn’t started yet.
Sourcepub fn mark_one_completed(&self)
pub fn mark_one_completed(&self)
Increments the ‘completed’ counter.
Sourcepub fn mark_all_completed(&self)
pub fn mark_all_completed(&self)
Mark this task complete. Does not affect sub-tasks.
Sourcepub fn mark_some_completed(&self, completed: u64)
pub fn mark_some_completed(&self, completed: u64)
Mark some some portion of this task as completed.
pub fn get_remaining_time(&self) -> Duration
Sourcepub fn mark_started(&self)
pub fn mark_started(&self)
Marks this task as started. If the task has already started, does nothing.
Sourcepub fn get_ended(&self) -> Option<&UnixTimestamp>
pub fn get_ended(&self) -> Option<&UnixTimestamp>
Returns the time at which this task ended, or None if the task hasn’t ended yet.
Sourcepub fn mark_ended(&self)
pub fn mark_ended(&self)
Marks this task as ended. If this task has already ended, does nothing.
Sourcepub fn num_children(&self) -> usize
pub fn num_children(&self) -> usize
Returns the number of child tasks this task has
Sourcepub fn each_child<F: FnMut(&Task)>(&self, func: F)
pub fn each_child<F: FnMut(&Task)>(&self, func: F)
Iterates over each child task, providing a reference of the child task to the input function
pub fn clean_completed_children(&self) -> Vec<Task>
Sourcepub fn new_child_task(&self, id: u64, name: String, max_elements: u64) -> Task
pub fn new_child_task(&self, id: u64, name: String, max_elements: u64) -> Task
Creates a new child task of this task
Sourcepub fn push_new_child_task(&self, task: Task)
pub fn push_new_child_task(&self, task: Task)
Appends this task as a tracked child task.
Sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
Returns true if this task is complete.
Sourcepub fn cancel(&self)
pub fn cancel(&self)
Marks this task as “Cancelled”. Users of this task may opt to ignore this flag, it’s really more like a suggestion.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Returns true if this task has been marked ‘cancelled’. Cancelling a task is a one-way operation.
Sourcepub fn current_status(&self) -> Option<Arc<String>>
pub fn current_status(&self) -> Option<Arc<String>>
Gets a copy of the current status
Sourcepub fn set_current_status<T: AsRef<str>>(&self, status: Option<T>)
pub fn set_current_status<T: AsRef<str>>(&self, status: Option<T>)
Sets the optional current status of this task