I want to use cache-money but I don't want to start automatically caching everything (I'm working with a large production app, terabytes of data etc). How do I use it for only the models that I specify? Right now I've got:
# initializers/cache_money.rb
require 'cache_money'
config = (cfg = YAML.load(IO.read(File.join(RAILS_ROOT, "config", "memcached.yml"))))[RAILS_ENV] || cfg["defaults"]
$memcache = MemCache.new(config)
$memcache.servers = config['servers']
$local = Cash::Local.new($memcache)
$lock = Cash::Lock.new($memcache)
$cache = Cash::Transactional.new($local, $lock)
and then in the model I want to cache with cache-money:
# my_model.rb
class MyModel < ActiveRecord::Base
is_cached :repository => $cache
# ...
end
But this doesn't work; the call to is_cached gives the following error: NoMethodError: undefined method `create' for Config:Module
Any ideas? Failing that, is there anywhere I can go for help with cache-money? I couldn't find a mailing list or anything.
I think this is a bug in the cache_money code.
There are forks available on github that fix this bug, eg:
http://github.com/quake/cache-money
The fix can be seen with this commit:
http://github.com/quake/cache-money/commit/54c3d12789f31f2904d1fe85c102d7dbe5829590
I've just experienced the same problem trying to deploy an application. Running on my development machine it was fine, but it failed with this error on the production machine.
Apart from the architecture (OSX vs CentOS) the only difference i could see was that the ruby versions were different (1.8.6 p114 vs 1.8.6 p0). After upgrading the server to the latest 1.8 version (1.8.7 p160) this error went away.
Related
I’m developing with Ruby on Rails. When I start an application server with Puma, the following logs continue to show every a few seconds.
{"method":{},"path":{},"format":{},"params":{},"controller":"ApplicationCable::Connection","action":"connect","status":200,"duration":8.75,"backtrace":null,"host":null,"user_id":null,"user_type":null,"remote_ip":null,"user_agent":null,"os":null,"os_version":null,"browser":null,"browser_version":null,"#timestamp":"2021-07-28T10:24:34.068Z","#version":"1","message":"[200] (ApplicationCable::Connection#connect)"}
{"method":{},"path":{},"format":{},"params":{},"controller":"ApplicationCable::Connection","action":"disconnect","status":200,"duration":0.58,"backtrace":null,"host":null,"user_id":null,"user_type":null,"remote_ip":null,"user_agent":null,"os":null,"os_version":null,"browser":null,"browser_version":null,"#timestamp":"2021-07-28T10:24:34.069Z","#version":"1","message":"[200] (ApplicationCable::Connection#disconnect)"}
This interrupts binding.pry prompts as follow, so I can’t debug an application properly.
[1] pry(#<SomeController>)> {"method":{},"path":{},"format":{},"params":{},"controller":"ApplicationCable::Connection","action":"connect","status":200,"duration":8.75,"backtrace":null,"host":null,"user_id":null,"user_type":null,"remote_ip":null,"user_agent":null,"os":null,"os_version":null,"browser":null,"browser_version":null,"#timestamp":"2021-07-28T10:24:34.068Z","#version":"1","message":"[200] (ApplicationCable::Connection#connect)"}
{"method":{},"path":{},"format":{},"params":{},"controller":"ApplicationCable::Connection","action":"disconnect","status":200,"duration":0.58,"backtrace":null,"host":null,"user_id":null,"user_type":null,"remote_ip":null,"user_agent":null,"os":null,"os_version":null,"browser":null,"browser_version":null,"#timestamp":"2021-07-28T10:24:34.069Z","#version":"1","message":"[200] (ApplicationCable::Connection#disconnect)"}
I wasn’t able to find from which these logs show.
What I’ve tried is adding ActionCable.server.config.logger = Logger.new(nil) to config/application.rb. But I still have the problem.
https://dev.to/xlts/fixing-rails-action-cable-logger-la8#option-2-try-to-do-it-systematically
How can I fix this problem?
Thank you in advance.
I’m using Lograge, so I’ve resolved this problem by adding the following configuration to config/initializers/lograge.rb.
Rails.application.configure do
# ...
# ...
# ...
config.lograge.ignore_actions = [
"ApplicationCable::Connection#connect",
"ApplicationCable::Connection#disconnect"
]
end
I am trying to get some basic information from the Steam Community via the steam-condenser gem and so far the Steam.new seems to work just fine with all the players information.
however when I do this (example)
player = SteamId.new("tiger")
stats = player.fetch_games
I get the following error message
Traceback (most recent call last):
1: from lib/assets/ruby/test.rb:15:in `<main>'
/home/zigs/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/steam-condenser-1.3.11/lib/steam/community/steam_id.rb:326:in `fetch_games': undefined method `[]' for nil:NilClass (NoMethodError)
A lot of the information I need seems to be connected to the fetch_games (for example the method total_playtime(id))
Not sure why this is not working. I am lost. Any help or ideas are highly appreciated! Thank you!
TLDR; it looks like this gem no longer works.
the particular module that you're having trouble with is:
def fetch_games
games_data = parse "#{base_url}/games?xml=1"
#games = {}
#recent_playtimes = {}
#total_playtimes = {}
games_data['games']['game'].each do |game_data|
app_id = game_data['appID'].to_i
#games[app_id] = SteamGame.new app_id, game_data
recent = game_data['hoursLast2Weeks'].to_f
total = (game_data['hoursOnRecord'] || '').delete(',').to_f
#recent_playtimes[app_id] = (recent * 60).to_i
#total_playtimes[app_id] = (total * 60).to_i
end
true
end
with the particular problem statement being games_data['games']['game'].each
If we were looking to get information for a particular user, it downloads an XML document about the user from a URL looking like:
http://steamcommunity.com/id/demomenz?xml=1
and this file does not seem to contain any games objects in it.
Having looked at the codebase for the steam-condenser gem; it hasn't really been updated in about 6 years. I can only assume that the XML format has been modified since this time and that the gem will no longer work.
Valve has added more privacy options to Steam Community profiles which are not reflected in the old XML APIs.
Apparently, the profile in question (tiger) has it‘s game details set to “Friends Only” or ”Private” as games are also unavailable in the browser.
The code from the released 1.x versions is no longer guaranteed to work when it comes to Steam Community. Valve deprecated the old XML APIs several years ago. Sadly, the modern Web API hasn‘t gotten much attention from Valve‘s side either. So development of Steam Condenser has mostly come to halt, too.
You might have more luck using the code from the master branch of the GitHub repository which uses Web API for most of the Community features.
You will have to register for a Steam Web API key, though: https://steamcommunity.com/dev/apikey
After upgrading the rgeo gem from 0.6.0 to 2.1.1, we've started to get 'LinearRing failed ring test' on certain geometries that never caused us problems before. (The geometry data is generated from external sources outside of our control, and stored in PostGIS table.)
rgeo initializer:
GEO_FACTORY = RGeo::Geographic.simple_mercator_factory
PROJECTION_FACTORY = GEO_FACTORY.projection_factory
RGeo::ActiveRecord::SpatialFactoryStore.instance.tap do |config|
config.default = PROJECTION_FACTORY
end
Example code:
district = District.first
# Convert projected geometry to geographic geometry
geographic_geometry = GEO_FACTORY.unproject(district.geometry)
RGeo::Error::InvalidGeometry: LinearRing failed ring test
I also tried initializing the factory with the following options, but the errors persisted:
FACTORY = RGeo::Geographic.simple_mercator_factory(uses_lenient_assertions:true)
FACTORY = RGeo::Geographic.simple_mercator_factory(lenient_multi_polygon_assertions:true)
I've inspected some of these geometries where that are failing the LinearRing test, and it appears they are failing for a variety of reasons. Some possibly violate ring winding order, while with others I couldn't perceive the exact problem. But the point is, these are all geometries that we were able to work with before, and now are raising errors. I'd like to understand how we can return to the more lenient mode.
NOTES:
This is only happening on my Macbook (GEOS version 3.8.0), but not on our Linux production server (GEOS version 3.5.0)
REFERENCES:
https://github.com/rgeo/rgeo/issues/194
https://github.com/rgeo/rgeo-geojson/issues/33
This doesn't appear to be an issue with the rgeo gem but rather the underlying geos library on your mac.
There appears to be a difference in the way that geos 3.8.x (3.8.1 is the latest version in Homebrew circa 4/13/2020) and earlier versions of the geos library handle the is_simple calculation that determines Polygon validity. This affects any RGeo factory (most of them but not RGeo::Geographic.spherical_factory or RGeo::Cartesian.simple_factory) backed by the CAPI.
If you download version 3.5.x of geos from https://trac.osgeo.org/geos/ and build it with cmake (takes a while but installs cleanly) you should have consistent behavior between your production and local development environments.
If you were using the simple_mercator factory I doubt that differences in how spherical coordinates (implemented in pure ruby) are validated explain the differences in behavior that you see.
See this issue: https://github.com/rgeo/rgeo/issues/218
You most probably encountered this [1] bug. Reproducing needs Mac OS and shows the error you have:
RGeo::Error::InvalidGeometry (LinearRing failed ring test)
Issue is linked to pull request [2], which found the issue on Float vs BigDecimal difference. Somehow Floats are not so precise, when there are enough decimals included.
Side note: Pull request is only 26 days old, so it is still open, thus you'll need to build it from branch for the moment.
Source:
[1] https://github.com/rgeo/rgeo/issues/212
[2] https://github.com/rgeo/rgeo/pull/213
I'm using RSpec framework with capybara + eyes_selenium for visual testing, and i want to integrate mobile visual testing. i installed the appium_capybara, and it works with a remote appium server that functions as a node in my remote selenium hub.
So far it works great, I've managed to login to my iOs simulator and interact with the page. The problem is integrating this whole thing with applitools.
i'm using the gem eyes_selenium, but i can't seem to perform Eyes.open with my Appium::Capybara::Driver object, getting an exception that this driver is Unknown.
Eyes.open(app_name: 'Applitools', test_name: test_name, viewport_size: viewport_size, driver: Capybara.page.driver)
anyone managed to make it work ?
Looking at the source for the eyes_selenium gem, the only place that error can come from is from the eyes_driver method - https://github.com/applitools/eyes.sdk.ruby/blob/master/lib/applitools/selenium/eyes.rb#L39 - which is implemented as below
def eyes_driver(driver, eyes = nil)
if driver.respond_to? :driver_for_eyes
driver.driver_for_eyes eyes
elsif defined?(::Capybara::Poltergeist) && (driver.is_a? ::Capybara::Poltergeist::Driver)
Applitools::Poltergeist::Driver.new(eyes, driver: driver)
else
unless driver.is_a?(Applitools::Selenium::Driver)
Applitools::EyesLogger.warn("Unrecognized driver type: (#{driver.class.name})!")
is_mobile_device = driver.respond_to?(:capabilities) && driver.capabilities['platformName']
Applitools::Selenium::Driver.new(eyes, driver: driver, is_mobile_device: is_mobile_device)
end
raise Applitools::EyesError.new "Unknown driver #{driver}!"
end
end
At a first glance the else section of that looks fully broken to me (why create a new instance of Applitools::Selenium::Driver just to then raise an error?). However, that leaves only a few possibilities for why it's not working for you,
Appium::Capybara::Driver is not a driver type supported by the eyes_selenium gem
You're not requiring the files needed to patch Appium::Capybara::Driver to be supported, such as 'applitools/capybara', although after a quick look through the eyes_selenium code I don't think it adds the driver_for_eyes method to any ancestor class of Appium::Capybara::Driver (does patch Appium::Driver though) so #1 is probably more likely.
I've installed super_exception_notifier by running:
sudo gem install super_exception_notifier
and then I've tried enabling it in my project (which already has mailing working, since it sends emails for other purposes) like this. On environment.rb I added
# Notification configuration
require 'exception_notifier'
ExceptionNotifier.configure_exception_notifier do |config|
config[:exception_recipients] = %w(info#isitsciencefiction.com)
config[:notify_error_codes] = %W( 404 405 500 503 )
end
and on my application_controller.rb I have:
require 'exception_notifiable'
class ApplicationController < ActionController::Base
include ExceptionNotifiable
Am I missing something? because no matter what error I generate. Either a 404, a route error, division by zero in a controller or in the console, in development or production mode, I get no emails and no error messages or anything at all.
Any ideas?
Pablo,
Thanks for pointing out the holes in the documentation. I will setup a blank rails project and then clearly enumerate the steps. I have already updated the Readme in response to the tickets you created on github.
To help with you immediate problem this is how I have it setup, (and it works for me! :)
Not all parts of this are essential to it working, but I'm not editing it (much), so you can see what I have:
I have this in my environment.rb:
config.load_paths += %W( #{RAILS_ROOT}/app/middlewares #{RAILS_ROOT}/app/mixins #{RAILS_ROOT}/app/classes #{RAILS_ROOT}/app/mailers #{RAILS_ROOT}/app/observers )
I have an initializer in config/initializers/super_exception_notification.rb
#The constants ($) are set in the config/environments files.
ExceptionNotifier.configure_exception_notifier do |config|
config[:render_only] = false
config[:skip_local_notification] = false
config[:view_path] = 'app/views/errors'
config[:exception_recipients] = $ERROR_MAIL_RECIPIENTS
config[:send_email_error_codes] = $ERROR_STATUS_SEND_EMAIL
#config[:sender_address] = %("RINO #{(defined?(Rails) ? Rails.env : RAILS_ENV).humanize} Error" )
config[:sender_address] = "errors#swankywebdesign.com"
config[:email_prefix] = "[RINO #{(defined?(Rails) ? Rails.env : RAILS_ENV).capitalize} ERROR] "
end
Then in my application.rb I have this:
include ExceptionNotifiable, CustomEnvironments
alias :rescue_action_locally :rescue_action_in_public if Environments.local_environments.include?(Rails.env)
self.error_layout = 'errors'
self.exception_notifiable_verbose = false
self.exception_notifiable_silent_exceptions = [MethodDisabled]
Then I also have this mixin in my app/mixins directory:
module CustomEnvironments
module Environments
def self.local_environments
%w( development test )
end
def self.deployed_environments
%w( production staging )
end
end
end
One other thing, this plugin does not abolish the rails standard which is that things in public are trump. So if you have 404.html in public, it will always get rendered for 404's.
Peter
Maybe it has has something to do with this:
http://github.com/pboling/exception_notification
Email notifications will only occur when the IP address is determined not to be local. You can specify certain addresses to always be local so that you’ll get a detailed error instead of the generic error page. You do this in your controller (or even per-controller).
consider_local "64.72.18.143", "14.17.21.25"
You can specify subnet masks as well, so that all matching addresses are considered local:
consider_local "64.72.18.143/24"
The address "127.0.0.1" is always considered local. If you want to completely reset the list of all addresses (for instance, if you wanted "127.0.0.1" to NOT be considered local), you can simply do, somewhere in your controller:
local_addresses.clear