Sha256: 774a4f7782b8766cb5b3eed214038618557da4e2d76e91e66324dc295a6143b0

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

namespace :beso do

  desc "Run Beso jobs and upload to S3"
  task :run => :environment do

    raise 'Beso has no jobs to run. Please define some in the beso initializer.' if Beso.jobs.empty?

    puts '==> Connecting...'

    Beso.connect do |bucket|

      puts '==> Connected!'

      prefix = ENV[ 'BESO_PREFIX' ] || 'beso'
      config = YAML.load( bucket.read 'beso.yml' ) || { }

      puts '==> Config:'
      puts config.inspect

      Beso.jobs.each do |job|

        config[ job.event ] ||= job.first_timestamp

        puts "==> Processing job: #{job.event.inspect} since #{config[ job.event ]}"

        csv = job.to_csv :since => config[ job.event ]

        if csv
          filename = "#{prefix}-#{job.event}-#{config[ job.event ].to_i}.csv"

          bucket.write filename, csv

          puts " ==> #{filename} saved to S3"

          config[ job.event ] = job.last_timestamp

          puts " ==> New timestamp is #{config[ job.event ]}"
        else
          puts " ==> No records found since #{config[ job.event ]}. Skipping..."
        end
      end

      bucket.write 'beso.yml', config.to_yaml

      puts '==> Config saved. Donezo.'
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
beso-0.1.0 lib/tasks/beso.rake