Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Tracy Lum talum

Block or report user

Report or block talum

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@talum
talum / ch3and4.md
Created Nov 27, 2018
microservices_patterns
View ch3and4.md

Microservices Patterns

Chapter 3 Interprocess Communication in a microservice architecture

Intro

IPC (Interprocess Communication)

  • REST w/ JSON - the fashionable choice
  • Messaging

Considerations

View sti_5.rb
class Lesson < Curriculum
belongs_to :canonical_material, class_name: CourseWork::CanonicalMaterial
has_one :lab, foreign_key: :curriculum_id
def lab?
if $rollout.active?(:remove_content)
canonical_material.lab?
else
!!lab
end
View sti_4.rb
class AssignedRepo < ActiveRecord::Base
def contents
if $rollout.active?(:remove_content)
raise 'Contents called from assigned repo.' # Remove method when removing :remove_content rollout
else
return self.none if canonical.nil?
canonical.contents
end
end
View sti_3.rb
class Track < Curriculum
def labs
if $rollout.active?(:remove_content)
CourseWork::CanonicalMaterial
.joins(:lessons)
.where(curriculums: {track_id: self.id})
.where(kind: CourseWork::CanonicalMaterial::LAB_KINDS)
else
Lab.where(track_id: self.id)
end
View sti_2.rb
class Api::V1::SearchesController < ApiController
def new
gh_id_mappings = if $rollout.active?(:remove_content)
GithubRepository.track_data_for_github_repos(repos.pluck(:id), current_user.active_track_id)
else
GithubRepository.github_id_mappings_for_global_search(current_user)
end
# omitted
end
View sti_1b.rb
# some other caller
def set_projects_progress_status!
project_repo_ids = AssignedRepo.team_projects_for(batch_id: batch.id, track_id: track.id).pluck(:canonical_id)
end
def set_projects_progress_status!
project_repo_ids = AssignedRepo.team_projects_for(batch_id: batch.id, track_id: track.id).canonical_github_repository_ids
end
# Assigned Repo
@talum
talum / sti_1a.rb
Last active Nov 25, 2018
STI examples
View sti_1a.rb
def completed_labs_count(student, canonical_repo_ids)
if $rollout.active?(:remove_content)
student.canonical_progresses.complete.
joins(github_repository: :canonical_material).
where(github_repository_id: canonical_repo_ids).
where(kind: CourseWork::CanonicalMaterial::LAB_KINDS).
uniq(:id).
count
else
student.canonical_progresses.complete.
View publishable_assignment_validation.rb
class PublishableAssignmentValidation
attr_reader :assignment
def initialize(assignment)
@assignment = assignment
end
def valid?
validate
assignment.errors.none?
View assignment.rb
class Assignment < ActiveRecord:Base
# code omitted
def set_tasks_from_list(task_attributes)
self.tasks = self.tasks.new(task_attributes)
end
def set_collaborators_from_list(collaborator_ids)
collaborators = collaborator_ids.map { |id| { collaborator_id: id } }
self.collaborations = self.collaborations.new(collaborators)
View assignments.rb
module Assignments
# This code lives in a module that we use to namespace our application as part of domain-driven design. You might call this an aggregate root.
def self.update_assignment(assignment_id, title:, description:, collaborator_ids:, assignee_ids:, tasks:, due_in:, due_in_units:)
assignment = Assignment
.includes(tasks: :rubric_items)
.find(assignment_id)
assignment.update(
title: title,
description: description,
You can’t perform that action at this time.