bridge_cache 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 07fea4f39114b3ebd89681fc161b102aa38084e8
4
- data.tar.gz: 7470148ae9f315a9d8934ac876a5cc4fe9e51b14
3
+ metadata.gz: e5045ed7ca30bd85e45e9de0132e62bd51897b64
4
+ data.tar.gz: e209c97121ffe249951b61544d50c521276741ae
5
5
  SHA512:
6
- metadata.gz: ac00747411dd23c9ca6393957f932f69e991e99458550c1b83360732ec5a20d3150d932a75d3fe787d28de0f39d00be3ae408bc90888292fc6e26dc50f41312a
7
- data.tar.gz: 04c3008fe94fb312df966f72c28bc539d43a84854cd81b5f756e89b2fc0cedfdec000227ebe9d8e6beea5d507c24b959de0db7b1eaca2fa1896e748140e50704
6
+ metadata.gz: '0138bba40a8c262f455fb0f2a23c2b5e7c75bad96b5f6e01aefdadb7bd62ba93fbc680862545816f04209f79cf8879f1d650bf54a1a3e042c7bcc6cc8ea30d90'
7
+ data.tar.gz: f1a7838f7b39db4f3828c4842063ef16caf2ee5ae5082715fe2d46d9c5e1d365fc236828c1a50a494601a659e0b401be7880d209571410a5eb52db0d0e022310
@@ -2,9 +2,9 @@ module BridgeCache
2
2
  class CourseTemplate < ActiveRecord::Base
3
3
  extend BridgeCache::Data::BridgeModel
4
4
 
5
- belongs_to :user, foreign_key: :user_id, primary_key: :bridge_id, class_name: 'BridgeCache::User'
6
- belongs_to :domain, foreign_key: :domain_id, primary_key: :bridge_id, class_name: 'BridgeCache::Domain'
7
- belongs_to :sub_account, foreign_key: :sub_account_id, primary_key: :bridge_id, class_name: 'BridgeCache::Domain'
5
+ belongs_to :user, foreign_key: :user_id, primary_key: :bridge_id, class_name: 'BridgeCache::User', optional: true
6
+ belongs_to :domain, foreign_key: :domain_id, primary_key: :bridge_id, class_name: 'BridgeCache::Domain', optional: true
7
+ belongs_to :sub_account, foreign_key: :sub_account_id, primary_key: :bridge_id, class_name: 'BridgeCache::Domain', optional: true
8
8
  has_many :enrollments, foreign_key: :course_template_id, primary_key: :bridge_id, class_name: 'BridgeCache::Enrollment'
9
9
 
10
10
  end
@@ -2,7 +2,7 @@ module BridgeCache
2
2
  class CustomField < ActiveRecord::Base
3
3
  extend BridgeCache::Data::BridgeModel
4
4
 
5
- belongs_to :domain, foreign_key: :domain_id, primary_key: :bridge_id, class_name: 'BridgeCache::Domain'
5
+ belongs_to :domain, foreign_key: :domain_id, primary_key: :bridge_id, class_name: 'BridgeCache::Domain', optional: true
6
6
 
7
7
  end
8
8
  end
@@ -3,10 +3,10 @@ module BridgeCache
3
3
  extend BridgeCache::Data::BridgeModel
4
4
 
5
5
  has_many :domain_children, primary_key: 'bridge_id', foreign_key: 'parent_id', class_name: 'BridgeCache::Domain'
6
- belongs_to :domain_parent, primary_key: 'bridge_id', foreign_key: 'parent_id', class_name: 'BridgeCache::Domain'
6
+ belongs_to :domain_parent, primary_key: 'bridge_id', foreign_key: 'parent_id', class_name: 'BridgeCache::Domain', optional: true
7
7
 
8
8
  has_many :domain_ownees, primary_key: 'bridge_id', foreign_key: 'owner_id', class_name: 'BridgeCache::Domain'
9
- belongs_to :domain_owner, primary_key: 'bridge_id', foreign_key: 'owner_id', class_name: 'BridgeCache::Domain'
9
+ belongs_to :domain_owner, primary_key: 'bridge_id', foreign_key: 'owner_id', class_name: 'BridgeCache::Domain', optional: true
10
10
 
11
11
  has_many :programs, primary_key: 'bridge_id', foreign_key: 'domain_id', class_name: 'BridgeCache::Program'
12
12
  has_many :course_templates, primary_key: 'bridge_id', foreign_key: 'domain_id', class_name: 'BridgeCache::CourseTemplate'
@@ -2,8 +2,8 @@ module BridgeCache
2
2
  class Enrollment < ActiveRecord::Base
3
3
  extend BridgeCache::Data::BridgeModel
4
4
 
5
- belongs_to :user, foreign_key: :user_id, primary_key: :bridge_id, class_name: 'BridgeCache::User'
6
- belongs_to :course_template, foreign_key: :course_template_id, primary_key: :bridge_id, class_name: 'BridgeCache::CourseTemplate'
5
+ belongs_to :user, foreign_key: :user_id, primary_key: :bridge_id, class_name: 'BridgeCache::User', optional: true
6
+ belongs_to :course_template, foreign_key: :course_template_id, primary_key: :bridge_id, class_name: 'BridgeCache::CourseTemplate', optional: true
7
7
 
8
8
  end
9
9
  end
@@ -2,8 +2,8 @@ module BridgeCache
2
2
  class Grant < ActiveRecord::Base
3
3
  extend BridgeCache::Data::BridgeModel
4
4
 
5
- belongs_to :user, foreign_key: :user_id, primary_key: :bridge_id, class_name: 'BridgeCache::User'
6
- belongs_to :domain, foreign_key: :domain_id, primary_key: :bridge_id, class_name: 'BridgeCache::Domain'
5
+ belongs_to :user, foreign_key: :user_id, primary_key: :bridge_id, class_name: 'BridgeCache::User', optional: true
6
+ belongs_to :domain, foreign_key: :domain_id, primary_key: :bridge_id, class_name: 'BridgeCache::Domain', optional: true
7
7
 
8
8
  end
9
9
  end
@@ -4,7 +4,7 @@ module BridgeCache
4
4
 
5
5
  self.inheritance_column = nil
6
6
 
7
- belongs_to :user, foreign_key: :user_id, primary_key: :bridge_id, class_name: 'BridgeCache::User'
7
+ belongs_to :user, foreign_key: :user_id, primary_key: :bridge_id, class_name: 'BridgeCache::User', optional: true
8
8
  has_many :program_group_enrollments, foreign_key: :group_id, primary_key: :bridge_id, class_name: 'BridgeCache::ProgramGroupEnrollment'
9
9
 
10
10
  end
@@ -2,8 +2,8 @@ module BridgeCache
2
2
  class Program < ActiveRecord::Base
3
3
  extend BridgeCache::Data::BridgeModel
4
4
 
5
- belongs_to :domain, foreign_key: :domain_id, primary_key: :bridge_id, class_name: 'BridgeCache::Domain'
6
- belongs_to :sub_account, foreign_key: :sub_account_id, primary_key: :bridge_id, class_name: 'BridgeCache::Domain'
5
+ belongs_to :domain, foreign_key: :domain_id, primary_key: :bridge_id, class_name: 'BridgeCache::Domain', optional: true
6
+ belongs_to :sub_account, foreign_key: :sub_account_id, primary_key: :bridge_id, class_name: 'BridgeCache::Domain', optional: true
7
7
  has_many :program_items, foreign_key: :program_id, primary_key: :bridge_id, class_name: 'BridgeCache::ProgramItem'
8
8
  has_many :program_enrollments, foreign_key: :program_id, primary_key: :bridge_id, class_name: 'BridgeCache::ProgramEnrollment'
9
9
  has_many :program_group_enrollments, foreign_key: :program_id, primary_key: :bridge_id, class_name: 'BridgeCache::ProgramGroupEnrollment'
@@ -2,8 +2,8 @@ module BridgeCache
2
2
  class ProgramEnrollment < ActiveRecord::Base
3
3
  extend BridgeCache::Data::BridgeModel
4
4
 
5
- belongs_to :user, foreign_key: :user_id, primary_key: :bridge_id, class_name: 'BridgeCache::User'
6
- belongs_to :program, foreign_key: :program_id, primary_key: :bridge_id, class_name: 'BridgeCache::Program'
5
+ belongs_to :user, foreign_key: :user_id, primary_key: :bridge_id, class_name: 'BridgeCache::User', optional: true
6
+ belongs_to :program, foreign_key: :program_id, primary_key: :bridge_id, class_name: 'BridgeCache::Program', optional: true
7
7
 
8
8
  end
9
9
  end
@@ -2,8 +2,8 @@ module BridgeCache
2
2
  class ProgramGroupEnrollment < ActiveRecord::Base
3
3
  extend BridgeCache::Data::BridgeModel
4
4
 
5
- belongs_to :group, foreign_key: :group_id, primary_key: :bridge_id, class_name: 'BridgeCache::Group'
6
- belongs_to :program, foreign_key: :program_id, primary_key: :bridge_id, class_name: 'BridgeCache::Program'
5
+ belongs_to :group, foreign_key: :group_id, primary_key: :bridge_id, class_name: 'BridgeCache::Group', optional: true
6
+ belongs_to :program, foreign_key: :program_id, primary_key: :bridge_id, class_name: 'BridgeCache::Program', optional: true
7
7
 
8
8
  end
9
9
  end
@@ -2,7 +2,7 @@ module BridgeCache
2
2
  class ProgramItem < ActiveRecord::Base
3
3
  extend BridgeCache::Data::BridgeModel
4
4
 
5
- belongs_to :program, foreign_key: :program_id, primary_key: :bridge_id, class_name: 'BridgeCache::Program'
5
+ belongs_to :program, foreign_key: :program_id, primary_key: :bridge_id, class_name: 'BridgeCache::Program', optional: true
6
6
 
7
7
  end
8
8
  end
@@ -2,8 +2,8 @@ module BridgeCache
2
2
  class Tagging < ActiveRecord::Base
3
3
  extend BridgeCache::Data::BridgeModel
4
4
 
5
- belongs_to :tag, foreign_key: :tag_id, primary_key: :bridge_id, class_name: 'BridgeCache::Tag'
6
- belongs_to :user, foreign_key: :tagger_id, primary_key: :bridge_id, class_name: 'BridgeCache::User'
5
+ belongs_to :tag, foreign_key: :tag_id, primary_key: :bridge_id, class_name: 'BridgeCache::Tag', optional: true
6
+ belongs_to :user, foreign_key: :tagger_id, primary_key: :bridge_id, class_name: 'BridgeCache::User', optional: true
7
7
 
8
8
  end
9
9
  end
@@ -2,8 +2,8 @@ module BridgeCache
2
2
  class User < ActiveRecord::Base
3
3
  extend BridgeCache::Data::BridgeModel
4
4
 
5
- belongs_to :domain, foreign_key: :domain_id, primary_key: :bridge_id, class_name: 'BridgeCache::Domain'
6
- belongs_to :sub_account, foreign_key: :sub_account_id, primary_key: :bridge_id, class_name: 'BridgeCache::Domain'
5
+ belongs_to :domain, foreign_key: :domain_id, primary_key: :bridge_id, class_name: 'BridgeCache::Domain', optional: true
6
+ belongs_to :sub_account, foreign_key: :sub_account_id, primary_key: :bridge_id, class_name: 'BridgeCache::Domain', optional: true
7
7
  has_many :enrollments, foreign_key: :user_id, primary_key: :bridge_id, class_name: 'BridgeCache::Enrollment'
8
8
  has_many :course_templates, foreign_key: :user_id, primary_key: :bridge_id, class_name: 'BridgeCache::CourseTemplate'
9
9
  has_many :taggings, foreign_key: :user_id, primary_key: :bridge_id, class_name: 'BridgeCache::Tagging'
@@ -0,0 +1,17 @@
1
+ module BridgeCache::Jobs
2
+ class ImportCheck < ActiveJob::Base
3
+ queue_as :default
4
+ include BridgeCache::Utils::WorkerHelper
5
+
6
+ def perform(bridge_base_url, bridge_api_key, bridge_api_secret, models, chain = [])
7
+ remote_data = BridgeBlueprint::RemoteData.new(bridge_base_url, bridge_api_key, bridge_api_secret)
8
+ if remote_data.status == BridgeBlueprint::Constants::STATUS_COMPLETE
9
+ BridgeCache::Jobs::ImportData.set(queue: self.queue_name).perform_later(bridge_base_url, bridge_api_key, bridge_api_secret, models, chain)
10
+ elsif remote_data.status == BridgeBlueprint::Constants::STATUS_PENDING
11
+ BridgeCache::Jobs::ImportCheck.set(queue: self.queue_name, wait: 30.seconds).perform_later(bridge_base_url, bridge_api_key, bridge_api_secret, models, chain)
12
+ elsif remote_data.status == BridgeBlueprint::Constants::STATUS_FAILED || remote_data.status == BridgeBluePrint::Constants::STATUS_NOT_FOUND
13
+ raise 'Bridge data dump download failed'
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ module BridgeCache::Jobs
2
+ class ImportData < ActiveJob::Base
3
+ queue_as :default
4
+
5
+ def perform(bridge_base_url, bridge_api_key, bridge_api_secret, models, chain = [])
6
+ remote_data = BridgeBlueprint::RemoteData.new(bridge_base_url, bridge_api_key, bridge_api_secret)
7
+ Dir.mktmpdir do |dir|
8
+ path = "#{dir}/data_dump"
9
+ remote_data.store_file(path)
10
+ import = BridgeBlueprint::DataDump.new(path)
11
+ models.each do |model|
12
+ import.each_row(model.pluralize) do |row|
13
+ BridgeCache::Jobs::ImportRow.set(queue: self.queue_name).perform_later(model, row.to_h)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ module BridgeCache::Jobs
2
+ class ImportRow < ActiveJob::Base
3
+ queue_as :default
4
+
5
+ def perform(model, row, chain = [])
6
+ "BridgeCache::#{model.camelcase}".constantize.create_from_csv_row(row)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ module BridgeCache::Jobs
2
+ class ImportStart < ActiveJob::Base
3
+ queue_as :default
4
+
5
+ def perform(bridge_base_url, bridge_api_key, bridge_api_secret, models, chain = [])
6
+ data = BridgeBlueprint::RemoteData.new(bridge_base_url, bridge_api_key, bridge_api_secret)
7
+ data.start_data_report
8
+ BridgeCache::Jobs::ImportCheck
9
+ .set(queue: self.queue_name, wait: 30.seconds)
10
+ .perform_later(
11
+ bridge_base_url,
12
+ bridge_api_key,
13
+ bridge_api_secret,
14
+ models,
15
+ chain
16
+ )
17
+ end
18
+ end
19
+ end
@@ -27,7 +27,7 @@ module BridgeCache::Plugins
27
27
 
28
28
  def self.dump_row(clazz, row)
29
29
  instance = initialze_row(clazz, row)
30
- dump_rows([instance])
30
+ dump_rows(clazz, [instance])
31
31
  end
32
32
 
33
33
  private
@@ -0,0 +1,12 @@
1
+ module BridgeCache::Utils
2
+ module WorkerHelper
3
+ def self.invoke_next(job_chain, params = [])
4
+ job_chain ||= []
5
+ job = job_chain.shift
6
+ if job
7
+ job_class = Object.const_get(job[:job].classify)
8
+ job_class.perform_later(*(job[:params].concat(params)))
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module BridgeCache
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -1,29 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bridge_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - jshaffer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-22 00:00:00.000000000 Z
11
+ date: 2017-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '5.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bridge_blueprint
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: actionmailer
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -195,8 +209,13 @@ files:
195
209
  - lib/bridge_cache.rb
196
210
  - lib/bridge_cache/data/bridge_model.rb
197
211
  - lib/bridge_cache/engine.rb
212
+ - lib/bridge_cache/jobs/import_check.rb
213
+ - lib/bridge_cache/jobs/import_data.rb
214
+ - lib/bridge_cache/jobs/import_row.rb
215
+ - lib/bridge_cache/jobs/import_start.rb
198
216
  - lib/bridge_cache/plugins/csv_dump.rb
199
217
  - lib/bridge_cache/plugins/data_transform.rb
218
+ - lib/bridge_cache/utils/worker_helper.rb
200
219
  - lib/bridge_cache/version.rb
201
220
  - lib/tasks/bridge_cache_tasks.rake
202
221
  - test/bridge_cache_test.rb