<%= f.label "contact_via_connect", "Allow Users to Message Me Via In-App Chat (DEV Connect)" %>
<%= f.check_box "contact_via_connect" %>
diff --git a/db/migrate/20190822162434_add_expires_at_to_classified_listings.rb b/db/migrate/20190822162434_add_expires_at_to_classified_listings.rb
new file mode 100644
index 000000000..5c16ed3cd
--- /dev/null
+++ b/db/migrate/20190822162434_add_expires_at_to_classified_listings.rb
@@ -0,0 +1,5 @@
+class AddExpiresAtToClassifiedListings < ActiveRecord::Migration[5.2]
+ def change
+ add_column :classified_listings, :expires_at, :datetime
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 6c7ffafb1..b68adff37 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -12,7 +12,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 2019_08_18_191954) do
+ActiveRecord::Schema.define(version: 2019_08_22_162434) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -254,6 +254,7 @@ ActiveRecord::Schema.define(version: 2019_08_18_191954) do
t.string "category"
t.boolean "contact_via_connect", default: false
t.datetime "created_at", null: false
+ t.datetime "expires_at"
t.datetime "last_buffered"
t.string "location"
t.bigint "organization_id"
diff --git a/lib/tasks/fetch.rake b/lib/tasks/fetch.rake
index 28eba3f2d..5c779dd58 100644
--- a/lib/tasks/fetch.rake
+++ b/lib/tasks/fetch.rake
@@ -34,6 +34,13 @@ task expire_old_listings: :environment do
end
end
+task expire_old_listings: :environment do
+ ClassifiedListing.where("expires_at = ?", Time.zone.today).each do |listing|
+ listing.update(published: false)
+ listing.remove_from_index!
+ end
+end
+
task clear_memory_if_too_high: :environment do
Rails.cache.clear if Rails.cache.stats.flatten[1]["bytes"].to_i > 9_650_000_000
end