Skip to content

Instantly share code, notes, and snippets.

@jcreed
Created September 17, 2021 14:59
Show Gist options
  • Save jcreed/ab5f75e74d435be6c9446c832bedc826 to your computer and use it in GitHub Desktop.
Save jcreed/ab5f75e74d435be6c9446c832bedc826 to your computer and use it in GitHub Desktop.
Auto Program Sync
class ProgramScopeSyncJob
extend Resque::FailureRetry
include Resque::Plugins::UniqueJob
@queue = :low
def self.perform(id)
new(id).sync_program
end
attr_accessor :program, :organization
def initialize(id)
@program = Program.find(id)
@organization = program.organization
end
def sync_program
local_statuses_scope_program
custom_fields_scope_program
applicant_headers_scope_program
users_scope_program
end
private
def local_statuses_scope_program
local_statuses = organization.local_statuses.with_auto_sync_programs
local_statuses.each do |local_status|
local_status.program_ids << @program.id
end
end
def custom_fields_scope_program
custom_fields = organization.custom_fields.with_auto_sync_programs
custom_fields.each do |custom_field|
custom_field.program_ids << @program.id
end
end
def applicant_headers_scope_program
applicant_headers = organization.applicant_details_headers.with_auto_sync_programs
applicant_headers.each do |applicant_header|
applicant_header.program_ids << @program.id
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment