forked from aces/cbrain
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new BACs: CleanCache, UnregisterFile
- Loading branch information
Showing
5 changed files
with
196 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
|
||
# | ||
# CBRAIN Project | ||
# | ||
# Copyright (C) 2008-2024 | ||
# The Royal Institution for the Advancement of Learning | ||
# McGill University | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
|
||
# Clean cached userfiles | ||
class BackgroundActivity::CleanCache < BackgroundActivity | ||
|
||
Revision_info=CbrainFileRevision[__FILE__] #:nodoc: | ||
|
||
validates_dynamic_bac_presence_of_option :days_older | ||
|
||
def pretty_name | ||
"Clean cache" | ||
end | ||
|
||
def process(item) | ||
userfile = Userfile.find(item) | ||
name = userfile.name | ||
return [ false, "File #{name} is under transfer" ] if | ||
userfile.local_sync_status&.status.to_s =~ /^To/ | ||
userfile.cache_erase | ||
[ true, userfile.id ] | ||
end | ||
|
||
def prepare_dynamic_items | ||
days_older = self.options[:days_older] || 30 | ||
with_user_ids = self.options[:with_user_ids] | ||
without_user_ids = self.options[:without_user_ids] | ||
with_types = self.options[:with_types] | ||
without_types = self.options[:without_types] | ||
|
||
# Base scopes: files cached locally and having been access longer that days_older | ||
scope = Userfile.all.joins(:sync_status) | ||
.where('sync_status.remote_resource_id' => self.remote_resource_id) | ||
.where('sync_status.accessed_at < ?', days_older.to_i.days.ago) | ||
|
||
# Add optional filters | ||
scope = scope.where( 'userfiles.user_id' => with_user_ids) if with_user_ids.present? | ||
scope = scope.where.not('userfiles.user_id' => without_user_ids) if without_user_ids.present? | ||
scope = scope.where( 'userfiles.type' => with_types) if with_types.present? | ||
scope = scope.where.not('userfiles.type' => without_types) if without_types.present? | ||
|
||
# The IDs of these files are what we need to work on | ||
self.items = scope.pluck('userfiles.id') | ||
end | ||
|
||
end | ||
|
60 changes: 60 additions & 0 deletions
60
BrainPortal/app/models/background_activity/unregister_file.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
|
||
# | ||
# CBRAIN Project | ||
# | ||
# Copyright (C) 2008-2024 | ||
# The Royal Institution for the Advancement of Learning | ||
# McGill University | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
|
||
# Unregister files on a browsable DP | ||
class BackgroundActivity::UnregisterFile < BackgroundActivity | ||
|
||
Revision_info=CbrainFileRevision[__FILE__] #:nodoc: | ||
|
||
validates_dynamic_bac_presence_of_option :userfile_custom_filter_id | ||
|
||
def pretty_name | ||
"Unregister files" | ||
end | ||
|
||
# Helper for scheduling a copy of files immediately. | ||
def self.setup!(user_id, userfile_ids, remote_resource_id=nil) | ||
ba = self.local_new(user_id, userfile_ids, remote_resource_id) | ||
ba.save! | ||
ba | ||
end | ||
|
||
def process(item) | ||
userfile = Userfile.find(item) | ||
name = userfile.name | ||
return [ false, "File #{name} is under transfer" ] if | ||
userfile.sync_status.to_a.any? { |ss| ss.status =~ /^To/ } | ||
return [ false, "File #{name} is not on a browsable DataProvider" ] if | ||
! userfile.data_provider.is_browsable? | ||
userfile.keep_dp_content_on_destroy = true | ||
ok = userfile.destroy # only remove entries from DB, does not affect file content | ||
[ ok, "File #{name} unregistered" ] | ||
end | ||
|
||
# Currently, there is no user interface to schedule | ||
# this sort of operation. | ||
def prepare_dynamic_items | ||
populate_items_from_userfile_custom_filter | ||
end | ||
|
||
end | ||
|
This file contains 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
This file contains 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