com.walmartlabs.active-status.progress
added in 0.1.15
Utilties to make it easier for long-running jobs to report progress.
elapsed-time-job
(elapsed-time-job status-board)(elapsed-time-job status-board options)Starts a job that presents elapsed time. This continues until the status board is shutdown.
- Options
- :delay-millis (default 0)
- Delay before the job is created and first updated.
- :interval-millis (default 1000)
- Interval between updates.
- :prefix (default
elapsed time:) - Prefix for job.
- :formatter (default format-elapsed-time)
- Formats elapsed time to a string.
format-elapsed-time
(format-elapsed-time millis)Formats a number of milliseconds of elapsed time into units of days, hours, minutes, and seconds.
report-progress
(report-progress interval job-ch formatter)Returns a transducer that counts and periodically reports the progress (using a status board job), including a final summary at the end.
The interval is in terms of values that pass through the tranducer.
The formatter is generally a string passed to format, along with the current count. Alternately, it can be a function that is passed the count and returns a string.
Technically, this is a count of how many values have passed through this tranducer (but could be queued elsewhere after this tranducer), but that is generally accurate enough for reporting progress.
Example:
(let [rows-ch (query-db ...) ;; returns channel that conveys rows
job-ch (as/add-job status-board)
work-ch (asyc/pipe rows-ch (chan 1 (report-progress 25 job-ch "read %,d rows")))]
(go-loop []
(when-let [row (<! work-ch)]
... ;; do work with the row
(recur))))
This will report on the job every 25 rows, and once more (with the final count) when the rows-ch channel closes.
report-progress?
(report-progress? n interval)Returns true if n is non-zero and an even multiple of interval.