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
All checks were successful
Build and Publish Docker Container / build (push) Successful in 5m49s
This commit is contained in:
parent
52d11a41ab
commit
351694df12
@ -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.
|
||||
#
|
||||
|
||||
@ -40,6 +40,6 @@ class AttendanceTrackerController < ApplicationController
|
||||
end
|
||||
|
||||
def refresh_toggl
|
||||
ScrapeTogglJob.perform_later
|
||||
ScrapeTogglJob.perform_later(Course.active.ids)
|
||||
end
|
||||
end
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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? %>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user