2012-05-11 18:44:19 +01:00
|
|
|
|
|
|
|
namespace :buildlist do
|
2012-08-24 16:19:26 +01:00
|
|
|
|
2012-05-11 18:44:19 +01:00
|
|
|
namespace :clear do
|
2012-08-06 22:07:54 +01:00
|
|
|
desc 'Remove outdated BuildLists and MassBuilds'
|
2014-01-21 04:51:49 +00:00
|
|
|
task outdated: :environment do
|
2013-03-15 14:40:39 +00:00
|
|
|
say "[#{Time.zone.now}] Removing outdated BuildLists"
|
|
|
|
say "[#{Time.zone.now}] There are #{BuildList.outdated.count} outdated BuildLists"
|
|
|
|
counter = 0
|
2014-01-21 04:51:49 +00:00
|
|
|
BuildList.outdated.order(:id).find_in_batches(batch_size: 100) do |build_lists|
|
2013-03-15 14:40:39 +00:00
|
|
|
build_lists.each do |bl|
|
|
|
|
bl.destroy && (counter += 1) if bl.id != bl.last_published.first.try(:id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
say "[#{Time.zone.now}] #{counter} outdated BuildLists have been removed"
|
2012-05-11 18:44:19 +01:00
|
|
|
|
2013-03-15 14:40:39 +00:00
|
|
|
say "[#{Time.zone.now}] Removing outdated MassBuilds"
|
|
|
|
say "[#{Time.zone.now}] There are #{MassBuild.outdated.count} outdated MassBuilds"
|
|
|
|
counter = 0
|
|
|
|
MassBuild.outdated.each do |mb|
|
|
|
|
mb.destroy && (counter += 1) if mb.build_lists.count == 0
|
|
|
|
end
|
|
|
|
say "[#{Time.zone.now}] #{counter} outdated MassBuilds have been removed"
|
2012-08-06 22:07:54 +01:00
|
|
|
|
2013-03-15 14:40:39 +00:00
|
|
|
say "[#{Time.zone.now}] Outdated BuildLists and MassBuilds was successfully removed"
|
2012-05-11 18:44:19 +01:00
|
|
|
end
|
2014-01-31 17:12:24 +00:00
|
|
|
|
|
|
|
desc 'Remove outdated BuildLists with status BUILD_CANCELING'
|
|
|
|
task outdated_canceling: :environment do
|
|
|
|
say "[#{Time.zone.now}] Removing outdated BuildLists"
|
|
|
|
|
|
|
|
scope = BuildList.for_status(BuildList::BUILD_CANCELING).
|
|
|
|
for_notified_date_period(nil, Time.zone.now - 3.hours)
|
|
|
|
|
|
|
|
say "[#{Time.zone.now}] There are #{scope.count} outdated BuildLists"
|
|
|
|
|
|
|
|
counter = 0
|
|
|
|
scope.find_each do |bl|
|
|
|
|
bl.destroy && (counter += 1)
|
|
|
|
end
|
|
|
|
|
|
|
|
say "[#{Time.zone.now}] #{counter} outdated BuildLists have been removed"
|
|
|
|
say "[#{Time.zone.now}] Outdated BuildLists were successfully removed"
|
|
|
|
end
|
|
|
|
|
2012-05-11 18:44:19 +01:00
|
|
|
end
|
2012-08-24 16:19:26 +01:00
|
|
|
|
|
|
|
namespace :packages do
|
|
|
|
# TODO Maybe do it in migration, because it's just a single query?
|
|
|
|
desc 'Actualize packages for all platforms'
|
2014-01-21 04:51:49 +00:00
|
|
|
task actualize: :environment do
|
2012-08-24 16:19:26 +01:00
|
|
|
|
|
|
|
say "Updating packages"
|
|
|
|
packages = BuildList::Package.joins( %q{
|
|
|
|
JOIN (
|
|
|
|
SELECT
|
|
|
|
name AS j_pn,
|
|
|
|
package_type AS j_pt,
|
|
|
|
platform_id AS j_plid,
|
|
|
|
MAX(created_at) AS j_ca
|
|
|
|
FROM
|
|
|
|
build_list_packages
|
|
|
|
GROUP BY
|
|
|
|
j_pn, j_pt, j_plid
|
|
|
|
) AS lastmaints
|
|
|
|
ON
|
|
|
|
j_pn = name
|
|
|
|
AND j_pt = package_type
|
|
|
|
AND j_plid = platform_id
|
|
|
|
AND j_ca = created_at
|
2014-01-21 04:51:49 +00:00
|
|
|
} ).update_all(actual: true)
|
2012-08-24 16:19:26 +01:00
|
|
|
say "'Actual' setted to #{packages} packages"
|
|
|
|
end
|
|
|
|
end
|
2012-05-11 18:44:19 +01:00
|
|
|
end
|