app/controllers/jobs_controller.rb
# users should be able to resubmit a job. But, this should be as a new job so that the
# old output is preserved - this might be useful in cases where the job version has changed
# and a comparison of old and new output is required
users should be able to resubmit a job. But, this should be as a new job so that the
old output is preserved - this might be useful in cases where the job version has changed
and a comparison of old and new output is required
users should be able to resubmit a job . But this should be as a new job so that the old output is preserved - this might be useful in cases where the job version has changed and a comparison of old and new output is required
def recreate
    @oldjob = Job.find(params[:id])
    @type = @oldjob.type
    @headers = @oldjob.type
    @title = "Re-submitting analysis"
    @text = "<p>You may edit this job before it is re-submitted.</p>"
    if !check_user(@oldjob) 
      flash[:alert] =  'Invalid job ID'
      redirect_to :jobs and return
    end
    account = Account.first(:users => current_user.id)
    if Time.now - (60 * 60 * 24) > Date.strptime(account.expiry[@type], "%d/%M/%Y")
      flash[:alert] = "Your account has expired. Please contact the administrator to re-instate it"
      redirect_to :jobs and return
    end
    if account.credits[@type].to_i <= 0 and account.arrears[@type] == 'no'
      flash[:alert] = "Your account has no credit left. Please contact the administrator to obtain more"
      redirect_to :jobs and return
    end
    case @type
      when 'beast'
        version = @oldjob.version
      when 'left', 'sdm', 'lcc'
        version = IO.readlines("#{Vibrant::Application.config.dropbox}/#{@type}/version.txt")[0].chomp!
      else
        version = "N/A"
    end
    @job = Job.new
    @job.inputurl = @oldjob.inputurl
    @job.job_description = @oldjob.job_description 
    @job.job_name = @oldjob.job_name
    @job.version = version
    @job.email = @oldjob.email
    @job.type = @oldjob.type
    begin
      if !@oldjob.infile.nil?
        tempfile = Tempfile.open(@oldjob.infile_name)
        tempfile.write(@oldjob.infile.read.force_encoding('UTF-8')) 
        @job.infile = File.open(tempfile)
        tempfile.unlink
        if !@oldjob.proper_infilename.nil?
          @job.proper_infilename = @oldjob.proper_infilename
        else
          @job.proper_infilename = @oldjob.infile_name
        end
      end
    rescue
      Rails.logger.error("Infile copy failed when resubmitting job #{@oldjob.id}")
      flash[:alert] = 'Resubmission failed'
      redirect_to "/jobs/#{@oldjob.id}" and return
    end
    begin
      if !@oldjob.parameters.nil?
        @job.parameters = @oldjob.parameters
      end
      if !@oldjob.vars[:oscid].nil?
        @job.vars[:oscid] = 'N/A' 
      end
      if !@oldjob.parameters[:identifier].nil?
        @job.parameters[:identifier] = 'N/A' 
      end
    rescue
      Rails.logger.error("Parameter copy failed when resubmitting job #{@oldjob.id}")
      flash[:alert] = 'Resubmission failed'
      redirect_to "/jobs/#{@oldjob.id}" and return
    end
    @job.status = 'held'
    if @job.save!
      flash[:notice] = 'Please check your job and submit'
      redirect_to :controller => 'jobs', :action => 'edit', :id => @job.id and return
    else
      Rails.logger.error("Save failed for resubmission of job #{@oldjob.id}")
    end
  end
def recreate @oldjob = Job . find ( params [ :id ] ) @type = @oldjob . type @headers = @oldjob . type @title = "Re-submitting analysis" @text = "<p>You may edit this job before it is re-submitted.</p>" if ! check_user ( @oldjob ) flash [ :alert ] = 'Invalid job ID' redirect_to :jobs and return end account = Account . first ( :users => current_user . id ) if Time . now - ( 60 * 60 * 24 ) > Date . strptime ( account . expiry [ @type ] , "%d/%M/%Y" ) flash [ :alert ] = "Your account has expired. Please contact the administrator to re-instate it" redirect_to :jobs and return end if account . credits [ @type ] . to_i <= 0 and account . arrears [ @type ] == 'no' flash [ :alert ] = "Your account has no credit left. Please contact the administrator to obtain more" redirect_to :jobs and return end case @type when 'beast' version = @oldjob . version when 'left' , 'sdm' , 'lcc' version = IO . readlines ( "#{Vibrant::Application.config.dropbox}/#{@type}/version.txt" ) [ 0 ] . chomp! else version = "N/A" end @job = Job . new @job . inputurl = @oldjob . inputurl @job . job_description = @oldjob . job_description @job . job_name = @oldjob . job_name @job . version = version @job . email = @oldjob . email @job . type = @oldjob . type begin if ! @oldjob . infile . nil? tempfile = Tempfile . open ( @oldjob . infile_name ) tempfile . write ( @oldjob . infile . read . force_encoding ( 'UTF-8' ) ) @job . infile = File . open ( tempfile ) tempfile . unlink if ! @oldjob . proper_infilename . nil? @job . proper_infilename = @oldjob . proper_infilename else @job . proper_infilename = @oldjob . infile_name end end rescue Rails . logger . error ( "Infile copy failed when resubmitting job #{@oldjob.id}" ) flash [ :alert ] = 'Resubmission failed' redirect_to "/jobs/#{@oldjob.id}" and return end begin if ! @oldjob . parameters . nil? @job . parameters = @oldjob . parameters end if ! @oldjob . vars [ :oscid ] . nil? @job . vars [ :oscid ] = 'N/A' end if ! @oldjob . parameters [ :identifier ] . nil? @job . parameters [ :identifier ] = 'N/A' end rescue Rails . logger . error ( "Parameter copy failed when resubmitting job #{@oldjob.id}" ) flash [ :alert ] = 'Resubmission failed' redirect_to "/jobs/#{@oldjob.id}" and return end @job . status = 'held' if @job . save! flash [ :notice ] = 'Please check your job and submit' redirect_to :controller => 'jobs' , :action => 'edit' , :id => @job . id and return else Rails . logger . error ( "Save failed for resubmission of job #{@oldjob.id}" ) end end
users should be able to resubmit a job.
users should be able to resubmit a job .
# here, the user must be found and their account determined. Then, before going any # further, expiry then credits can be checked. Re-direct to job listing with appropriate # flash, or give a plain text error message otherwise # expiry # version &c. # these bits are done separately in case of any funny business # from the GridFS # N.B. from Mon Sep  5  2011 a code update somewhere caused this to start mucking about, # so I have written to a tempfile to get around the problems caused by trying to copy # a file within gridfs # a new parameter must be created here, and the old one iterated over # the new job should now exist, so there should be no reason why it could not be saved # here...