Skip to content
This repository

Sitemap working on resque workers #20

Open
wants to merge 1 commit into from

1 participant

Rodrigo Dominguez
Rodrigo Dominguez
rorra commented

Sitemap working on resque workers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Apr 09, 2012
Rodrigo Dominguez Fixing worker for sitemap 018c2c3
This page is out of date. Refresh to see the latest.
1  Gemfile
@@ -27,7 +27,6 @@ gem "resque-scheduler", :require => 'resque_scheduler'
27 27
 gem 'sitemap_generator'
28 28
 gem "SystemTimer"
29 29
 gem "aasm"
30  
-gem "aws-s3"
31 30
 gem "aws-sdk"
32 31
 gem "acl9"
33 32
 gem "paperclip"
6  Gemfile.lock
@@ -123,10 +123,6 @@ GEM
123 123
       ruby-hmac (~> 0.3)
124 124
     arel (2.2.1)
125 125
     awesome_print (1.0.2)
126  
-    aws-s3 (0.6.2)
127  
-      builder
128  
-      mime-types
129  
-      xml-simple
130 126
     aws-sdk (1.3.4)
131 127
       httparty (~> 0.7)
132 128
       json (~> 1.4)
@@ -362,7 +358,6 @@ GEM
362 358
       rack (>= 1.0.0)
363 359
     will_paginate (3.0.3)
364 360
     wirble (0.1.3)
365  
-    xml-simple (1.1.1)
366 361
     xpath (0.1.4)
367 362
       nokogiri (~> 1.3)
368 363
 
@@ -379,7 +374,6 @@ DEPENDENCIES
379 374
   airbrake
380 375
   amazon-ecs
381 376
   awesome_print
382  
-  aws-s3
383 377
   aws-sdk
384 378
   bitly
385 379
   capistrano
29  app/workers/sitemap_worker.rb
... ...
@@ -1,9 +1,13 @@
1  
-require 'aws/s3'
  1
+require 'aws'
2 2
 
3 3
 class SitemapWorker
  4
+
4 5
   @queue = :sitemaps
5 6
 
6 7
   def self.perform()
  8
+    app_settings_file = "#{Rails.root}/config/application_settings.yml"
  9
+    site_url = ActiveSupport::HashWithIndifferentAccess.new(YAML.load_file(app_settings_file)[Rails.env])['base_site_url']
  10
+    SitemapGenerator::Sitemap.default_host = site_url
7 11
     SitemapGenerator::Sitemap.verbose = false
8 12
     SitemapGenerator::Sitemap.create
9 13
     self.upload_sitemaps_to_s3
@@ -16,22 +20,21 @@ def self.upload_sitemaps_to_s3
16 20
       s3_options = YAML.load_file(File.join(Rails.root, "config", "s3.yml"))[Rails.env].symbolize_keys
17 21
       bucket = s3_options[:bucket]
18 22
       s3_options.delete(:bucket)
19  
-      
  23
+
20 24
       # Establish S3 connection
21  
-      AWS::S3::Base.establish_connection!(s3_options)
22  
-      
  25
+      #AWS::S3::Base.establish_connection!(s3_options)
  26
+      s3 = AWS::S3.new(:access_key_id => s3_options[:access_key_id], :secret_access_key => s3_options[:secret_access_key])
  27
+
  28
+      s3.buckets.create(bucket) unless s3.buckets[bucket.to_sym].exists?
  29
+      s3_bucket = s3.buckets[bucket.to_sym]
  30
+
23 31
       ["sitemap1.xml.gz", "sitemap_index.xml.gz"].each do |file_name|
24 32
         path = "/sitemaps/#{file_name}"
25 33
         file = File.new(File.join(Rails.root, "public", "system", "sitemaps", file_name))
26  
-        begin
27  
-          AWS::S3::S3Object.store(path, file, bucket, :access => :public_read)
28  
-          
29  
-        rescue AWS::S3::NoSuchBucket => e
30  
-          AWS::S3::Bucket.create(bucket)
31  
-          retry
32  
-        rescue AWS::S3::ResponseError => e
33  
-          raise
34  
-        end
  34
+
  35
+        obj = s3_bucket.objects[path]
  36
+        obj.write(file.read, :acl => :public_read)
  37
+
35 38
         puts "Saved #{file_name} to S3"
36 39
       end
37 40
     end
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.