Skip to content

Commit

Permalink
Merge pull request #36 from inkstak/feature-read_multi
Browse files Browse the repository at this point in the history
Return progress with only one call to cache store
  • Loading branch information
inkstak committed Apr 18, 2024
2 parents 483458c + 5559622 commit 1a3c28e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/activejob-status/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def status
end

def progress
read[:progress].to_f / read[:total].to_f
read.then do |hash|
hash[:progress].to_f / hash[:total].to_f
end
end

def present?
Expand Down
8 changes: 8 additions & 0 deletions spec/specs/active_job/status_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ def jobs_with(*args, **kwargs)
expect(job.status.progress).to eq(0.4)
end
end

it "reads cache once" do
job = BaseJob.new

allow(described_class.store).to receive(:read)
job.status.progress
expect(described_class.store).to have_received(:read).once
end
end

describe "job status" do
Expand Down

0 comments on commit 1a3c28e

Please sign in to comment.