Skip to content

Instantly share code, notes, and snippets.

View fmontes86's full-sized avatar

Felix Montes fmontes86

View GitHub Profile
@fmontes86
fmontes86 / Import.rb
Last active August 29, 2015 14:04
Full advantage threads handle with JRuby - Sidekiq - Sinatra - Smart_csv
# APP 1: Import Class
class Import
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Paperclip
field :starter_at, type: Time
field :finished_at, type: Time
field :total_rows, type: Integer
@fmontes86
fmontes86 / campaign_import.rb
Last active August 29, 2015 13:58
Delayed_job implementaion with smarter_csv and fork creation by chunks
def load_imported_campaign
total_chunks = SmarterCSV.process(file.path, {:chunk_size => 2, :strings_as_keys => true, :remove_unmapped_keys => true, :col_sep => "\t"}) do |chunk|
chunk.each_with_index do |h, i|
forkPID = fork do
p "Start new FORK with PID: #{forkPID} on ROW: #{i}"
# ESTO ES PARA EL USUARIO
# user = User.where(email: row["General-Email"]).first_or_create
# user.update(email: row["General-Email"])
# user.save!