Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return progress with only one call to cache store #36

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading