vendredi 14 février 2020

Frequently polls happening from delayed job

Hi I am using delayed job active record gem in my production application with Postgres, a lot of background jobs are working through the delayed job

One thing I have noticed in the output of pg:outliers in our production database, the prop_exec_time is 4.5% for this query and almost 1.8 million calls happened in 45 hours.

Query:

UPDATE "delayed_jobs" SET locked_at = $1, locked_by = $2 WHERE id IN (SELECT id FROM "delayed_jobs" WHERE ((run_at <= $3 AND (locked_at IS NULL OR locked_at < $4) OR locked_by = $5) AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT $6 FOR UPDATE) RETURNING *

As per the delayed job, the polls happen every 5 seconds by default, but this happens even if there is no job to perform. Currently, there is no extra configuration in our app.

I guess I can override the default time of delayed_job, will this make any impact? Any kind of suggestion to reduce the calls

mardi 11 février 2020

Rails: Form helper how to convert this dropdown select into a radio button list

Ok....sigh. I have inherited this code (Rails 2.3.14) and I have been banging my head trying to figure out how to pull this off. I have this form_for that contains a dropdown select "g.select" that I need to be a list of checkboxes instead. How can this be done?

Here is the current code...

                <% form_for :attendance, nil, :url => {:action => "doattendance", :id => skedj.current.id}, :loading => "$(#{ loading_indicator_id("attendance_assignment_form").to_json }).show();" do |g| %>
                  <%#= g.label :attendance_type_id %>
                  <% t = Time.now.to_i%>
                  <%= g.select("attendance_type_id",
                               AttendanceType.find(:all).sort_by(&:id).collect {|p| [ p.name, p.id ] },
                               {:include_blank => true, :selected => skedj.current.attendance_type_id},
                               :id => "attendance_attendance_type_id_#{t}") %>
<!--                  TODO: convert to Radio Buttons?-->
                  <br />

               ????? <---- Radio Button code here

                  <br />

                  <%= g.submit "Save" %>
                  <%= loading_indicator_tag("attendance_assignment_form") %>
                <% end %>
              </div>

Any help appreciated

jeudi 6 février 2020

I cant execute rails server

When i run $rails s or $rails server it returns an error.

I looked for solutions but I didn't understand. I installed RVM, Ruby and Rails several times but I always get this error

I already executed the command $bundle install but it didn't work This is the error:

    25: from /Users/joel.alayon/.rvm/gems/ruby-2.6.3/gems/railties-6.0.2.1/lib/rails/application.rb:363:in `initialize!'
    24: from /Users/joel.alayon/.rvm/gems/ruby-2.6.3/gems/railties-6.0.2.1/lib/rails/initializable.rb:60:in `run_initializers'
    23: from /Users/joel.alayon/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:205:in `tsort_each'
    22: from /Users/joel.alayon/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:226:in `tsort_each'
    21: from /Users/joel.alayon/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:347:in `each_strongly_connected_component'
    20: from /Users/joel.alayon/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:347:in `call'
    19: from /Users/joel.alayon/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:347:in `each'
    18: from /Users/joel.alayon/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:349:in `block in each_strongly_connected_component'
    17: from /Users/joel.alayon/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:431:in `each_strongly_connected_component_from'
    16: from /Users/joel.alayon/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
    15: from /Users/joel.alayon/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:228:in `block in tsort_each'
    14: from /Users/joel.alayon/.rvm/gems/ruby-2.6.3/gems/railties-6.0.2.1/lib/rails/initializable.rb:61:in `block in run_initializers'
    13: from /Users/joel.alayon/.rvm/gems/ruby-2.6.3/gems/railties-6.0.2.1/lib/rails/initializable.rb:32:in `run'
    12: from /Users/joel.alayon/.rvm/gems/ruby-2.6.3/gems/railties-6.0.2.1/lib/rails/initializable.rb:32:in `instance_exec'
    11: from /Users/joel.alayon/.rvm/gems/ruby-2.6.3/gems/webpacker-4.2.2/lib/webpacker/railtie.rb:84:in `block in <class:Engine>'
    10: from /Users/joel.alayon/.rvm/gems/ruby-2.6.3/gems/webpacker-4.2.2/lib/webpacker.rb:35:in `bootstrap'
     9: from /Users/joel.alayon/.rvm/gems/ruby-2.6.3/gems/webpacker-4.2.2/lib/webpacker/commands.rb:25:in `bootstrap'
     8: from /Users/joel.alayon/.rvm/gems/ruby-2.6.3/gems/webpacker-4.2.2/lib/webpacker/manifest.rb:18:in `refresh'
     7: from /Users/joel.alayon/.rvm/gems/ruby-2.6.3/gems/webpacker-4.2.2/lib/webpacker/manifest.rb:83:in `load'
     6: from /Users/joel.alayon/.rvm/gems/ruby-2.6.3/gems/webpacker-4.2.2/lib/webpacker/configuration.rb:51:in `public_manifest_path'
     5: from /Users/joel.alayon/.rvm/gems/ruby-2.6.3/gems/webpacker-4.2.2/lib/webpacker/configuration.rb:47:in `public_output_path'
     4: from /Users/joel.alayon/.rvm/gems/ruby-2.6.3/gems/webpacker-4.2.2/lib/webpacker/configuration.rb:43:in `public_path'
     3: from /Users/joel.alayon/.rvm/gems/ruby-2.6.3/gems/webpacker-4.2.2/lib/webpacker/configuration.rb:84:in `fetch'
     2: from /Users/joel.alayon/.rvm/gems/ruby-2.6.3/gems/webpacker-4.2.2/lib/webpacker/configuration.rb:88:in `data'
     1: from /Users/joel.alayon/.rvm/gems/ruby-2.6.3/gems/webpacker-4.2.2/lib/webpacker/configuration.rb:91:in `load'
/Users/joel.alayon/.rvm/gems/ruby-2.6.3/gems/webpacker-4.2.2/lib/webpacker/configuration.rb:95:in `rescue in load': Webpacker configuration file not found /Users/joel.alayon/Desktop/blog/config/webpacker.yml. Please run rails webpacker:install Error: No such file or directory @ rb_sysopen - /Users/joel.alayon/Desktop/blog/config/webpacker.yml (RuntimeError)

The error is longer, but I can't put everything, it is an example

mercredi 5 février 2020

Deploy to Engine Yard failing: 'key not found: :ciphers'

I can't deploy using the ey command:

$ ey deploy -e myapp
Loading application data from Engine Yard Cloud...
key not found: :ciphers
engineyard version 3.2.5
ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-darwin18]

I think this has something to do with ssl. Ruby 2.5.3 was installed with rbenv and is using openssl 1.1.1 (I think I remember seeing that) though not sure how to find this after actual install...

lundi 3 février 2020

nested array ruby TypeError: no implicit conversion of Hash into Integer

def get_att(webinar_id)
  finalArray = []
    api_service = ApiService.new
    response = api_service.get_attendees(webinar_id)
    json = JSON.parse(response.body)

  for x in json['_embedded']['attendeeParticipationResponses']
    first_name = json['_embedded']['attendeeParticipationResponses'][x]['firstName']
    last_name = json['_embedded']['attendeeParticipationResponses'][x]['lastName']
    email = json['_embedded']['attendeeParticipationResponses'][x]['email']
    finalArray << [first_name, last_name, email]
  end

  # x = 2
  # first_name = json['_embedded']['attendeeParticipationResponses'][x]['firstName']
  # last_name = json['_embedded']['attendeeParticipationResponses'][x]['lastName']
  # email = json['_embedded']['attendeeParticipationResponses'][x]['email']
  # finalArray << [first_name, last_name, email]

    Rails.logger.info(finalArray)
end

This is the method (sorry the indenting is weird when pasted into stack overflow, but its normal in actual code). The idea is to return an array of arrays with all of the people and their 3 tags. I know that the JSON parse data is working because the commented out code works perfectly and I can change x assignment and it runs. The for loop also works because it counts 15 responses in json['_embedded']['attendeeParticipationResponses'] when I add a counter. So I know the 15 people are there and I can add them one by one into the final array (which I got to hold multiple arrays by the way), but for some reason the second I put it in the for loop I get the weird error which fully reads:

TypeError: no implicit conversion of Hash into Integer from /Users/josh/Documents/GitHub/schools_health/lib/go_to_webinar/to_pipeline.rb:19:in `[]'

Server Failed to Process Image

[![enter image description here][1]][1]

[1]: https://i.stack.imgur.Anyone know how to fix this error? I am using solidus to build an e-commerce websitecom/Tq6tF.png

LIKE statement but skips current post

I'm trying to use the LIKE condition to find similar posts.

Here is my code:

    @post = Post.find(params[:id])

    @post_gsub = Post.find(params[:id]).name.gsub(/something|something else|something else again/, '')

    @related_posts = Post.where("name LIKE '%#{@post_gsub}%'")

But when I pull this into the Rails view, there is currently always one match that shows up, which is the current blog post the user is on. How do I skip that current blog post so that "@related_posts" is only showing unique recommendations and not the post the user is currently on?