Skip to content

Commit

Permalink
Only use sidekiq for certificate generation
Browse files Browse the repository at this point in the history
Stop using `DelayedJob` for certificate generation
in parallel with sidekiq.
  • Loading branch information
pkqk committed Aug 21, 2015
1 parent f594099 commit f2833e1
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 20 deletions.
16 changes: 9 additions & 7 deletions app/controllers/datasets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,17 @@ def admin

def create
jurisdiction, dataset, create_user = params.values_at(:jurisdiction, :dataset, :create_user)
generator = CertificateGenerator.create(
request: dataset,
user: current_user,
certification_campaign: campaign
)
generator.delay.generate(jurisdiction, create_user, params[:existing_dataset])
existing_dataset_id = params[:existing_dataset].try(:id)
generator = CertificateGenerator.transaction do
CertificateGenerator.create(
request: dataset,
user: current_user,
certification_campaign: campaign)
end
CertificateGeneratorWorker.perform_async(generator.id, jurisdiction, create_user, existing_dataset_id)
render status: :accepted, json: {
success: "pending",
dataset_id: params[:existing_dataset].try(:id),
dataset_id: existing_dataset_id,
dataset_url: status_datasets_url(generator)
}
end
Expand Down
2 changes: 1 addition & 1 deletion features/api.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Feature: Open Data Certificate API
Background:
Given I want to create a certificate via the API

@sidekiq_fake
Scenario: API call returns pending initially
When I request a certificate via the API
And I request the status via the API
Expand All @@ -15,7 +16,6 @@ Feature: Open Data Certificate API
Scenario: API call with autocompleting data
Given my URL autocompletes via DataKitten
When I request a certificate via the API
And the certificate is created
And I request the results via the API
Then the API response should return sucessfully
And my certificate should be published
Expand Down
3 changes: 0 additions & 3 deletions features/campaigns.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Feature: Display information about campaigns in UI
Given I want to create a certificate via the API
And I apply a campaign "brian"
And I request a certificate via the API
And the certificate is created
And I request a certificate via the API
And I am signed in as the API user

Expand Down Expand Up @@ -35,7 +34,6 @@ Feature: Display information about campaigns in UI
And I apply a campaign "brian"
But I miss the field "dataTitle"
And I request a certificate via the API
And the certificate is created
When I visit the campaign page for "brian"
Then I should see "3 datasets inspected"
And I should see "2 datasets added"
Expand All @@ -47,7 +45,6 @@ Feature: Display information about campaigns in UI
And I apply a campaign "brian"
But I miss the field "dataTitle"
And I request a certificate via the API
And the certificate is created
When I visit the campaign page for "brian"
And I click the "Download CSV" link
Then I should get a CSV file
Expand Down
1 change: 0 additions & 1 deletion features/rerun_whole_campaigns.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Feature: Rerun campaigns
And the field "publisherUrl" is missing from my metadata
And my URL autocompletes via DataKitten
When I request a certificate via the API
And the certificate is created
And I visit the campaign page for "brian"
When I add the field "publisherUrl" with the value "http://example.com" to my metadata
And my URL autocompletes via DataKitten
Expand Down
5 changes: 2 additions & 3 deletions features/step_definitions/api_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
Given(/^I request (\d+) certificates with the campaign "(.*?)"$/) do |num, tag|
num.to_i.times do |i|
steps %Q{
Given I want to create a certificate via the API
Given I want to create a certificate via the API with the URL "http://example.com/dataset#{i}"
And I apply a campaign "#{tag}"
And I request a certificate via the API
}
Expand All @@ -51,7 +51,6 @@
Given(/^I create a certificate via the API$/) do
steps %Q{
When I request a certificate via the API
And the certificate is created
And I request the results via the API
Then the API response should return sucessfully
}
Expand Down Expand Up @@ -88,7 +87,7 @@
end

When(/^the certificate is created$/) do
generator = CertificateGenerator.all.select { |g| g.request["documentationUrl"] == @documentationURL }.first
generator = CertificateGenerator.all.find { |g| g.request["documentationUrl"] == @documentationURL }
generator.generate(@body[:jurisdiction], @body[:create_user])
end

Expand Down
1 change: 0 additions & 1 deletion features/step_definitions/campaign_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
Given I want to create a certificate via the API with the URL "http://data.example.com/datasets/#{i}"
And I apply a campaign "#{@campaign}"
And I request a certificate via the API
And the certificate is created
}
end
end
Expand Down
6 changes: 2 additions & 4 deletions test/functional/datasets_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,6 @@ class DatasetsControllerTest < ActionController::TestCase
dataset = certificate.dataset
http_auth FactoryGirl.create(:user)

CertificateGenerator.any_instance.stubs(:delay).returns CertificateGenerator.new
CertificateGenerator.any_instance.expects(:generate).once

assert_difference "CertificateGenerator.count", 1 do
Expand Down Expand Up @@ -431,7 +430,6 @@ class DatasetsControllerTest < ActionController::TestCase
load_custom_survey 'cert_generator.rb'
http_auth FactoryGirl.create(:user)

CertificateGenerator.any_instance.stubs(:delay).returns CertificateGenerator.new
CertificateGenerator.any_instance.expects(:generate).once

assert_difference "CertificateGenerator.count", 1 do
Expand All @@ -448,7 +446,7 @@ class DatasetsControllerTest < ActionController::TestCase
user = FactoryGirl.create(:user)
http_auth user

CertificateGenerator.any_instance.stubs(:delay).returns stub(generate: nil)
CertificateGeneratorWorker.expects(:perform_async).returns(nil)

assert_difference "CertificationCampaign.count", 1 do
post :create, {
Expand All @@ -471,7 +469,7 @@ class DatasetsControllerTest < ActionController::TestCase
other_user = FactoryGirl.create(:user)
http_auth generating_user

CertificateGenerator.any_instance.stubs(:delay).returns stub(generate: nil)
CertificateGeneratorWorker.expects(:perform_async).returns(nil)

assert_difference "CertificationCampaign.count", 1 do
post :create, jurisdiction: 'cert-generator',
Expand Down

0 comments on commit f2833e1

Please sign in to comment.