Francisco Quinones

Joined

7,370 Experience
40 Lessons Completed
2 Questions Solved

Activity

<% cache [record_list, current_user.role.id, current_user.role.updated_at ,current_company.id ] do %>
stuff
<%end%>

Hi! chris. Im using Roles and Cancancan all over my app. I was thinking of adding the role record to the cache, has it will create a cache base on the role and not the current_user. What do you think about this approach?

Posted in Advanced Counter Caching Discussion

I was having problem with counter caching with condition and found this the other day in week's ruby https://blog.heroku.com/sol...

Just checking if this a typo when you past it.

  has_many :deck_cards, through: :deck_cards

did you mean?

`has_many :decks, through: :deck_cards`

@deniel will love to see a demo app on this approach as I can clean my code a lot with this trick. your using a Single Table Inheritance

Posted in How to add ssl to the CDN of AWS

I got it working. I need it to use ssl with a wildcard for subdomain for the assets. Now im using cdn.mysite.com with dns and works great.

Posted in How to add ssl to the CDN of AWS

Hi so I have a rails app with ssl from godadddy with a wildcard for subdomain. Now I move my assets to use CDN, but I need to use the ssl so all my subdomain use the assets with out getting CORS policy errors.

Posted in Advanced Counter Caching Discussion

YEY Chris! +1

Posted in Rails Counter Caches Discussion

Thank You Chris

Posted in Decorators From Scratch Discussion

mmm... looks like a lot of dependency and complexity to keep a eye for.

wow great talk will love to see more dev. talk like this. thank you all.

Posted in Apartment and Sidekiq

the problem was profile
worker: bundle exec sidekiq -e production -C ./config/sidekiq.yml
chage it to
worker: bundle exec sidekiq -C ./config/sidekiq.yml

Posted in Our First API (Example) - GoRails

like the bonus tips at the end.

Posted in Apartment and Sidekiq

its like sidekiq is running this command on redis db and not the rails db maybe?

Posted in Apartment and Sidekiq

running same code in public

        12:06:03 worker.1  | 2016-12-19T16:06:03.901Z 7982 TID-ov17zarr8 INFO: Running in ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]
        12:06:03 worker.1  | 2016-12-19T16:06:03.901Z 7982 TID-ov17zarr8 INFO: See LICENSE and the LGPL-3.0 for licensing details.
        12:06:03 worker.1  | 2016-12-19T16:06:03.901Z 7982 TID-ov17zarr8 INFO: Upgrade to Sidekiq Pro for more features and support: http://sidekiq.org
        12:06:03 worker.1  | 2016-12-19T16:06:03.903Z 7982 TID-ov17zarr8 INFO: Starting processing, hit Ctrl-C to stop
        12:06:03 worker.1  | 2016-12-19T16:06:03.974Z 7982 TID-ov19dahp0 MyWorker JID-99b40a9908c8b8f114434bd8 INFO: start
        12:06:03 worker.1  | ------------------------
        12:06:03 worker.1  | ------------------------
        12:06:03 worker.1  | Tenant public
        12:06:03 worker.1  | ------------------------
        12:06:03 worker.1  | ------------------------

Adding User.last in public schema
12:08:26 worker.1 | 2016-12-19T16:08:26.441Z 8064 TID-oxmshthdc WARN: ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "public.users" does not exist
12:08:26 worker.1 | LINE 1: SELECT "public"."users".* FROM "public"."users" ORDER BY "...

Posted in Apartment and Sidekiq

So Im working with apartment and sidekiq and the job is not switch tenant.

gem 'apartment', '~> 1.0', '>= 1.0.2'
gem 'sidekiq', '~> 4.0', '>= 4.1'
gem 'apartment-sidekiq', '~> 0.2.0'

class MyWorker
    include Sidekiq::Worker
    def perform(tenant)
            puts  "------------------------"
            puts  "------------------------"
            puts  "Tenant #{tenant}"
            puts  "Current Tenant #{Apartment::Tenant.current}"
            puts  "------------------------"
            puts  "------------------------"
    end
end


sidekiq setup:

require 'sidekiq'
require 'autoscaler/sidekiq'
require 'autoscaler/heroku_scaler'

Rails.logger = Sidekiq::Logging.logger

heroku = nil
if ENV['HEROKU_APP']
  heroku = Autoscaler::HerokuScaler.new
end

Sidekiq.configure_client do |config|
  config.redis = { size: 1, url: ENV['REDIS_URL']}
  if heroku
    config.client_middleware do |chain|
      chain.add Autoscaler::Sidekiq::Client, 'default' => heroku
    end
  end
end

Sidekiq.configure_server do |config|
  config.redis = { size: 27, url: ENV['REDIS_URL']}
  database_url = ENV['DATABASE_URL']
  if database_url
    ENV['DATABASE_URL'] = "#{database_url}?pool=25"
    ActiveRecord::Base.establish_connection
  end
  config.server_middleware do |chain|
    if heroku
      p "[Sidekiq] Running on Heroku, autoscaler is used"
      chain.add(Autoscaler::Sidekiq::Server, heroku, 60) # 60 seconds timeout
    else
      p "[Sidekiq] Running locally, so autoscaler isn't used"
    end
  end
end






MyWorker.perform_in(1.seconds, Apartment::Tenant.current)


2016-12-19T15:33:56.927Z 7489 TID-ox4ubmy98 INFO: Booting Sidekiq 4.2.7 with redis options {:size=>27, :url=>"redis://localhost:6379/0"}
11:33:56 worker.1  | "[Sidekiq] Running locally, so autoscaler isn't used"
11:33:58 worker.1  | 2016-12-19T15:33:58.356Z 7489 TID-ox4ubmy98 INFO: Running in ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]
11:33:58 worker.1  | 2016-12-19T15:33:58.356Z 7489 TID-ox4ubmy98 INFO: See LICENSE and the LGPL-3.0 for licensing details.
11:33:58 worker.1  | 2016-12-19T15:33:58.356Z 7489 TID-ox4ubmy98 INFO: Upgrade to Sidekiq Pro for more features and support: http://sidekiq.org
11:33:58 worker.1  | 2016-12-19T15:33:58.361Z 7489 TID-ox4ubmy98 INFO: Starting processing, hit Ctrl-C to stop
11:34:10 worker.1  | 2016-12-19T15:34:10.773Z 7489 TID-ox4vqdyhs MyWorker JID-882bc1314ea2ee37435e89ce INFO: start
11:34:10 worker.1  | 2016-12-19T15:34:10.775Z 7489 TID-ox4vqe0x0 MyWorker JID-8d1f27f683ff53d80921744f INFO: start
11:34:10 worker.1  | 2016-12-19T15:34:10.798Z 7489 TID-ox4vqdyhs MyWorker JID-882bc1314ea2ee37435e89ce INFO: fail: 0.025 sec
11:34:10 worker.1  | 2016-12-19T15:34:10.798Z 7489 TID-ox4vqdyhs WARN: {"context":"Job raised exception","job":{"class":"MyWorker","args":["companydemo"],"retry":true,"queue":"default","jid":"882bc1314ea2ee37435e89ce","created_at":1482160998.107182,"apartment":"companydemo","enqueued_at":1482161650.772489,"error_message":"One of the following schema(s) is invalid: \"companydemo\" \"public\"","error_class":"Apartment::TenantNotFound","failed_at":1482161016.38253,"retry_count":3,"retried_at":1482161650.79791},"jobstr":"{\"class\":\"MyWorker\",\"args\":[\"companydemo\"],\"retry\":true,\"queue\":\"default\",\"jid\":\"882bc1314ea2ee37435e89ce\",\"created_at\":1482160998.107182,\"apartment\":\"companydemo\",\"enqueued_at\":1482161650.772489,\"error_message\":\"One of the following schema(s) is invalid: \\\"companydemo\\\" \\\"public\\\"\",\"error_class\":\"Apartment::TenantNotFound\",\"failed_at\":1482161016.38253,\"retry_count\":2,\"retried_at\":1482161078.826396}"}
11:34:10 worker.1  | 2016-12-19T15:34:10.798Z 7489 TID-ox4vqdyhs WARN: Apartment::TenantNotFound: One of the following schema(s) is invalid: "companydemo" "public"
11:34:10 worker.1  | 2016-12-19T15:34:10.798Z 7489 TID-ox4vqdyhs WARN: /Users/IFrank/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/apartment-1.2.0/lib/apartment/adapters/postgresql_adapter.rb:72:in `rescue in connect_to_new'
11:34:10 worker.1  | /Users/IFrank/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/apartment-1.2.0/lib/apartment/adapters/postgresql_adapter.rb:65:in `connect_to_new'
11:34:10 worker.1  | /Users/IFrank/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/apartment-1.2.0/lib/apartment/adapters/abstract_adapter.rb:91:in `block in switch!'
11:34:10 worker.1  | /Users/IFrank/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:88:in `__run_callbacks__'
11:34:10 worker.1  | /Users/IFrank/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:778:in `_run_switch_callbacks'
11:34:10 worker.1  | /Users/IFrank/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:81:in `run_callbacks'
11:34:10 worker.1  | /Users/IFrank/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/apartment-1.2.0/lib/apartment/adapters/abstract_adapter.rb:88:in `switch!'
11:34:10 worker.1  | /Users/IFrank/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/apartment-1.2.0/lib/apartment/adapters/abstract_adapter.rb:105:in `switch'
11:34:10 worker.1  | /Users/IFrank/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/apartment-sidekiq-0.2.0/lib/apartment/sidekiq/middleware/server.rb:4:in `call'
11:34:10 worker.1  | /Users/IFrank/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sidekiq-4.2.7/lib/sidekiq/middleware/chain.rb:130:in `block in invoke'
11:34:10 worker.1  | /Users/IFrank/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sidekiq-4.2.7/lib/sidekiq/middleware/server/active_record.rb:6:in `call'
11:34:10 worker.1  | /Users/IFrank/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sidekiq-4.2.7/lib/sidekiq/middleware/chain.rb:130:in `block in invoke'
11:34:10 worker.1  | /Users/IFrank/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sidekiq-4.2.7/lib/sidekiq/middleware/server/retry_jobs.rb:74:in `call'
11:34:10 worker.1  | /Users/IFrank/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sidekiq-4.2.7/lib/sidekiq/middleware/chain.rb:130:in `block in invoke'
11:34:10 worker.1  | /Users/IFrank/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sidekiq-4.2.7/lib/sidekiq/middleware/server/logging.rb:11:in `block in call'
11:34:10 worker.1  | /Users/IFrank/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sidekiq-4.2.7/lib/sidekiq/logging.rb:32:in `with_context'
11:34:10 worker.1  | /Users/IFrank/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sidekiq-4.2.7/lib/sidekiq/middleware/server/logging.rb:7:in `call'
11:34:10 worker.1  | /Users/IFrank/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sidekiq-4.2.7/lib/sidekiq/middleware/chain.rb:130:in `block in invoke'
11:34:10 worker.1  | /Users/IFrank/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sidekiq-4.2.7/lib/sidekiq/middleware/chain.rb:133:in `invoke'
11:34:10 worker.1  | /Users/IFrank/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sidekiq-4.2.7/lib/sidekiq/processor.rb:132:in `block (2 levels) in process'
11:34:10 worker.1  | /Users/IFrank/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sidekiq-4.2.7/lib/sidekiq/processor.rb:174:in `stats'
11:34:10 worker.1  | /Users/IFrank/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sidekiq-4.2.7/lib/sidekiq/processor.rb:131:in `block in process'
11:34:10 worker.1  | /Users/IFrank/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sidekiq-4.2.7/lib/sidekiq.rb:35:in `block in <module:Sidekiq>'
11:34:10 worker.1  | /Users/IFrank/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sidekiq-4.2.7/lib/sidekiq/processor.rb:126:in `process'
11:34:10 worker.1  | /Users/IFrank/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sidekiq-4.2.7/lib/sidekiq/processor.rb:82:in `process_one'
11:34:10 worker.1  | /Users/IFrank/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sidekiq-4.2.7/lib/sidekiq/processor.rb:70:in `run'
11:34:10 worker.1  | /Users/IFrank/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sidekiq-4.2.7/lib/sidekiq/util.rb:17:in `watchdog'
11:34:10 worker.1  | /Users/IFrank/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sidekiq-4.2.7/lib/sidekiq/util.rb:25:in `block in safe_thread'
11:34:10 worker.1  | 2016-12-19T15:34:10.800Z 7489 TID-ox4vqe0x0 MyWorker JID-8d1f27f683ff53d80921744f INFO: fail: 0.025 sec

Posted in Adding Exceptions To Recurring Events Discussion

Chris love to see a reschedule event or one recurrent.

Posted in Recurring events with the ice_cube gem Discussion

On my app I use a Event and a EventTrans model so for each time a event occurs we can have a record with info and other stuff. So for the Calendar we display the First event with the recurrent on the fly and each time the event pass we save it as a record or if we need to move only on recurrent we create it as a event transaction.

My only problem is the time it takes to check if a recurrent is create as event_trans or not for calendar view.

As always Chris great job

logo Created with Sketch.

Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

© 2020 GoRails, LLC. All rights reserved.