Class: Charming::Tasks::Progress
- Inherits:
-
Object
- Object
- Charming::Tasks::Progress
- Defined in:
- lib/charming/tasks/progress.rb
Overview
Progress is the reporter handed to task blocks that accept an argument:
run_task(:import) do |progress|
rows.each_with_index do |row, i|
import(row)
progress.report(i + 1, of: rows.length, message: row.name)
end
end
Each ‘report` pushes a TaskProgressEvent onto the runtime queue, which dispatches it to the controller’s matching ‘on_task_progress` handler.
Instance Method Summary collapse
-
#initialize(queue, name) ⇒ Progress
constructor
A new instance of Progress.
-
#report(current, of: nil, message: nil) ⇒ Object
Reports progress: current units done, optionally of: a total and with a human-readable message:.
Constructor Details
#initialize(queue, name) ⇒ Progress
Returns a new instance of Progress.
17 18 19 20 |
# File 'lib/charming/tasks/progress.rb', line 17 def initialize(queue, name) @queue = queue @name = name end |
Instance Method Details
#report(current, of: nil, message: nil) ⇒ Object
Reports progress: current units done, optionally of: a total and with a human-readable message:.
24 25 26 27 |
# File 'lib/charming/tasks/progress.rb', line 24 def report(current, of: nil, message: nil) @queue << Events::TaskProgressEvent.new(name: @name, current: current, total: of, message: ) nil end |