Class: Quorum::Job

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Sequence
Defined in:
app/models/quorum/job.rb

Class Method Summary collapse

Methods included from Sequence

#create_hash, #discover_input_sequence_type, #write_input_sequence_to_file

Class Method Details

.delete_jobs(time = 1.week) ⇒ Object

Delete submitted jobs.



106
107
108
109
110
111
112
# File 'app/models/quorum/job.rb', line 106

def self.delete_jobs(time = 1.week)
  if time.is_a?(String)
    time = time.split.inject { |count, unit| count.to_i.send(unit) }
  end

  self.where("created_at < '#{time.ago.to_s(:db)}'").destroy_all
end

.search(params) ⇒ Object

Return search results (Resque worker results).



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/models/quorum/job.rb', line 37

def self.search(params)
  data = JobData.new

  # Allow for multiple algos and search params.
  # Ex: /quorum/jobs/:id/search?algo=blastn,blastp
  if params[:algo]
    params[:algo].split(",").each do |a|
      if Quorum::SUPPORTED_ALGORITHMS.include?(a)
        enqueued = "#{a}_job".to_sym
        report   = "#{a}_job_reports".to_sym
        begin
          job = Job.find(params[:id])
        rescue ActiveRecord::RecordNotFound => e
          logger.error e.message
        else
          if job.try(enqueued).present?
            if job.try(report).present?
              data.results << job.try(report).search(a, params).default_order
            else
              data = JobData.new
            end
          else
            data.not_enqueued
          end
        end
      end
    end
  else
    data.no_results
  end

  data.results
end

.set_blast_hit_sequence_lookup_values(params) ⇒ Object

Fetch Blast hit_id, hit_display_id, queue Resque worker and return worker’s meta_id.



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'app/models/quorum/job.rb', line 75

def self.set_blast_hit_sequence_lookup_values(params)
  fetch_data   = JobFetchData.new
  algo         = params[:algo]
  algo_id      = params[:algo_id]

  if Quorum::SUPPORTED_ALGORITHMS.include?(algo)
    fetch_data.algo = algo
    begin
      job = Job.find(params[:id])
    rescue ActiveRecord::RecordNotFound => e
      logger.error e.message
    else
      algo_job         = "#{algo}_job".to_sym
      algo_job_reports = "#{algo}_job_reports".to_sym

      fetch_data.blast_dbs = job.try(algo_job).blast_dbs

      job_report = job.try(algo_job_reports).where(
        "quorum_#{algo}_job_reports.id = ?", algo_id
      ).first

      fetch_data.hit_id          = job_report.hit_id
      fetch_data.hit_display_id  = job_report.hit_display_id
    end
  end
  fetch_data
end