From 9c767ea7ca2a91e84de44fe53dbd488183097094 Mon Sep 17 00:00:00 2001 From: nicolassatragno Date: Sat, 15 Dec 2012 23:46:44 -0300 Subject: [PATCH 1/2] Added database:import_oldest_rpms[n] task --- app/models/rpm_importer.rb | 10 ++++++++++ lib/tasks/database.rake | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/app/models/rpm_importer.rb b/app/models/rpm_importer.rb index f24c72a..448a3b7 100644 --- a/app/models/rpm_importer.rb +++ b/app/models/rpm_importer.rb @@ -5,6 +5,16 @@ class RpmImporter BASE_URI = 'http://pkgs.fedoraproject.org/cgit/' PKG_LIST_URI = BASE_URI + '?q=rubygem-' + def self.import_oldest(number) + total = 0 + rpms = FedoraRpm.order("updated_at ASC").limit(number) + rpms.each { |f| + puts "Updating #{f.name} (#{total += 1}/#{rpms.size})..." + f.update_from_source + } + + end + def self.import_all total = 0 rpms = FedoraRpm.find(:all) diff --git a/lib/tasks/database.rake b/lib/tasks/database.rake index 62a30db..ce47825 100644 --- a/lib/tasks/database.rake +++ b/lib/tasks/database.rake @@ -70,5 +70,15 @@ namespace :database do end GemImporter.update_gems(days) end + + desc 'import oldest n rpms' + task :update_oldest_rpms, [:rpms_number] => :environment do |t, args| + args.with_defaults(:rpms_number => 10) + number = args.rpms_number.to_i + unless number.nil? || number.is_a?(Fixnum) + raise ArgumentError, "invalid number of oldest rpms to import" + end + RpmImporter.import_oldest(number) + end end From 25a6f0909e1fe970b8221591114f6809b5637437 Mon Sep 17 00:00:00 2001 From: nicolassatragno Date: Sun, 16 Dec 2012 00:38:14 -0300 Subject: [PATCH 2/2] Removed old update script and made another one new deleted: .openshift/cron/hourly/update_db Deleted script that called the old update script new file: .openshift/cron/hourly/update_rpm_list.sh This script updates the RPM list daily new file: .openshift/cron/minutely/update_oldest_rpm.sh This script updates the oldest RPM minutely modified: app/models/rpm_importer.rb Added an exeption catcher in the new import_oldest(number) method. --- .openshift/cron/hourly/update_db | 3 --- .openshift/cron/hourly/update_rpm_list.sh | 9 +++++++++ .openshift/cron/minutely/update_oldest_rpm.sh | 5 +++++ app/models/rpm_importer.rb | 3 ++- 4 files changed, 16 insertions(+), 4 deletions(-) delete mode 100755 .openshift/cron/hourly/update_db create mode 100755 .openshift/cron/hourly/update_rpm_list.sh create mode 100755 .openshift/cron/minutely/update_oldest_rpm.sh diff --git a/.openshift/cron/hourly/update_db b/.openshift/cron/hourly/update_db deleted file mode 100755 index 7b88c5d..0000000 --- a/.openshift/cron/hourly/update_db +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -nohup $OPENSHIFT_REPO_DIR/script/update_db diff --git a/.openshift/cron/hourly/update_rpm_list.sh b/.openshift/cron/hourly/update_rpm_list.sh new file mode 100755 index 0000000..553466f --- /dev/null +++ b/.openshift/cron/hourly/update_rpm_list.sh @@ -0,0 +1,9 @@ +#!/bin/bash +if [ `date +%H` == "02" ] +then + export RAILS_ENV="production" + cd $OPENSHIFT_REPO_DIR + echo "Starting RPM list update..." > $OPENSHIFT_DATA_DIR/last_update.log + rake "database:import_rpms[refresh_list]" >> $OPENSHIFT_DATA_DIR/last_update.log 2>&1 + echo "RPM list update done!" >> $OPENSHIFT_DATA_DIR/last_update.log +fi diff --git a/.openshift/cron/minutely/update_oldest_rpm.sh b/.openshift/cron/minutely/update_oldest_rpm.sh new file mode 100755 index 0000000..8699078 --- /dev/null +++ b/.openshift/cron/minutely/update_oldest_rpm.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +cd $OPENSHIFT_REPO_DIR +export RAILS_ENV="production" +rake "database:update_oldest_rpms[1]" >> $OPENSHIFT_DATA_DIR/last_update.log 2>&1 diff --git a/app/models/rpm_importer.rb b/app/models/rpm_importer.rb index 448a3b7..11837df 100644 --- a/app/models/rpm_importer.rb +++ b/app/models/rpm_importer.rb @@ -12,7 +12,8 @@ def self.import_oldest(number) puts "Updating #{f.name} (#{total += 1}/#{rpms.size})..." f.update_from_source } - + rescue Exception => ex + puts ex.message end def self.import_all