8000 Fixed the workflow redis key format used in `Client#next_free_workflow_id` by noahfpf · Pull Request #120 · chaps-io/gush · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fixed the workflow redis key format used in Client#next_free_workflow_id #120

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

Merged
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
2 changes: 1 addition & 1 deletion lib/gush/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def next_free_workflow_id
id = nil
loop do
id = SecureRandom.uuid
available = !redis.exists?("gush.workflow.#{id}")
available = !redis.exists?("gush.workflows.#{id}")

break if available
end
Expand Down
31 changes: 31 additions & 0 deletions spec/gush/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,37 @@
end
end

describe "#next_free_job_id" do
it "returns an id" do
expect(client.next_free_job_id('123', Prepare.to_s)).to match(/^\h{8}-\h{4}-(\h{4})-\h{4}-\h{12}$/)
end

it "returns an id that doesn't match an existing job id" do
workflow = TestWorkflow.create
job = workflow.jobs.first

second_try_id = '1234'
allow(SecureRandom).to receive(:uuid).and_return(job.id, second_try_id)

expect(client.next_free_job_id(workflow.id, job.class.to_s)).to eq(second_try_id)
end
end

describe "#next_free_workflow_id" do
it "returns an id" do
expect(client.next_free_workflow_id).to match(/^\h{8}-\h{4}-(\h{4})-\h{4}-\h{12}$/)
end

it "returns an id that doesn't match an existing workflow id" do
workflow = TestWorkflow.create

second_try_id = '1234'
allow(SecureRandom).to receive(:uuid).and_return(workflow.id, second_try_id)

expect(client.next_free_workflow_id).to eq(second_try_id)
end
end

describe "#persist_workflow" do
it "persists JSON dump of the Workflow and its jobs" do
job = double("job", to_json: 'json')
Expand Down
0