Compare commits

..

No commits in common. "main" and "feature/adopt-good-job" have entirely different histories.

13 changed files with 69 additions and 45 deletions

View File

@ -75,8 +75,8 @@ gem "tailwindcss-rails", "~> 2.0"
gem "font-awesome-sass"
gem "httparty"
# gem "sidekiq"
# gem 'sidekiq-scheduler'
gem "sidekiq"
gem 'sidekiq-scheduler'
gem "icalendar"
gem "administrate"

View File

@ -240,12 +240,16 @@ GEM
rdoc (6.5.0)
psych (>= 4.0.0)
redis (4.8.1)
redis-client (0.17.0)
connection_pool
regexp_parser (2.8.1)
reline (0.3.8)
io-console (~> 0.5)
rexml (3.2.6)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
rufus-scheduler (3.9.1)
fugit (~> 1.1, >= 1.1.6)
sassc (2.4.0)
ffi (~> 1.9)
sassc-rails (2.1.2)
@ -259,6 +263,15 @@ GEM
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
sidekiq (7.1.5)
concurrent-ruby (< 2)
connection_pool (>= 2.3.0)
rack (>= 2.2.4)
redis-client (>= 0.14.0)
sidekiq-scheduler (5.0.3)
rufus-scheduler (~> 3.2)
sidekiq (>= 6, < 8)
tilt (>= 1.4.0)
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
@ -323,6 +336,8 @@ DEPENDENCIES
rails (= 7.1.0.rc2)
redis (~> 4.0)
selenium-webdriver
sidekiq
sidekiq-scheduler
sprockets-rails
stimulus-rails
tailwindcss-rails (~> 2.0)

View File

@ -1,6 +1,5 @@
# Lecture Attendance Management System
## Alterations
### Continuum Mechanics

View File

@ -24,12 +24,9 @@ class AttendanceTrackerController < ApplicationController
current_time_entry = Toggl.current_time_entry
return nil if current_time_entry.nil?
# Match both 'Lecture 1' and 'Lecture 1: Prep', etc
lecture_title = current_time_entry['description'].split(':')[0]
lecture = Lecture
.joins(:course)
.find_by(title: lecture_title, course: { toggl_project: current_time_entry['project_id'] })
.find_by(title: current_time_entry['description'], course: { toggl_project: current_time_entry['project_id'] })
return lecture if lecture.present?

View File

@ -13,16 +13,9 @@ class LectureController < ApplicationController
def start
lecture = Lecture.find(params[:id])
catch_up = params[:catch_up].present?
description = if catch_up
"#{lecture.title}: Catch-up"
else
lecture.title
end
Toggl::start_time_entry(
description:,
description: lecture.title,
project_id: lecture.course.toggl_project,
)

View File

@ -80,7 +80,6 @@ class ScrapeTogglJob < ApplicationJob
preparation_regex = /^(.+): ?(?:Prep|Preparation)?$/
review_regex = /^(.+): ?(?:Review|Recap)/
catchup_regex = /^(.+): ?(?:Catch-up|Catch up|Catch Up)/
if (lecture_title_match = entry_title.match(preparation_regex)) and (lecture = lectures.find_by(title: lecture_title_match[1]))
lecture.tracked_time_entries.create!(
@ -97,14 +96,6 @@ class ScrapeTogglJob < ApplicationJob
associated_toggl_entry_id: entry['time_entries'][0]['id'],
)
# broadcast_update_to lecture, :lectures
elsif (lecture_title_match = entry_title.match(catchup_regex)) and (lecture = lectures.find_by(title: lecture_title_match[1]))
lecture.tracked_time_entries.create!(
kind: :catchup,
toggl_data: entry,
associated_toggl_entry_id: entry['time_entries'][0]['id'],
)
# broadcast_update_to lecture, :lectures
end
end

View File

@ -93,7 +93,7 @@ class Course < ApplicationRecord
# 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(subject: lectures).destroy_all
TrackedTimeEntry.where(lecture: lectures).destroy_all
ScrapeTogglJob.perform_later([self.id])
end
end

View File

@ -14,4 +14,4 @@
"Redo Toggl entries",
[namespace, page.resource, :redo_toggl_entries],
class: "button",
) if accessible_action?(page.resource, :redo_toggl_entries) %>
) if accessible_action?(page.resource, :redo_toggl_entries) && page.resource.default_live_video_url.present? %>

View File

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html>
<head>
<title>LectureAttendanceManager</title>
<meta name="viewport" content="width=device-width,initial-scale=1">

View File

@ -7,25 +7,21 @@
<% elsif joinable_time.future? %>
<%= button_to "Prepare",
lecture_start_preparation_path(id: lecture.id),
class: 'action-button' %>
class: 'action-button'
%>
<% elsif joinable_time.past? && !lecture.attended? %>
<% if lecture.end_time.future? %>
<% start_label = if lecture.is_live?
"Join"
else
"Start"
end %>
<%= button_to start_label,
lectures_start_path(id: lecture.id),
class: 'action-button' %>
<% else %>
<%= button_to 'Catch Up',
lectures_start_path(id: lecture.id, catch_up: true),
class: 'action-button' %>
<% end %>
<% start_label = if lecture.is_live? then
"Join"
else
"Start"
end %>
<%= button_to start_label,
lectures_start_path(id: lecture.id),
class: 'action-button'
%>
<% else %>
<%= button_to "Review",
lecture_start_review_path(id: lecture.id),
class: 'action-button' %>
class: 'action-button'
%>
<% end %>

View File

@ -0,0 +1,7 @@
Sidekiq.configure_server do |config|
config.redis = { url: ENV['REDIS_URL'] }
end
Sidekiq.configure_client do |config|
config.redis = { url: ENV['REDIS_URL'] }
end

View File

@ -12,7 +12,6 @@ Rails.application.routes.draw do
get '/courses/:id/renumber_lectures', to: 'courses#renumber_lectures', as: :course_renumber_lectures
get '/courses/:id/fill_in_default_live_video_url', to: 'courses#fill_in_default_live_video_url', as: :course_fill_in_default_live_video_url
get '/courses/:id/redo_toggl_entries', to: 'courses#redo_toggl_entries', as: :course_redo_toggl_entries
end
root controller: :attendance_tracker, action: :overview

27
config/sidekiq.yml Normal file
View File

@ -0,0 +1,27 @@
---
:concurrency: 5
staging:
:concurrency: 10
production:
:concurrency: 20
:queues:
- default
- mailers
# These are the cron jobs
:scheduler:
:schedule:
:lecture_checkin_job:
# Lectures start at 15 minutes past the hour so run the checkin script just before
cron: '14 * * * 1,2,3,4,5'
class: 'LectureCheckinJob'
queue: default
:scrape_panopto_job:
cron: '* * * * 1,2,3,4,5'
class: 'ScrapePanoptoJob'
queue: default
:scrape_toggl_job:
# Lectures end at 5 past the hour so scrape toggl a little after when I will have ended the time entry
cron: '10 * * * 1,2,3,4,5'
class: 'ScrapeTogglJob'
queue: default