caboose-rets 0.0.79 → 0.0.80

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTk3NDMxYmE0ZjI5NzNjMWUwMTlmZjQ1MWIzOTIzZTAyYTk4MWI4YQ==
4
+ NTgwODhiYTYyYjBkZjdmNDk3ZTJmYmMxOWU3MDViOTljZDM5Zjk3ZA==
5
5
  data.tar.gz: !binary |-
6
- NmE0Mjk2ODdkNTdhZDI1MzEwYzljYTMyMWE3MThkZTM0NDhjMzk0Mg==
6
+ YjM5YmRhNmFhYzY5ZjQ0YWJhZjRmNjVmZGM4NmJmZTc1M2UyNjdhZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NWJlOWM4M2I2YWEwOTVkMDBmNWI1ZDk2ZGFjZmU5OTY4OGYyYzg5ZTU3MjMz
10
- M2E3N2VjODRiOTM5NWFhNzNjNWM0OWM2ZGY4ZGUxZDJjNjdiMWQ2MTc4Y2Zi
11
- Y2FmZDYwNDVhYTE3ZWEzZWUwYjc1ZDdjNzgzZmMxZWE0NWQzMDA=
9
+ MzlhOWY2ZDQ0NTY1NTZmNWZlYmQ2OTBiYTM2YTEwYTM5MzY5YTA2NGZlMzkz
10
+ ZGQxMWNjNDc4NmExNjE4NDVjZGRmMDE0ZDM4ZDQ5ZDI2M2Y5MGMyNzUwMjll
11
+ ZDk4MGRlMTY3N2I1OTg0MTU2OTE0M2NiZjZjY2NiYjgxOTk4MmQ=
12
12
  data.tar.gz: !binary |-
13
- MGY1NGZmYTBhNTdmNGU2ZTBhNWY0OTgzYjkwNzY3ZThjNmVjMTJkNThhNjZh
14
- MmZiYzdiYjRkNmIzY2ExNDg5MjUyNjQ0YjlmOTcwZGE4NjY3MmIxMWM0ZTI2
15
- MjM4NmVmM2JiZWUzODFjYzcxYzdjMTYyNGZmOTc3MjAxOGQwODk=
13
+ ODlhYjA2Yjg1NDhmNTc0ZTU3OWUwYzE4MTU5ODQxOGY0YTFhOWZiZmY0Mjc2
14
+ NmNhYjI3YWQ1YThhNGMzZDg1ZjM4NjE0ZDIyMWNjOWE1ZGQ2NDM5ZWZiZDZj
15
+ ZjdiZDdkOGQwNTY4OTQzZmVhMjQzZjdlNjFmZWQ0MDE3ZWM2Mzc=
@@ -80,6 +80,7 @@ module CabooseRets
80
80
  @saved = logged_in? && SavedProperty.where(:user_id => logged_in_user.id, :mls_acct => params[:mls_acct]).exists?
81
81
  if @property.nil?
82
82
  @mls_acct = params[:mls_acct]
83
+ CabooseRets::RetsImporter.delay.import_property(@mls_acct.to_i)
83
84
  render 'land/not_exists'
84
85
  return
85
86
  end
@@ -61,6 +61,7 @@ module CabooseRets
61
61
  @saved = logged_in? && SavedProperty.where(:user_id => logged_in_user.id, :mls_acct => params[:mls_acct]).exists?
62
62
  if @property.nil?
63
63
  @mls_acct = params[:mls_acct]
64
+ CabooseRets::RetsImporter.delay.import_property(@mls_acct.to_i)
64
65
  render 'multi_family/not_exists'
65
66
  return
66
67
  end
@@ -74,7 +74,8 @@ module CabooseRets
74
74
  @agent = Agent.where(:la_code => @property.la_code).first
75
75
  end
76
76
  if @property.nil?
77
- @mls_acct = params[:mls_acct]
77
+ @mls_acct = params[:mls_acct]
78
+ CabooseRets::RetsImporter.delay.import_property(@mls_acct.to_i)
78
79
  render 'residential/residential_not_exists'
79
80
  return
80
81
  end
@@ -2,8 +2,7 @@
2
2
  class CabooseRets::Agent < ActiveRecord::Base
3
3
  self.table_name = "rets_agents"
4
4
  has_many :commercial_properties
5
- has_many :residential_properties
6
- # attr_accessible :title, :body
5
+ has_many :residential_properties
7
6
  has_attached_file :image,
8
7
  :path => 'rets/agents/:la_code_:style.:extension',
9
8
  :styles => {
@@ -11,6 +10,7 @@ class CabooseRets::Agent < ActiveRecord::Base
11
10
  :large => '200x300>'
12
11
  }
13
12
  do_not_validate_attachment_file_type :image
13
+ attr_accessible :id, :la_code
14
14
  after_initialize :fix_name
15
15
 
16
16
  def assistants
@@ -2,6 +2,8 @@
2
2
  class CabooseRets::OpenHouse < ActiveRecord::Base
3
3
  self.table_name = "rets_open_houses"
4
4
 
5
+ attr_accesible :id
6
+
5
7
  def property
6
8
  models = [CabooseRets::ResidentialProperty, CabooseRets::CommercialProperty, CabooseRets::LandProperty, CabooseRets::MultiFamilyProperty]
7
9
  models.each do |model|
@@ -68,7 +68,7 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
68
68
 
69
69
  def self.import(class_type, query)
70
70
  m = self.meta(class_type)
71
- self.log("Importing #{m.search_type}:#{class_type} with query #{query}...")
71
+ #self.log("Importing #{m.search_type}:#{class_type} with query #{query}...")
72
72
  self.get_config if @@config.nil? || @@config['url'].nil?
73
73
  params = {
74
74
  :search_type => m.search_type,
@@ -126,23 +126,24 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
126
126
  #=============================================================================
127
127
 
128
128
  def self.update_after(date_modified, save_images = true)
129
- self.update_helper('RES', date_modified, save_images)
130
- self.update_helper('COM', date_modified, save_images)
131
- self.update_helper('LND', date_modified, save_images)
132
- self.update_helper('MUL', date_modified, save_images)
133
- self.update_helper('OFF', date_modified, save_images)
134
- self.update_helper('AGT', date_modified, save_images)
135
- self.update_helper('OPH', date_modified, save_images)
129
+ self.delay.update_helper('RES', date_modified, save_images)
130
+ self.delay.update_helper('COM', date_modified, save_images)
131
+ self.delay.update_helper('LND', date_modified, save_images)
132
+ self.delay.update_helper('MUL', date_modified, save_images)
133
+ self.delay.update_helper('OFF', date_modified, save_images)
134
+ self.delay.update_helper('AGT', date_modified, save_images)
135
+ self.delay.update_helper('OPH', date_modified, save_images)
136
136
  end
137
137
 
138
138
  def self.update_helper(class_type, date_modified, save_images = true)
139
139
  m = self.meta(class_type)
140
- k = m.remote_key_field
140
+ k = m.remote_key_field
141
+ d = date_modified.in_time_zone(CabooseRets::timezone).strftime("%FT%T")
141
142
  params = {
142
143
  :search_type => m.search_type,
143
144
  :class => class_type,
144
145
  :select => [m.remote_key_field],
145
- :query => "(#{m.date_modified_field}=#{date_modified.strftime("%FT%T")}+)",
146
+ :query => "(#{m.date_modified_field}=#{d}+)",
146
147
  :standard_names_only => true,
147
148
  :timeout => -1
148
149
  }
@@ -478,8 +479,15 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
478
479
  # Logging
479
480
  #=============================================================================
480
481
 
481
- def self.log(msg)
482
+ def self.log(msg)
483
+ puts "[rets_importer] #{msg}"
484
+ #Rails.logger.info("[rets_importer] #{msg}")
485
+ end
486
+
487
+ def self.log2(msg)
488
+ puts "======================================================================"
482
489
  puts "[rets_importer] #{msg}"
490
+ puts "======================================================================"
483
491
  #Rails.logger.info("[rets_importer] #{msg}")
484
492
  end
485
493
 
@@ -488,7 +496,12 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
488
496
  #=============================================================================
489
497
 
490
498
  def self.update_rets
491
- return if self.task_is_locked
499
+ self.log2("Updating rets...")
500
+ if self.task_is_locked
501
+ self.log2("Task is locked, aborting.")
502
+ return
503
+ end
504
+ self.log2("Locking task...")
492
505
  task_started = self.lock_task
493
506
 
494
507
  begin
@@ -499,17 +512,30 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
499
512
  # Keep this in here to make sure all updates are caught
500
513
  #overlap = 1.month
501
514
  end
515
+
516
+ self.log2("Updating after #{self.last_updated.strftime("%FT%T%:z")}...")
502
517
  self.update_after(self.last_updated - overlap)
518
+
519
+ self.log2("Saving the timestamp for when we updated...")
503
520
  self.save_last_updated(task_started)
521
+
522
+ self.log2("Unlocking the task...")
504
523
  self.unlock_task
505
- rescue
524
+ rescue Exception => err
525
+ puts err
506
526
  raise
507
527
  ensure
528
+ self.log2("Unlocking task if last updated...")
508
529
  self.unlock_task_if_last_updated(task_started)
509
530
  end
510
531
 
511
532
  # Start the same update process in five minutes
512
- self.delay(:run_at => 1.minutes.from_now).update_rets
533
+ self.log2("Adding the update rets task for 5 minutes from now...")
534
+ q = "handler like '%update_rets%'"
535
+ count = Delayed::Job.where(q).count
536
+ if count == 0 || (count == 1 && Delayed::Job.where(q).first.locked_at)
537
+ self.delay(:run_at => 5.minutes.from_now).update_rets
538
+ end
513
539
  end
514
540
 
515
541
  def self.last_updated
@@ -529,14 +555,14 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
529
555
  end
530
556
 
531
557
  def self.save_last_updated(d)
532
- s = Caboose::Setting.where(:name => 'rets_last_updated').first
533
- s.value = d.strftime('%FT%T')
558
+ s = Caboose::Setting.where(:name => 'rets_last_updated').first
559
+ s.value = d.in_time_zone(CabooseRets::timezone).strftime("%FT%T%:z")
534
560
  s.save
535
561
  end
536
562
 
537
563
  def self.save_last_purged(d)
538
564
  s = Caboose::Setting.where(:name => 'rets_last_purged').first
539
- s.value = d.strftime('%FT%T')
565
+ s.value = d.in_time_zone(CabooseRets::timezone).strftime("%FT%T%:z")
540
566
  s.save
541
567
  end
542
568
 
@@ -544,9 +570,9 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
544
570
  return Caboose::Setting.exists?(:name => 'rets_update_running')
545
571
  end
546
572
 
547
- def self.lock_task
548
- d = DateTime.now.utc - 5.hours
549
- Caboose::Setting.create(:name => 'rets_update_running', :value => d.strftime('%F %T'))
573
+ def self.lock_task
574
+ d = DateTime.now.utc.in_time_zone(CabooseRets::timezone)
575
+ Caboose::Setting.create(:name => 'rets_update_running', :value => d.strftime("%FT%T%:z"))
550
576
  return d
551
577
  end
552
578
 
@@ -556,7 +582,7 @@ class CabooseRets::RetsImporter # < ActiveRecord::Base
556
582
 
557
583
  def self.unlock_task_if_last_updated(d)
558
584
  setting = Caboose::Setting.where(:name => 'rets_update_running').first
559
- self.unlock_task if setting && d.strftime('%F %T') == setting.value
585
+ self.unlock_task if setting && d.in_time_zone.strftime("%FT%T%:z") == setting.value
560
586
  end
561
587
 
562
588
  end
data/lib/caboose-rets.rb CHANGED
@@ -17,4 +17,7 @@ module CabooseRets
17
17
  mattr_accessor :offices_base_url
18
18
  @@offices_base_url = ''
19
19
 
20
+ mattr_accessor :timezone
21
+ @@timezone = 'Central Time (US & Canada)'
22
+
20
23
  end
@@ -1,3 +1,3 @@
1
1
  module CabooseRets
2
- VERSION = '0.0.79'
2
+ VERSION = '0.0.80'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caboose-rets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.79
4
+ version: 0.0.80
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Barry
@@ -49,7 +49,6 @@ files:
49
49
  - app/controllers/caboose_rets/saved_properties_controller.rb
50
50
  - app/controllers/caboose_rets/saved_searches_controller.rb
51
51
  - app/helpers/caboose_rets/application_helper.rb
52
- - app/models/caboose_rets/#Untitled-1#
53
52
  - app/models/caboose_rets/agent.rb
54
53
  - app/models/caboose_rets/commercial_property.rb
55
54
  - app/models/caboose_rets/land_property.rb
@@ -1,6 +0,0 @@
1
- heroku maintenance:on
2
- heroku ps:scale worker=0
3
- heroku pgbackups:transfer DATABASE_URL HEROKU_POSTGRESQL_PURPLE_URL
4
- heroku pg:promote HEROKU_POSTGRESQL_PURPLE_URL
5
- heroku ps:scale worker=1
6
- heroku maintenance:off