-
Notifications
You must be signed in to change notification settings - Fork 20
Feature/859 team skill tracking over time #890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f60479e
Generate SkillSnapshot model
RandomTannenbaum 2e3b8ed
Make skills discardable
RandomTannenbaum 0586900
Rename SkillSnapshot to DepartmentSkillSnapshot, serialize skills as …
RandomTannenbaum 8346266
Add explanatory comment to the department skill snapshot builder
RandomTannenbaum fd5c8ff
Install and configure delayed_job_activerecord
RandomTannenbaum a35bb91
Install and configure delayed cron job
RandomTannenbaum ac9bac2
Add delayed cron job that is executed once a month and reates departm…
RandomTannenbaum 2857c43
Run rubocop fix
RandomTannenbaum cd57dc0
Rename field skills on department skill snapshot to department_skill_…
RandomTannenbaum 22c1c88
Start writing domain specs for departments
RandomTannenbaum 1c34691
Write test that tests creation of snapshots
RandomTannenbaum 0a190b6
Add delayed_job model to be able to read djs from console, make snaps…
RandomTannenbaum 610f306
Delete old migration test that is not needed anymore
RandomTannenbaum File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class DepartmentSkillsSnapshotBuilder | ||
# This will create snapshots of all departments with their respective skills and levels. | ||
# Each snapshot is an instance of DepartmentSkillSnapshot which takes a hash of skills. | ||
# This hash has the format: | ||
# { <skill_id1> => [skill_level1, skill_level2], <skill_id2> => [skill_level1, skill_level2] } | ||
# The count of skill_levels per skill_id is equal to the count of people that have rated that | ||
# skill in a given department. | ||
|
||
def snapshot_all_departments | ||
Person.where.not(department_id: nil).group_by(&:department_id).each do |department_id, people| | ||
department_skill_levels = PeopleSkill | ||
.where(person_id: people) | ||
.group_by(&:skill_id) | ||
.transform_values { |value| value.pluck(:level) } | ||
|
||
DepartmentSkillSnapshot.create!(department_id:, department_skill_levels:) | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
class CronJob < ApplicationJob | ||
class_attribute :cron_expression | ||
|
||
class << self | ||
def schedule | ||
set(cron: cron_expression).perform_later unless scheduled? | ||
end | ||
|
||
def remove | ||
delayed_job.destroy if scheduled? | ||
end | ||
|
||
def scheduled? | ||
delayed_job.present? | ||
end | ||
|
||
def delayed_job | ||
Delayed::Job | ||
.where('handler LIKE ?', "%job_class: #{name}%") | ||
.first | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class MonthlyDepartmentSkillsSnapshotJob < CronJob | ||
# Perform job on first day of month at 3am | ||
self.cron_expression = '0 3 1 * *' | ||
|
||
def perform | ||
DepartmentSkillsSnapshotBuilder.new.snapshot_all_departments | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class DelayedJob < ApplicationRecord | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class DepartmentSkillSnapshot < ApplicationRecord | ||
belongs_to :department | ||
|
||
serialize :department_skill_levels, type: Hash, coder: JSON | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment')) | ||
require 'delayed/command' | ||
Delayed::Command.new(ARGV).daemonize |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
db/migrate/20250509105746_create_department_skill_snapshots.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class CreateDepartmentSkillSnapshots < ActiveRecord::Migration[8.0] | ||
def change | ||
create_table :department_skill_snapshots do |t| | ||
t.references :department, null: false, foreign_key: true | ||
t.text :department_skill_levels | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class AddDiscardedAtToSkills < ActiveRecord::Migration[8.0] | ||
def change | ||
add_column :skills, :discarded_at, :datetime | ||
add_index :skills, :discarded_at | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class CreateDelayedJobs < ActiveRecord::Migration[8.0] | ||
def self.up | ||
create_table :delayed_jobs do |table| | ||
table.integer :priority, default: 0, null: false # Allows some jobs to jump to the front of the queue | ||
table.integer :attempts, default: 0, null: false # Provides for retries, but still fail eventually. | ||
table.text :handler, null: false # YAML-encoded string of the object that will do work | ||
table.text :last_error # reason for last failure (See Note below) | ||
table.datetime :run_at # When to run. Could be Time.zone.now for immediately, or sometime in the future. | ||
table.datetime :locked_at # Set when a client is working on this object | ||
table.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead) | ||
table.string :locked_by # Who is working on this object (if locked) | ||
table.string :queue # The name of the queue this job is in | ||
table.timestamps null: true | ||
end | ||
|
||
add_index :delayed_jobs, [:priority, :run_at], name: "delayed_jobs_priority" | ||
end | ||
|
||
def self.down | ||
drop_table :delayed_jobs | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class AddCronToDelayedJobs < ActiveRecord::Migration[8.0] | ||
def self.up | ||
add_column :delayed_jobs, :cron, :string | ||
end | ||
|
||
def self.down | ||
remove_column :delayed_jobs, :cron | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace :db do | ||
desc 'Schedule all cron jobs' | ||
task :schedule_jobs => :environment do | ||
# Need to load all jobs definitions in order to find subclasses | ||
glob = Rails.root.join('app', 'jobs', '**', '*_job.rb') | ||
Dir.glob(glob).each { |file| require file } | ||
CronJob.subclasses.each(&:schedule) | ||
end | ||
end | ||
|
||
# invoke schedule_jobs automatically after every migration and schema load. | ||
%w(db:migrate db:schema:load).each do |task| | ||
Rake::Task[task].enhance do | ||
Rake::Task['db:schedule_jobs'].invoke | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'rails_helper' | ||
|
||
describe PeopleSearch do | ||
it 'should create snapshot of all departments that have members' do | ||
DepartmentSkillsSnapshotBuilder.new.snapshot_all_departments | ||
|
||
snapshots = DepartmentSkillSnapshot.all | ||
|
||
expect(snapshots.count).to eql(Person.distinct.pluck(:department_id).count) | ||
|
||
department = departments(:sys) | ||
snapshot = snapshots.find_by(department_id: department) | ||
|
||
expect(snapshot).not_to be_nil | ||
|
||
department_skill_levels = snapshot.department_skill_levels | ||
people_skills_of_department = PeopleSkill.joins(:person).where(people: {department_id: department.id}) | ||
|
||
expect(department_skill_levels.keys).to match_array(people_skills_of_department.distinct.pluck(:skill_id).map(&:to_s)) | ||
department_skill_levels.each do |k, v| | ||
expect(people_skills_of_department.where(skill_id: k.to_i).pluck(:level)).to match_array(v) | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe DepartmentSkillSnapshot, type: :model do | ||
it 'should correctly serialize department_skill_levels' do | ||
department_skill_snapshot = DepartmentSkillSnapshot.create!(department_id: Department.first.id, department_skill_levels: {"1" => [2, 2, 3], "2" => [3, 3, 1]}) | ||
|
||
expect(department_skill_snapshot.department_skill_levels.is_a? Hash).to eql(true) | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.