zuora_connect 1.5.03 → 1.5.04

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 166cb6acb2386c330f4bd0606bc49954a1f74ba2
4
- data.tar.gz: 46d7c7d0fffaeca07947b0c445cc50615723e397
3
+ metadata.gz: 824aaae9f843edae29e1d76e21fa69a575ff2e47
4
+ data.tar.gz: 7b387043e25d6227a60f640ec988e73ee724e46a
5
5
  SHA512:
6
- metadata.gz: e249d7640c336e2367baaaa6f7f8b7d5aa8ce6fd8bedd9740e46deb9ccc13ec2f639c8f0b317e8c25be725800ce47c4e8ee389d19a6c0c8bd31ce4e218934d11
7
- data.tar.gz: 92bb490c7ba14f08364274407639a16de90875894b59f2f3a4af43ed4015ccb5ee77969713eca708dc9ed5a0d93a2ab77081cf7377aefb68945c821c5fbb7c1a
6
+ metadata.gz: e234f53cec985f83a88d22bf4aad67a6b269cc4987edca3e30aa91fbed1bf51540d8735c9f6c338cd05520895879ef718912a53efce85e18901f0cd2c249d174
7
+ data.tar.gz: e3a8601d48936dfd55c2bec6fda15343d6bb520b649d0a92dcf7841dbc967773688b0d335a21fa5fab5be80d1aab0929e9d05260ecfbeba57ec42ce57e2bd13b
@@ -581,5 +581,17 @@ module ZuoraConnect
581
581
  end
582
582
  super
583
583
  end
584
+
585
+ def self.update_functions
586
+ ActiveRecord::Base.connection.execute(File.read("#{Gem.loaded_specs["zuora_connect"].gem_dir}/app/views/sql/refresh_aggregate_table.txt"))
587
+ end
588
+
589
+ def self.refresh_aggregate_table(aggregate_name: 'all_tasks_processing', table_name: 'tasks', where_clause: "where status in ('Processing', 'Queued')", index_table: true)
590
+ self.update_functions
591
+ #Broke function into two parts to ensure transaction size was small enough
592
+ ActiveRecord::Base.connection.execute('SELECT "shared_extensions".refresh_aggregate_table(\'%s\', \'%s\', %s, \'Table\');' % [aggregate_name, table_name, ActiveRecord::Base.connection.quote(where_clause)])
593
+ ActiveRecord::Base.connection.execute('SELECT "shared_extensions".refresh_aggregate_table(\'%s\', \'%s\', %s, \'Index\');' % [aggregate_name, table_name, ActiveRecord::Base.connection.quote(where_clause)]) if index_table
594
+ end
595
+
584
596
  end
585
597
  end
@@ -0,0 +1,84 @@
1
+ CREATE OR REPLACE FUNCTION "shared_extensions".refresh_aggregate_table(aggregate_table_name text, table_name text, filter text, mode text) RETURNS void AS $$
2
+ DECLARE
3
+ schema RECORD;
4
+ result RECORD;
5
+ sql TEXT := '';
6
+ i INTEGER;
7
+ created boolean := false;
8
+ fields_order character varying;
9
+ index_name varchar;
10
+ index_string varchar;
11
+ index_id varchar;
12
+ BEGIN
13
+ IF mode = 'Table' THEN
14
+ raise notice 'Starting aggregate of % to %', table_name, aggregate_table_name;
15
+
16
+
17
+ EXECUTE format('DROP TABLE IF EXISTS "public".%I', aggregate_table_name);
18
+ raise notice 'Filter %', filter;
19
+
20
+ FOR schema IN EXECUTE
21
+ format(
22
+ 'SELECT schema_name FROM information_schema.schemata WHERE schema_name ~ ''^[0-9]+$'''
23
+ )
24
+ LOOP
25
+ IF NOT created THEN
26
+ -- Create the aggregate table if we haven't already
27
+ EXECUTE format(
28
+ 'CREATE TABLE "public".%I (LIKE %I.%I)',
29
+ aggregate_table_name,
30
+ schema.schema_name, table_name
31
+ );
32
+ -- Add a special `schema_name` column, which we'll populate with the name of the schema
33
+ -- each row originated from
34
+ EXECUTE format(
35
+ 'ALTER TABLE "public".%I ADD COLUMN schema_name text', aggregate_table_name
36
+ );
37
+ created := true;
38
+ END IF;
39
+
40
+ -- Finally, we'll select everything from this schema's target table, plus the schema's name,
41
+ -- and insert them into our new aggregate table
42
+ EXECUTE format(
43
+ 'SELECT string_agg(column_name, '','') from information_schema.columns where table_name = ''%s'' AND table_schema = ''%s''',
44
+ table_name, schema.schema_name
45
+ ) into fields_order;
46
+
47
+ raise notice 'Importing Schema %', schema.schema_name;
48
+
49
+ EXECUTE format(
50
+ 'INSERT INTO "public".%I (schema_name, %s) (SELECT ''%s'' AS schema_name, * FROM %I.%I %s )',
51
+ aggregate_table_name,
52
+ fields_order,
53
+ schema.schema_name,
54
+ schema.schema_name, table_name,
55
+ filter
56
+ );
57
+ END LOOP;
58
+
59
+ EXECUTE
60
+ format('CREATE INDEX ON "public".%I (schema_name)', aggregate_table_name);
61
+ EXECUTE
62
+ format('CREATE INDEX ON "public".%I (id)', aggregate_table_name);
63
+ END IF;
64
+ IF mode = 'Index' THEN
65
+ FOR index_string, index_name, index_id IN
66
+ SELECT pg_get_indexdef(idx.oid)||';', idx.relname, idx.oid
67
+ from pg_index ind
68
+ join pg_class idx on idx.oid = ind.indexrelid
69
+ join pg_class tbl on tbl.oid = ind.indrelid
70
+ left join pg_namespace ns on ns.oid = tbl.relnamespace where idx.relname != concat(table_name, '_pkey') and tbl.relname = table_name and ns.nspname = 'public'
71
+ LOOP
72
+ BEGIN
73
+ EXECUTE
74
+ format('DROP INDEX IF EXISTS "public"."%s"', concat(aggregate_table_name, '_', index_id));
75
+
76
+ EXECUTE
77
+ format(replace(replace(index_string, index_name, concat(aggregate_table_name, '_', index_id)), concat(' ', table_name, ' '), concat( ' ', aggregate_table_name, ' ')));
78
+
79
+ RAISE NOTICE 'Creating Indexes %', replace(replace(replace(index_string, index_name, concat(aggregate_table_name, '_', index_id)), concat(' ', table_name, ' '), concat( ' ', aggregate_table_name, ' ')), concat('public.', table_name), concat( 'public.', aggregate_table_name)) ;
80
+ END;
81
+ END LOOP;
82
+ END IF;
83
+ END
84
+ $$ LANGUAGE plpgsql;
@@ -1,6 +1,6 @@
1
1
  redis_url = ENV["REDIS_URL"].present? ? ENV["REDIS_URL"] : 'redis://localhost:6379/1'
2
2
  if defined?(Redis.current)
3
- Redis.current = Redis.new(:url => redis_url, :timeout => 1)
3
+ Redis.current = Redis.new(:url => redis_url, :timeout => 10)
4
4
  if defined?(Resque.redis)
5
5
  Resque.redis = Redis.current
6
6
  end
@@ -1,5 +1,5 @@
1
1
  if defined?(Resque::Worker)
2
2
  Resque.send(:extend, Resque::Additions)
3
- Resque::Worker.send(:include, Resque::DynamicQueues)
3
+ #Resque::Worker.send(:include, Resque::DynamicQueues)
4
4
  Resque::Job.send(:include, Resque::SelfLookup)
5
5
  end
@@ -22,11 +22,11 @@ module Resque
22
22
  matched_queues = []
23
23
 
24
24
  #Remove Queues under Api Limits
25
- api_limit_instances = Redis.current.keys("APILimits:*").map {|key| key.split('APILimits:').last.to_i}
25
+ api_limit_instances = Redis.current.keys('APILimits:*').map {|key| key.split('APILimits:').last.to_i}
26
26
  real_queues = real_queues.select {|key| key if !api_limit_instances.include?((key.match(/^(\d*)_.*/) || [])[1].to_i)}
27
27
 
28
28
  #Queue Pausing
29
- paused_instances = Redis.current.keys("resque:PauseQueue:*").map {|key| key.split('resque:PauseQueue:').last.to_i}
29
+ paused_instances = Redis.current.keys('resque:PauseQueue:*').map {|key| key.split('resque:PauseQueue:').last.to_i}
30
30
  real_queues = real_queues.select {|key| key if !paused_instances.include?((key.match(/^(\d*)_.*/) || [])[1].to_i)}
31
31
 
32
32
  while q = queue_names.shift
@@ -48,7 +48,7 @@ module Resque
48
48
  q = q[1..-1]
49
49
  end
50
50
 
51
- patstr = q.gsub(/\*/, ".*")
51
+ patstr = q.gsub(/\*/, '.*')
52
52
  pattern = /^#{patstr}$/
53
53
  if negated
54
54
  matched_queues -= matched_queues.grep(pattern)
@@ -9,7 +9,6 @@ module Resque
9
9
  return @payload_class
10
10
  end
11
11
 
12
-
13
12
  def self.included(receiver)
14
13
  receiver.class_eval do
15
14
  alias payload_class_old payload_class
@@ -1,3 +1,3 @@
1
1
  module ZuoraConnect
2
- VERSION = "1.5.03"
2
+ VERSION = "1.5.04"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zuora_connect
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.03
4
+ version: 1.5.04
5
5
  platform: ruby
6
6
  authors:
7
7
  - Connect Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-19 00:00:00.000000000 Z
11
+ date: 2017-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: apartment
@@ -207,6 +207,7 @@ files:
207
207
  - app/models/zuora_connect/app_instance_base.rb
208
208
  - app/models/zuora_connect/login.rb
209
209
  - app/views/layouts/zuora_connect/application.html.erb
210
+ - app/views/sql/refresh_aggregate_table.txt
210
211
  - app/views/zuora_connect/static/invalid_app_instance_error.html.erb
211
212
  - app/views/zuora_connect/static/session_error.html.erb
212
213
  - config/initializers/apartment.rb