ruby

Basic Sidekiq Questions about Idempotency and functions

╄→尐↘猪︶ㄣ 提交于 2021-01-29 12:03:38
问题 I'm using Sidekiq to perform some heavy processing in the background. I looked online but couldn't find the answers to the following questions. I am using: Class.delay.use_method(listing_id) And then, inside the class, I have a self.use_method(listing_id) listing = Listing.find_by_id listing_id UserMailer.send_mail(listing) Class.call_example_function() Two questions: How do I make this function idempotent for the UserMailer sendmail? In other words, in case the delayed method runs twice, how

Saving a json file on Heroku

╄→гoц情女王★ 提交于 2021-01-29 11:44:55
问题 I have a simple sinatra app on Heroku which fetches some json data and is then fetched again and rewritten every 10 minutes, what would be the easiest way to save the json data? Should I use S3 or mongodb or is there a simpler option? 回答1: I think writing into a database (mongodb or other) would be your best bet. It's simplest to set up on Heroku. 回答2: I think the easiest route is to save your json using Heroku's free 5mb memcached plugin (use the dalli gem), This link describes setting up a

Ruby on rails + jquery - how to use

Deadly 提交于 2021-01-29 11:05:04
问题 I am just learing and i've come across a problem. I'd like burger icon to work, but it doesn't work. ----> https://getbootstrap.com/docs/4.5/examples/album/# It doesn't collapse. I add gem 'jquery-rails' to gemfile and then type bundle update it installed jquery Fetching jquery-rails 4.4.0 Installing jquery-rails 4.4.0 then i added <%= stylesheet_link_tag 'application', media: 'all' %> <%= javascript_include_tag 'application' %> to the application.html.erb and the script below <script src=

Can I prepend to derived classes from base class?

故事扮演 提交于 2021-01-29 10:54:24
问题 I want prepend module to all derived classes. But boring that writes prepend GenericFooException to all files. (gloomy tone.) How to easy way to write? module GenericFooException class FooException < StandardError; end def perform super rescue FooException => e # The truth is that rails ActiveRecord::ActiveRecordError with .cause puts "[CATCH] #{e.class}" end end module Foo class Base prepend GenericFooException def perform raise RuntimeError end end end # It is my best. but can not catch the

Rails - Singleton class troubles with rspec feature

跟風遠走 提交于 2021-01-29 10:32:36
问题 I have a problem testing a functionality that depends of a Singleton class. That class (ERPDao) is a suite with diferent methods that helps application to connect with external ERP vía REST services using Faraday gem. URLMaker is a helper class for build requests strings. When i try to run a feature spec that depends of one of this methods i have the following message in rspec: Failure/Error: result = ERPDao.instance.get_credit_info(erp_id) NoMethodError: undefined method `instance' for

Finding data trendlines with Ruby?

久未见 提交于 2021-01-29 10:31:21
问题 I have a dataset with user session numbers from my site which looks like: page_1 = [4,2,4,1,2,6,3,2,1,6,2,7,0,0,0] page_2 = [6,3,2,3,5,7,9,3,1,6,1,6,2,7,8] ... And so on. I would like to find out whether the page has a positive or negative trendline in terms of growth, however I would also like to get the pages that are growing/falling beyond a certain threshold. Python has a ton of solutions and libs for this kind of task, yet Ruby has only one gem (trendline) which has no code in it. Before

Why can Ruby not parse local JSON file?

帅比萌擦擦* 提交于 2021-01-29 09:39:12
问题 I have a related question here, but I'm posting another question to focus on a specific part of the problem. Goal: Add script to my Ruby app which can read a local JSON file, parse it to a Ruby hash, and access the properties within it. System: CentOS 7 File: Locally saved /tmp/valid.json file: { "firstName": "John", "lastName": "Smith", "isAlive": true, "age": 27, "address": { "streetAddress": "21 2nd Street", "city": "New York", "state": "NY", "postalCode": "10021-3100" }, "phoneNumbers": [

Rails 5.2.1 - Model & Fragment Caching

和自甴很熟 提交于 2021-01-29 09:23:20
问题 I am trying to setup Model and Fragment Caching in Rails 5.2.1 I have had success with Fragment caching, but I am still seeing database queries after implementing model caching for my Model. I have enabled development caching $ rails dev:cache Model Helper module LanguagesHelper def approved_languages Rails.cache.fetch("approved_languages") { Languages.is_active.is_approved } end end Controller class LanguagesController < ApplicationController include LanguagesHelper def index @languages =

why rake tasks are not executing using and operator?

若如初见. 提交于 2021-01-29 09:21:33
问题 I have a rake task : task :kill_process do system %q(ps -ef | awk '{if($8~"java" || $8~"glassfish" || $8~"ruby" || $8~"god" || $8~"couch"){printf("Killing : %s \n",$2);{system("kill -9 "$2)};}}') end This is basically killing processes. And this task is a part of another rake task : desc "stop the entire system" task :stop => [...., :kill_process] There's another task: desc "start the entire system" task :start => [....] When I am doing rake stop && rake start stop task is executed

Pointer in Ruby

有些话、适合烂在心里 提交于 2021-01-29 09:20:28
问题 I just solved some tasks about linked lists using Ruby. It was very interesting, but it requires a couple of new lines. Because if I pass head in some function, and change the head of the list, I have to return new head from method and reassign it to the variable. Because if I have a variable and I pass it to method, reassign a inside, outside a dose not changes: it "dose not changes if reassign variable in method" do a = [1,2] def reasign array array = [1] array end assert_equal [1], reasign