class Cloudinary::Migrator
def initialize(options={})
def initialize(options={}) self.class.init options[:db_file] = "tmp/migration#{$$}.db" if options[:private_database] && !options[:db_file] @dbfile = options[:db_file] || "tmp/migration.db" FileUtils.mkdir_p(File.dirname(@dbfile)) @db = SQLite3::Database.new @dbfile, :results_as_hash=>true @retrieve = options[:retrieve] @complete = options[:complete] @debug = options[:debug] || false @ignore_duplicates = options[:ignore_duplicates] @threads = [options[:threads] || 10, 100].min @extra_options = {:api_key=>options[:api_key], :api_secret=>options[:api_secret]} @delete_after_done = options[:delete_after_done] || options[:private_database] @max_processing = @threads * 10 @in_process = 0 @work = Queue.new @results = Queue.new @mutex = Mutex.new @db.execute " create table if not exists queue ( id integer primary key, internal_id integer, public_id text, url text, metadata text, result string, status text, updated_at integer ) " @db.execute " create index if not exists status_idx on queue ( status ) " @db.execute " create unique index if not exists internal_id_idx on queue ( internal_id ) " @db.execute " create unique index if not exists public_id_idx on queue ( public_id ) " if options[:reset_queue] @db.execute("delete from queue") end end