Skip to content

Commit

Permalink
add rake task to rerun waiting claims
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jun 5, 2021
1 parent 5a1aa88 commit d31d609
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 12 deletions.
5 changes: 3 additions & 2 deletions app/models/claim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,13 @@ def to_param # overridden, use uuid instead of id
def process_data(options = {})
start

result = options[:collect_data] || collect_data
result = collect_data

if result.body["skip"]
return finish! if claimed_at.present?

logger.info "[Skipped] #{uid}#{doi}] #{result.body['reason']}"
write_attribute(:error_messages, nil)

skip
elsif result.body["errors"]
Expand All @@ -206,7 +207,7 @@ def process_data(options = {})
# send notification to Sentry
# Raven.capture_exception(RuntimeError.new(result.body["errors"].first["title"])) if ENV["SENTRY_DSN"]

logger.error "[Error] #{uid}#{doi}] " + result.body["errors"].first["title"].inspect
logger.error "[Error] #{uid}#{doi} " + result.body["errors"].inspect

error!
elsif result.body["notification"]
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def process_data(options = {})
# send notification to Sentry
# Raven.capture_exception(RuntimeError.new(result.body["errors"].first["title"]))if ENV["SENTRY_DSN"]

logger.error result.body["errors"].first["title"]
logger.error result.body["errors"].inspect
else
write_attribute(:github_put_code, result.body["put_code"])
end
Expand Down
8 changes: 8 additions & 0 deletions lib/tasks/claim.rake
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ namespace :claim do
end
end

desc "Push all waiting claims"
task waiting: :environment do
Claim.waiting.find_each do |claim|
ClaimJob.perform_later(claim)
puts "[#{claim.aasm_state}] Pushed waiting claim #{claim.doi} for user #{claim.orcid} to ORCID."
end
end

desc "Get notification_access_token"
task get_notification_access_token: :environment do
response = Claim.last.notification.get_notification_access_token(
Expand Down
99 changes: 99 additions & 0 deletions spec/fixtures/vcr_cassettes/Claim/collect_data/invalid_token.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 8 additions & 9 deletions spec/models/claim_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,20 @@
expect(response.body).to eq("reason" => "No auto-update permission", "skip" => true)
end

it "invalid token" do
it "missing token" do
user = FactoryBot.create(:invalid_user)
subject = FactoryBot.create(:claim, user: user, orcid: "0000-0003-1419-240x", doi: "10.14454/v6e2-yc93", source_id: "orcid_update")
response = subject.collect_data
expect(response.body).to eq("reason" => "No user and/or ORCID token", "skip" => true)
end

it "invalid token" do
user = FactoryBot.create(:invalid_user, orcid_token: "123")
subject = FactoryBot.create(:claim, user: user, orcid: "0000-0003-1419-240x", doi: "10.14454/v6e2-yc93", source_id: "orcid_update")
response = subject.collect_data
expect(response.body).to eq("errors"=>[{"title"=>"Missing data"}])
end

it "no user" do
subject = FactoryBot.create(:claim, orcid: "0000-0001-6528-2027", doi: "10.14454/v6e2-yc93")
response = subject.collect_data
Expand All @@ -77,14 +84,6 @@
# expect(subject.state).to eq("failed")
# end

it "no errors with dependency injection" do
options = { collect_data: OpenStruct.new(body: { "put_code" => "1069294" }) }
expect(subject.process_data(options)).to be true
expect(subject.put_code).to eq(put_code)
expect(subject.claimed_at).not_to be_blank
expect(subject.state).to eq("done")
end

it "already exists" do
FactoryBot.create(:claim, user: user, orcid: "0000-0001-6528-2027", doi: "10.14454/j6gr-cf48", claim_action: "create", claimed_at: Time.zone.now, put_code: put_code)
expect(subject.process_data).to be true
Expand Down

0 comments on commit d31d609

Please sign in to comment.