Sha256: 8ef9b7353603011393d0900ef5d06e4aeaea17d04507a35eed60f2f02245ae95

Contents?: true

Size: 1.89 KB

Versions: 6

Compression:

Stored size: 1.89 KB

Contents

namespace :iqvoc do
  namespace :matches do
    stdout_logger = Logger.new(STDOUT)
    stdout_logger.level = Logger::INFO

    desc 'Create reverse matches jobs for already known matches'
    task :create_jobs => :environment do
      raise "You have to specify the host of the current iqvoc instance. Example: rake iqvoc:matches:create_jobs HOST='http://try.iqvoc.com' PORT='80'" unless ENV['HOST']
      raise "You have to specify the host of the current iqvoc instance. Example: rake iqvoc:matches:create_jobs HOST='http://try.iqvoc.com' PORT='80'" unless ENV['PORT']

      raise "Error: there are pending reverse match jobs. Clear or process them before." if Delayed::Job.where(queue: 'reverse_matches').any?

      iqvoc_sources = Iqvoc.config['sources.iqvoc'].map { |s| URI.parse(s) }
      host = ENV['HOST']
      port = ENV['PORT'].to_i

      reverse_match_service = Services::ReverseMatchService.new(host, port)

      Match::Base.includes(:concept).find_each do |m|
        target_base_uri = base_uri(m.value)

        # create jobs if target_base_uri is in iqvoc_sources
        if iqvoc_sources.include?(target_base_uri)
          job = reverse_match_service.build_job(:add_match, m.concept.origin, m.value, m.type)
          reverse_match_service.add(job)

          stdout_logger.info "Create #{job.match_class}-job: #{job.subject} => #{job.object}"
        else
          stdout_logger.info "#{m.value}: is not a known iQvoc source"
        end
      end
    end

    desc 'Delete all reverse matches jobs and job relations'
    task :delete_jobs => :environment do
      JobRelation.find_each do |jr|
        jr.job.destroy!
        jr.destroy!
      end
      stdout_logger.info "Cleared Jobs and JobRelations"
    end

    private

    def base_uri(url_string)
      target_uri = URI.parse(url_string)
      base_uri = URI.parse("#{target_uri.scheme}://#{target_uri.host}:#{target_uri.port}")
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
iqvoc-4.8.2 lib/tasks/matches.rake
iqvoc-4.8.1 lib/tasks/matches.rake
iqvoc-4.8.0 lib/tasks/matches.rake
iqvoc-4.7.0 lib/tasks/matches.rake
iqvoc-4.6.1 lib/tasks/matches.rake
iqvoc-4.6.0 lib/tasks/matches.rake