Last active
January 4, 2016 03:59
-
-
Save laser/8565179 to your computer and use it in GitHub Desktop.
blar.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Prunable | |
def from_assets(assets) | |
assets.select &method(:is_prunable?) | |
end | |
def is_prunable?(asset) | |
asset.created_at < Date.today - 30 | |
end | |
module_function from_assets, is_prunable? | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# a Resque job that deletes old images from an S3 bucket | |
class S3Pruner < JobProcessor | |
def process_job | |
Image.all.select do |image| | |
image.created_at < Date.today - 30 | |
end.each do |image| | |
S3Object.delete image.s3_object_name, image.s3_bucket_name | |
image.destroy | |
end | |
end | |
end | |
class SoundCloudPruner < JobProcessor | |
def process_job | |
Audio.all.select do |audio| | |
audio.created_at < Date.today - 30 | |
end.each do |audio| | |
MyApp::SoundCloud.client.delete audio.uri | |
audio.destroy | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# a Resque job that deletes old images from an S3 bucket | |
class S3Pruner < JobProcessor | |
def process_job | |
Prunable.from_assets(Image.all).each do |image| | |
S3Object.delete image.s3_object_name, image.s3_bucket_name | |
image.destroy | |
end | |
end | |
end | |
class SoundCloudPruner < JobProcessor | |
def process_job | |
Prunable.from_assets(Audio.all).each do |audio| | |
MyApp::SoundCloud.client.delete audio.uri | |
audio.destroy | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment