The code powering m.abunchtell.com https://m.abunchtell.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

34 lines
1.2 KiB

  1. # frozen_string_literal: true
  2. class ProofProvider::Keybase::Worker
  3. include Sidekiq::Worker
  4. sidekiq_options queue: 'pull', retry: 20, unique: :until_executed
  5. sidekiq_retry_in do |count, exception|
  6. # Retry aggressively when the proof is valid but not live in Keybase.
  7. # This is likely because Keybase just hasn't noticed the proof being
  8. # served from here yet.
  9. if exception.class == ProofProvider::Keybase::ExpectedProofLiveError
  10. case count
  11. when 0..2 then 0.seconds
  12. when 2..6 then 1.second
  13. end
  14. end
  15. end
  16. def perform(proof_id)
  17. proof = proof_id.is_a?(AccountIdentityProof) ? proof_id : AccountIdentityProof.find(proof_id)
  18. verifier = ProofProvider::Keybase::Verifier.new(proof.account.username, proof.provider_username, proof.token)
  19. status = verifier.status
  20. # If Keybase thinks the proof is valid, and it exists here in Mastodon,
  21. # then it should be live. Keybase just has to notice that it's here
  22. # and then update its state. That might take a couple seconds.
  23. raise ProofProvider::Keybase::ExpectedProofLiveError if status['proof_valid'] && !status['proof_live']
  24. proof.update!(verified: status['proof_valid'], live: status['proof_live'])
  25. end
  26. end