mirror of
https://github.com/ubicloud/ubicloud.git
synced 2025-11-29 17:10:26 +08:00
Fixes and improvements to previous commit: * Add delete_all_cache_entries to LOGGED_ACTIONS. * Change optional initiated_at assemble argument from positional to keyword. * Don't use repository_id as the id of the created strand. * Remove unnecessary start label in prog. * Only delete cache entries before initiated at. * Add next_entry method to prog for easier mocking. * Update flash notices used in route. * Only mock when necessary in the specs. * Simplify web and cli specs. * Only use a transaction in the route if there are cache entries.
30 lines
718 B
Ruby
30 lines
718 B
Ruby
# frozen_string_literal: true
|
|
|
|
class Prog::Github::DeleteCacheEntries < Prog::Base
|
|
subject_is :github_repository
|
|
|
|
def self.assemble(repository_id, initiated_at: Time.now)
|
|
Strand.create(
|
|
prog: "Github::DeleteCacheEntries",
|
|
label: "delete_entries",
|
|
stack: [{
|
|
"subject_id" => repository_id,
|
|
"initiated_at" => initiated_at.to_s
|
|
}]
|
|
)
|
|
end
|
|
|
|
label def delete_entries
|
|
if (cache_entry = next_entry)
|
|
cache_entry.destroy
|
|
nap 0
|
|
end
|
|
|
|
pop "all cache entries deleted"
|
|
end
|
|
|
|
def next_entry
|
|
initiated_at = Time.parse(frame["initiated_at"])
|
|
github_repository.cache_entries_dataset.order(:created_at).first { created_at < initiated_at }
|
|
end
|
|
end
|