Skip to content
Browse files

add --clean/-C option to remove old syncs records

  • Loading branch information...
1 parent 0883b9b commit f1f0cce3312624cd75abf87c485dc25333188397 @DerGuteMoritz DerGuteMoritz committed Dec 6, 2010
Showing with 14 additions and 0 deletions.
  1. +4 −0 bin/salesforce-sync
  2. +5 −0 lib/salesforce_sync/database.rb
  3. +5 −0 lib/salesforce_sync/synchronization.rb
View
4 bin/salesforce-sync
@@ -37,6 +37,10 @@ OptionParser.new do |opts|
opts.on('-i', '--interactive', 'Drop to interactive shell (irb)') do
options[:interactive] = true
end
+
+ opts.on('-C', '--clean [DAYS]') do |days|
+ options[:clean] = days && days.to_i
+ end
opts.on('-h', '--help', 'Display this help') do
puts opts
View
5 lib/salesforce_sync/database.rb
@@ -68,6 +68,11 @@ def insert_sync_timestamp(object, timestamp)
[syncs_table, db.quote(object), db.quote(timestamp)])
end
+ def clean_syncs_table(days)
+ db.delete("DELETE FROM %s WHERE created_at < statement_timestamp() - interval '%i days'" %
+ [syncs_table, db.quote(days)])
+ end
+
def quote_table_name(name)
db.quote_table_name(name)
end
View
5 lib/salesforce_sync/synchronization.rb
@@ -9,6 +9,11 @@ def self.run(options, salesforce, database)
logger.info 'another process is already running. exiting.'
exit 2
end
+
+ if options[:clean]
+ logger.info 'deleting _salesforce_syncs entries older than %i days' % options[:clean]
+ database.clean_syncs_table(options[:clean])
+ end
logger.info 'starting schema synchronization'
start = salesforce.current_time

0 comments on commit f1f0cce

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