diff --git a/app/controllers/settings/hostings_controller.rb b/app/controllers/settings/hostings_controller.rb
index 6eea6ecc..06474826 100644
--- a/app/controllers/settings/hostings_controller.rb
+++ b/app/controllers/settings/hostings_controller.rb
@@ -3,7 +3,7 @@ class Settings::HostingsController < ApplicationController
guard_feature unless: -> { self_hosted? }
- before_action :ensure_admin, only: :clear_cache
+ before_action :ensure_admin, only: [ :clear_cache, :clear_syncs ]
def show
synth_provider = Provider::Registry.get_provider(:synth)
@@ -34,6 +34,11 @@ class Settings::HostingsController < ApplicationController
redirect_to settings_hosting_path, notice: t(".cache_cleared")
end
+ def clear_syncs
+ SyncsCacheClearJob.perform_later(Current.family)
+ redirect_to settings_hosting_path, notice: t(".syncs_cleared")
+ end
+
private
def hosting_params
params.require(:setting).permit(:require_invite_for_signup, :require_email_confirmation, :synth_api_key)
diff --git a/app/jobs/syncs_cache_clear_job.rb b/app/jobs/syncs_cache_clear_job.rb
new file mode 100644
index 00000000..698f66b4
--- /dev/null
+++ b/app/jobs/syncs_cache_clear_job.rb
@@ -0,0 +1,12 @@
+class SyncsCacheClearJob < ApplicationJob
+ queue_as :low_priority
+
+ def perform(family)
+ syncs = family.syncs
+ ActiveRecord::Base.transaction do
+ syncs
+ .where(status: [ "pending", "syncing" ])
+ .update_all(status: "failed")
+ end
+ end
+end
diff --git a/app/views/settings/hostings/_danger_zone_settings.html.erb b/app/views/settings/hostings/_danger_zone_settings.html.erb
index 6c96415e..e9dbf819 100644
--- a/app/views/settings/hostings/_danger_zone_settings.html.erb
+++ b/app/views/settings/hostings/_danger_zone_settings.html.erb
@@ -16,5 +16,21 @@
}}
%>
+
+
+
<%= t("settings.hostings.show.clear_syncs") %>
+
<%= t("settings.hostings.show.clear_syncs_warning") %>
+
+ <%=
+ button_to t("settings.hostings.show.clear_syncs"), clear_syncs_settings_hosting_path, method: :delete,
+ class: "w-full md:w-auto bg-orange-500 text-white text-sm font-medium rounded-lg px-4 py-2",
+ data: { turbo_confirm: {
+ title: t("settings.hostings.show.confirm_clear_syncs.title"),
+ body: t("settings.hostings.show.confirm_clear_syncs.body"),
+ accept: t("settings.hostings.show.clear_syncs"),
+ acceptClass: "w-full bg-orange-500 text-white rounded-xl text-center p-[10px] border mb-2"
+ }}
+ %>
+
<% end %>
diff --git a/config/locales/views/settings/hostings/en.yml b/config/locales/views/settings/hostings/en.yml
index 7377c492..877cbb09 100644
--- a/config/locales/views/settings/hostings/en.yml
+++ b/config/locales/views/settings/hostings/en.yml
@@ -21,6 +21,12 @@ en:
confirm_clear_cache:
title: Clear data cache?
body: Are you sure you want to clear the data cache? This will remove all exchange rates, security prices, account balances, and other data. This action cannot be undone.
+ clear_syncs: Clear syncs cache
+ clear_syncs_warning: Clearing the syncs cache will remove all syncs enqueued.
+ confirm_clear_syncs:
+ title: Clear syncs cache?
+ body: Are you sure you want to clear the data cache? This will remove all syncs enqueued.
+
synth_settings:
api_calls_used: "%{used} / %{limit} API calls used (%{percentage})"
description: Input the API key provided by Synth
@@ -33,4 +39,6 @@ en:
success: Settings updated
clear_cache:
cache_cleared: Data cache has been cleared. This may take a few moments to complete.
+ clear_syncs:
+ syncs_cleared: Syncs cache has been cleared. This may take a few moments to complete.
not_authorized: You are not authorized to perform this action
diff --git a/config/routes.rb b/config/routes.rb
index ec9e2cce..e63793f4 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -52,6 +52,7 @@ Rails.application.routes.draw do
resource :preferences, only: :show
resource :hosting, only: %i[show update] do
delete :clear_cache, on: :collection
+ delete :clear_syncs, on: :collection
end
resource :billing, only: :show
resource :security, only: :show