Allow for scraping toggl entries for specific courses only, change default to be active courses and add a new action to allow manual re-scraping in the case of errors.
All checks were successful
Build and Publish Docker Container / build (push) Successful in 5m49s

This commit is contained in:
Joshua Coles 2024-02-07 10:08:01 +00:00
parent 52d11a41ab
commit 351694df12
5 changed files with 21 additions and 3 deletions

View File

@ -10,6 +10,11 @@ module Admin
redirect_to admin_course_url(requested_resource), notice: "Filled in default live video URL"
end
def redo_toggl_entries
requested_resource.redo_toggl_entries!
redirect_to admin_course_url(requested_resource), notice: "Redid Toggl entries"
end
# Overwrite any of the RESTful controller actions to implement custom behavior
# For example, you may want to send an email after a foo is updated.
#

View File

@ -40,6 +40,6 @@ class AttendanceTrackerController < ApplicationController
end
def refresh_toggl
ScrapeTogglJob.perform_later
ScrapeTogglJob.perform_later(Course.active.ids)
end
end

View File

@ -1,8 +1,8 @@
class ScrapeTogglJob < ApplicationJob
queue_as :default
def perform(*args)
courses = Course.all
def perform(course_ids)
courses = Course.where(id: course_ids)
courses.each do |course|
self.scrape_course(course)

View File

@ -89,4 +89,11 @@ class Course < ApplicationRecord
raise "No default live video URL set" if self.default_live_video_url.nil?
lectures.where(live_video_url: nil).update_all(live_video_url: self.default_live_video_url)
end
# Sometimes our toggl entries get mismatched or otherwise out of sync. This method will delete all tracked time entries
# for this course and then re-import them from Toggl.
def redo_toggl_entries!
TrackedTimeEntry.where(lecture: lectures).destroy_all
ScrapeTogglJob.perform_later([self.id])
end
end

View File

@ -9,3 +9,9 @@
[namespace, page.resource, :fill_in_default_live_video_url],
class: "button",
) if accessible_action?(page.resource, :fill_in_default_live_video_url) && page.resource.default_live_video_url.present? %>
<%= link_to(
"Redo Toggl entries",
[namespace, page.resource, :redo_toggl_entries],
class: "button",
) if accessible_action?(page.resource, :redo_toggl_entries) && page.resource.default_live_video_url.present? %>