button to enqueue jobs
This commit is contained in:
@@ -31,12 +31,7 @@ class Domain::UserJobEventsController < DomainController
|
||||
|
||||
sig { void }
|
||||
def tracked_objects
|
||||
@kind = T.let(params[:kind], T.nilable(String))
|
||||
raise ActionController::RoutingError, "Not Found" if @kind.blank?
|
||||
unless Domain::UserJobEvent::AddTrackedObject.kinds.include?(@kind)
|
||||
raise ActionController::RoutingError, "Not Found"
|
||||
end
|
||||
|
||||
set_and_validate_kind!
|
||||
@tracked_objects =
|
||||
T.let(
|
||||
T
|
||||
@@ -49,6 +44,34 @@ class Domain::UserJobEventsController < DomainController
|
||||
)
|
||||
end
|
||||
|
||||
sig { void }
|
||||
def enqueue_scan_job
|
||||
set_and_validate_kind!
|
||||
@user = T.must(@user)
|
||||
|
||||
unless @user.is_a?(Domain::User::FaUser)
|
||||
flash[:error] = "This user is not a FurAffinity user"
|
||||
redirect_to tracked_objects_domain_user_job_events_path(
|
||||
@user,
|
||||
kind: @kind,
|
||||
)
|
||||
return
|
||||
end
|
||||
|
||||
case @kind
|
||||
when "favs"
|
||||
flash[:success] = "Enqueued scan job for #{@user.url_name} favs"
|
||||
Domain::Fa::Job::FavsJob.set(queue: "manual").perform_later(
|
||||
user: @user,
|
||||
force_scan: true,
|
||||
)
|
||||
else
|
||||
flash[:error] = "Unimplemented kind: #{@kind}"
|
||||
end
|
||||
|
||||
redirect_to tracked_objects_domain_user_job_events_path(@user, kind: @kind)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
sig { override.returns(DomainController::DomainParamConfig) }
|
||||
@@ -59,4 +82,13 @@ class Domain::UserJobEventsController < DomainController
|
||||
post_group_id_param: :domain_post_group_id,
|
||||
)
|
||||
end
|
||||
|
||||
sig { void }
|
||||
def set_and_validate_kind!
|
||||
@kind = T.let(params[:kind], T.nilable(String))
|
||||
raise ActionController::RoutingError, "Not Found" if @kind.blank?
|
||||
unless Domain::UserJobEvent::AddTrackedObject.kinds.include?(@kind)
|
||||
raise ActionController::RoutingError, "Not Found"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -162,6 +162,14 @@ module Domain::UsersHelper
|
||||
"#{domain_user_path(user)}/job_events/tracked_objects"
|
||||
end
|
||||
|
||||
sig { params(user: Domain::User, kind: String).returns(String) }
|
||||
def enqueue_scan_job_domain_user_job_events_path(user, kind:)
|
||||
unless Domain::UserJobEvent::AddTrackedObject.kinds.include?(kind)
|
||||
Kernel.raise "invalid kind: #{kind}"
|
||||
end
|
||||
"#{domain_user_path(user)}/job_events/enqueue_scan_job/#{kind}"
|
||||
end
|
||||
|
||||
class StatRow < T::ImmutableStruct
|
||||
include T::Struct::ActsAsComparable
|
||||
|
||||
|
||||
@@ -2,20 +2,33 @@
|
||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||
<% end %>
|
||||
<div class="mx-auto mt-4 flex w-full max-w-2xl flex-col gap-4 pb-4">
|
||||
<% if flash[:success] %>
|
||||
<div class="bg-green-50 text-green-700 p-4 rounded-md border border-green-300">
|
||||
<%= flash[:success] %>
|
||||
</div>
|
||||
<% elsif flash[:error] %>
|
||||
<div class="bg-red-50 text-red-700 p-4 rounded-md border border-red-300">
|
||||
<%= flash[:error] %>
|
||||
</div>
|
||||
<% end %>
|
||||
<section class="rounded-md border border-slate-300 bg-slate-50 p-4">
|
||||
<div class="flex items-center justify-between gap-4">
|
||||
<div class="flex min-w-0 items-center gap-2">
|
||||
<%= link_to tracked_objects_domain_user_job_events_kinds_path(@user),
|
||||
<div class="flex items-center justify-between gap-2">
|
||||
<%= link_to tracked_objects_domain_user_job_events_kinds_path(@user),
|
||||
class:
|
||||
"px-4 py-2 text-sm font-medium text-slate-700 bg-white border border-slate-300 rounded-md hover:bg-slate-50" do %>
|
||||
<span class="mr-1">←</span>
|
||||
<span>Back to Scans</span>
|
||||
<% end %>
|
||||
<h1 class="text-lg font-medium">
|
||||
<%= add_tracked_object_kind_for_view(@kind) %> Scans for
|
||||
<%= link_to @user.name, domain_user_path(@user), class: "text-blue-600 hover:underline" %>
|
||||
</h1>
|
||||
</div>
|
||||
<span class="mr-1">←</span>
|
||||
<span>Back to Scans</span>
|
||||
<% end %>
|
||||
<h1 class="text-lg font-medium">
|
||||
<%= add_tracked_object_kind_for_view(@kind) %> Scans for
|
||||
<%= link_to @user.name, domain_user_path(@user), class: "text-blue-600 hover:underline" %>
|
||||
</h1>
|
||||
<%= button_to enqueue_scan_job_domain_user_job_events_path(@user, kind: @kind),
|
||||
method: :post,
|
||||
form_class: "justify-self-end",
|
||||
class: "px-4 py-2 text-sm font-medium text-slate-700 bg-white border border-slate-300 rounded-md hover:bg-slate-50" do %>
|
||||
Enqueue <%= add_tracked_object_kind_for_view(@kind) %> Scan Job
|
||||
<% end %>
|
||||
</div>
|
||||
</section>
|
||||
<%= render 'tracked_objects_chart' %>
|
||||
@@ -33,8 +46,8 @@
|
||||
<div title="<%= scan.log_entry.requested_at.strftime("%Y-%m-%d %H:%M:%S") %>">
|
||||
<%= time_ago_in_words(scan.log_entry.requested_at) %> ago
|
||||
</div>
|
||||
<div class="text-right font-mono"><%= scan.num_added %></div>
|
||||
<div class="text-right font-mono"><%= scan.num_total %></div>
|
||||
<div class="text-right font-mono"><%= number_with_delimiter(scan.num_added) %></div>
|
||||
<div class="text-right font-mono"><%= number_with_delimiter(scan.num_total) %></div>
|
||||
<div>
|
||||
<% if scan.duration_since_last_scan.present? %>
|
||||
<div class="text-right">
|
||||
@@ -44,7 +57,7 @@
|
||||
<span class="text-slate-400">N/A</span>
|
||||
<% end %>
|
||||
</div>
|
||||
<div>
|
||||
<div class="text-right">
|
||||
<% if scan.log_entry %>
|
||||
<%= link_to scan.log_entry.id, log_entry_path(scan.log_entry), class: "text-blue-600 hover:underline" %>
|
||||
<% end %>
|
||||
|
||||
@@ -43,6 +43,11 @@ Rails.application.routes.draw do
|
||||
on: :collection,
|
||||
action: :tracked_objects,
|
||||
as: :tracked_objects
|
||||
|
||||
post "enqueue_scan_job/:kind",
|
||||
on: :collection,
|
||||
action: :enqueue_scan_job,
|
||||
as: :enqueue_scan_job
|
||||
end
|
||||
|
||||
resources :posts, only: [], controller: "domain/posts", path: "" do
|
||||
|
||||
@@ -171,7 +171,7 @@ describe Domain::Inkbunny::Job::UpdatePostsJob do
|
||||
expect(post_3104202.description).to match(/Vulk grabs Lyra/)
|
||||
expect(post_3104202.writing).to eq("")
|
||||
expect(post_3104202.num_views).to eq(202)
|
||||
expect(post_3104202.deep_updated_at).to be_within(1.second).of(Time.now)
|
||||
expect(post_3104202.deep_updated_at).to be_within(3.seconds).of(Time.now)
|
||||
|
||||
post_3104200.reload
|
||||
expect(post_3104200.description).to match(/Some requests from my Patreon/)
|
||||
@@ -186,7 +186,7 @@ describe Domain::Inkbunny::Job::UpdatePostsJob do
|
||||
),
|
||||
)
|
||||
expect(post_3104200.deep_update_log_entry).to eq(log_entries[0])
|
||||
expect(post_3104200.deep_updated_at).to be_within(1.second).of(Time.now)
|
||||
expect(post_3104200.deep_updated_at).to be_within(3.seconds).of(Time.now)
|
||||
|
||||
# Check user details were updated
|
||||
user_seff.reload
|
||||
@@ -377,7 +377,7 @@ describe Domain::Inkbunny::Job::UpdatePostsJob do
|
||||
|
||||
post_1047334.reload
|
||||
expect(post_1047334.files.count).to eq(2)
|
||||
expect(post_1047334.last_file_updated_at).to be_within(1.second).of(
|
||||
expect(post_1047334.last_file_updated_at).to be_within(3.seconds).of(
|
||||
Time.parse("2023-09-14 19:07:45.735562+02"),
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user