Module: OpenLoam::Progress
- Defined in:
- lib/open_loam/progress.rb
Overview
Entry point for progress tracking. Start a job, then drive it through the returned OpenLoam::ProgressJob:
progress = OpenLoam::Progress.start(name: "Reindex", total: equipment.count)
equipment.find_each do |record|
break if progress.cancelled? # cooperative cancel
do_work(record)
progress.advance # throttled SSE push
end
progress.complete!
The job is created in the current tenant (and stamped with the current actor), so it is only visible and streamable there. In a background job, establish the tenant with OpenLoam.as_tenant first, like the webhook/digest jobs.
Class Method Summary collapse
Class Method Details
.start(name:, total:, key: nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/open_loam/progress.rb', line 19 def start(name:, total:, key: nil) OpenLoam::ProgressJob.create!( key: key, name: name, total: total.to_i, completed: 0, status: "running", actor_id: OpenLoam.actor&.id, started_at: Time.current ) end |