Skip to content
This repository
Browse code

[#6]Generate md5 for upload based on entire zip, rather than just the…

… worker
  • Loading branch information...
commit 548f867042c771259ff67f4bed1efad9ce74c69e 1 parent be34a85
rkononov authored

Showing 1 changed file with 14 additions and 12 deletions. Show diff stats Hide diff stats

  1. +14 12 lib/iron_worker/service.rb
26 lib/iron_worker/service.rb
@@ -45,23 +45,25 @@ def upload(filename, class_name, options={})
45 45 existing_md5 = IO.read(md5_f)
46 46 end
47 47
48   - # Check for code changes.
49   - md5 = Digest::MD5.hexdigest(File.read(filename))
50   - new_code = false
51   - if self.config.force_upload || md5 != existing_md5
52   - IronWorker.logger.info "Uploading #{class_name}, code modified."
53   - File.open(md5_f, 'w') { |f| f.write(md5) }
54   - new_code = true
55   - # todo: delete md5 file if error occurs during upload process
56   - else
57   -# puts "#{class_name}: same code, not uploading"
58   - return
59   - end
60 48
61 49 begin
62 50
63 51 zip_filename = build_merged_file(filename, options[:merge], options[:unmerge], options[:merged_gems], options[:merged_mailers], options[:merged_folders])
64 52
  53 + # Check for code changes.
  54 + zipfile = Zip::ZipFile.open(zip_filename, Zip::ZipFile::CREATE)
  55 + crc = zipfile.entries.collect{|x|x.crc}.inject(:+)
  56 + new_code = false
  57 + if self.config.force_upload || crc.to_s != existing_md5
  58 + IronWorker.logger.info "Uploading #{class_name}, code modified."
  59 + File.open(md5_f, 'w') { |f| f.write(crc) }
  60 + new_code = true
  61 + # todo: delete md5 file if error occurs during upload process
  62 + else
  63 +# puts "#{class_name}: same code, not uploading"
  64 + return
  65 + end
  66 +
65 67 if new_code
66 68 upload_code(name, zip_filename, 'runner.rb', :runtime=>'ruby')
67 69 end

4 comments on commit 548f867

Travis Reeder
Owner

Roman, will this run build_merged_file every time someone queues up a job?

Roman
Collaborator

yes, because anyway we need to scan every file he is trying to queue for changes

Travis Reeder
Owner

Do we still have the is_uploaded? check so it only does this once per ruby process? Otherwise, that would add a huge overhead, imagine running that 10,000 times in a row.

Roman
Collaborator

we're doing this once on first queue

look in base.rb

we're checking

if !uploaded?

and setting after upload

self.class.instance_variable_set(:@uploaded, true)

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