Method: CodeRunner#update

Defined in:
lib/coderunner/instance_methods.rb

#update(write_status_dots = true, use_large_cache = @use_large_cache, use_large_cache_but_recheck_incomplete = @use_large_cache_but_recheck_incomplete) ⇒ Object

Update the information about all the runs stored in the variable @run_list. By default, this is done by calling CodeRunner#traverse_directories. If, on the other hand, @use_large_cache is set to true, this is done by reading the temporary cache maintained in “.CODE_RUNNER_TEMP_RUN_LIST_CACHE” in the root folder. This is much quicker. If in addition @use_large_cache_but_recheck_incomplete is set to true, all runs whose status is not either :Complete or :Failed will be rechecked.



828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
# File 'lib/coderunner/instance_methods.rb', line 828

def update(write_status_dots=true, use_large_cache=@use_large_cache, use_large_cache_but_recheck_incomplete=@use_large_cache_but_recheck_incomplete)
	@use_large_cache = use_large_cache
	logf(:update)
	@write_status_dots = write_status_dots

	@run_list={}
	@ids=[]
	@component_run_list = {}
	@component_ids = []
	@run_store =[]
# 		@multiple_processes_directories = []
	set_max_id 0
	@run_class.update_status(self)
	if @use_large_cache and not @recalc_all and not @reprocess_all
		log("using large cache")
		begin
			begin
				eputs 'Loading large cache...' if @write_status_dots
				Dir.chdir(@root_folder) do 
					@run_list = Marshal.load(File.read(".CODE_RUNNER_TEMP_RUN_LIST_CACHE"))
				end
				@run_list.values.each{|run| run.runner = self}
			rescue ArgumentError => err
				eputs err
				raise err unless err.message =~ /undefined class/
				#NB all code_names have to contain only lowercase letters:
# 					modlet, code = err.message.scan(/CodeRunner\:\:([A-Z][\w+])?([A-Z]\w+)Run/)[0]
				code, modlet = err.message.scan(/CodeRunner\:\:([A-Z][a-z0-9_]+)(?:::([A-Z]\w+))?/)[0]
# 					ep code.downcase, modlet
				modlet.downcase! if modlet
				setup_run_class(code.downcase, modlet: modlet)
				retry
			end
# 				ep @run_list
			@ids = @run_list.keys
				@run_list.each{|id, run| run.runner = self }
			#eputs "Setting max id..."
			set_max_id(@ids.max || 0)
			#eputs "max_id = #@max_id"
# 				puts @max_id; gets
# 				@use_large_cache = false
			@ids.sort!
			redone_count = 0
			
			
# 					puts "hello"
# 				ep @use_large_cache_but_recheck_incomplete; exit
			recheck_incomplete_runs if use_large_cache_but_recheck_incomplete
# 				sort_runs
			eprint "Updating runs..." if @write_status_dots
# 				get_all_root_folder_contents
# 				puts @run_list.values[0].directory, File.expand_path(@root_folder).esc_regex
			fix_directories = (run_list.size > 0 and not @run_list.values[0].directory =~ File.expand_path(@root_folder).esc_regex)
# 				eputs 'fdirectories', fix_directories
# 				exit
			eputs "Fixing Directories..." if fix_directories
			@run_list.each do |id, run|
				eprint '.' if @write_status_dots
				run.directory = File.join(@root_folder, run.relative_directory) if fix_directories
# 					run.directory = "#@root_folder/#{run.relative_directory}"
# 					unless @root_folder_contents.include? run.directory# File.directory? run.directory and run.directory =~ File.expand_path(@root_folder).esc_regex
# 						if @root_folder_contents.include?(rel = File.join(@root_folder, run.relative_directory))
# 							run.directory = rel
# 						else
# 							raise CRFatal.new("Directory #{run.directory} not found")
# 						end
# 					end
# 					eputs @use_component
				#run.generate_component_runs #if @use_component.to_s =~ /component/i
				run.component_runs.each{|r| add_component_run(r)} if run.component_runs
			end
			eputs if @write_status_dots
			save_large_cache if fix_directories
# 				puts redone_count
			return self
		rescue Errno::ENOENT, ArgumentError, TypeError => err
			if err.class == ArgumentError and not err.message =~ /marshal data too short/ or err.class == TypeError and not err.message =~ /incompatible marshal file format/
				eputs err
				eputs err.backtrace
				raise CRFatal.new
			end
			eputs err, "Rereading run data"
# 				@use_large_cache = false
		end
	end

	log("not using large cache")
	@run_list={}
	@ids=[]
	@component_run_list = {}
	@component_ids = []
	@run_store =[]
# 		@multiple_processes_directories = []
	set_max_id 0

	log("traversing directories")
	eprint 'Analysing runs..' if @write_status_dots
	#interrupted = false; 
	#old_trap2 = trap(2){}
	#trap(2){eputs "Interrupt acknowledged... reloading saved cache. Interrupt again to override (may cause file corruption)."; trap(2, old_trap2); update(true, true, false); Process.kill(2,0)}
	Dir.chdir(@root_folder){traverse_directories}
	@max_id ||= 0
	eputs
# 		puts 'before request', @ids, @requests;
	respond_to_requests
# 		@n_checks += 1
# 		exit if ($nruns > 0 && @n_checks > $nruns) 
	sort_runs
	@recalc_all = false
# 		pp @run_list
	save_large_cache
	#@run_list.each{|id, run| run.generate_component_runs}
	#trap(2, old_trap2)
	#Process.kill(2, 0) if interrupted
	return self
end