Skip to content
Browse files

Changed SNP-parsing to be done by resque. Unsure why it not works yet.

  • Loading branch information...
1 parent fb5717a commit 1a78a31f61b49c0017288ed0b61e748aabe6ab62 @philippbayer philippbayer committed
Showing with 32 additions and 18 deletions.
  1. +1 −0 Gemfile
  2. +2 −0 Gemfile.lock
  3. +1 −0 Rakefile
  4. +4 −18 app/controllers/genotypes_controller.rb
  5. +20 −0 app/jobs/parse_snps.rb
  6. +1 −0 config/initializers/resque.rb
  7. +3 −0 lib/tasks/resque.rake
View
1 Gemfile
@@ -11,6 +11,7 @@ gem 'rails3-generators'
gem 'sqlite3'
gem 'email_veracity'
gem 'resque'
+gem 'SystemTimer'
# Use unicorn as the web server
# gem 'unicorn'
View
2 Gemfile.lock
@@ -1,6 +1,7 @@
GEM
remote: http://rubygems.org/
specs:
+ SystemTimer (1.2.3)
abstract (1.0.0)
actionmailer (3.0.9)
actionpack (= 3.0.9)
@@ -92,6 +93,7 @@ PLATFORMS
ruby
DEPENDENCIES
+ SystemTimer
authlogic
email_veracity
rails (= 3.0.9)
View
1 Rakefile
@@ -1,6 +1,7 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+require 'resque/tasks'
require File.expand_path('../config/application', __FILE__)
require 'rake'
View
22 app/controllers/genotypes_controller.rb
@@ -27,7 +27,9 @@ def create
if @genotype.save
current_user.toggle!(:has_sequence)
@genotype.move_file
- parse_snps(@genotype)
+ #parse_snps(@genotype)
+ # we want to enqueue the job instead
+ Resque.enqueue(Parse, @genotype)
format.html { redirect_to(current_user, :notice => 'Genotype was successfully uploaded') }
format.xml { render :xml => current_user, :status => :created, :location => @user }
else
@@ -69,20 +71,4 @@ def do_upload_genotype
end
end
- def parse_snps(genotype)
- genotype_file = File.open(::Rails.root.to_s+"/public/data/"+ @genotype.fs_filename, "r")
- new_snps = genotype_file.readlines
- new_snps.each do |single_snp|
- if single_snp[0] != "#"
- snp_array = single_snp.split("\t")
- if snp_array.length == (4)
- @snp = Snp.new()
- @snp.name = snp_array[0]
- @snp.chromosome = snp_array[1]
- @snp.position = snp_array[2]
- @snp.save
- end
- end
- end
- end
-end
+end
View
20 app/jobs/parse_snps.rb
@@ -0,0 +1,20 @@
+module Parse
+ @queue = :parse
+
+ def parse_snps(genotype)
+ genotype_file = File.open(::Rails.root.to_s+"/public/data/"+ @genotype.fs_filename, "r")
+ new_snps = genotype_file.readlines
+ new_snps.each do |single_snp|
+ if single_snp[0] != "#"
+ snp_array = single_snp.split("\t")
+ if snp_array.length == (4)
+ @snp = Snp.new()
+ @snp.name = snp_array[0]
+ @snp.chromosome = snp_array[1]
+ @snp.position = snp_array[2]
+ @snp.save
+ end
+ end
+ end
+ end
+end
View
1 config/initializers/resque.rb
@@ -0,0 +1 @@
+Dir["#{Rails.root}/app/jobs/*.rb"].each { |file| require file }
View
3 lib/tasks/resque.rake
@@ -0,0 +1,3 @@
+require 'resque'
+
+task "resque:setup" => :environment

0 comments on commit 1a78a31

Please sign in to comment.
Something went wrong with that request. Please try again.