jeudi 21 septembre 2023

i want to see server log file from browser in rails app button click

i have a make a deployment app , by clicking deployment button it deployed, now i want to see the log file like terminal show in browser

i try to read the log file using file read but when i start to read my application stop with this

Rendering deployments/show_log.html.erb within layouts/application
/home/syftet/.rvm/gems/ruby-3.0.0/gems/activesupport-7.0.5/lib/active_support/core_ext/string/output_safety.rb:350: [BUG] Segmentation fault at 0x00007f46a87f1000
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]

-- Control frame information -----------------------------------------------
c:0123 p:---- s:0827 e:000826 CFUNC  :escapeHTML
c:0122 p:0036 s:0822 e:000821 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/activesupport-7.0.5/lib/active_support/core_ext/string/output_safety.rb:350
c:0121 p:0012 s:0814 e:000812 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/activesupport-7.0.5/lib/active_support/core_ext/string/output_safety.rb:216
c:0120 p:0016 s:0808 e:000807 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionview-7.0.5/lib/action_view/buffers.rb:29
c:0119 p:0022 s:0803 e:000802 METHOD /home/syftet/development/trusteeze-saas/app/views/deployments/show_log.html.erb:2 [FINISH]
c:0118 p:---- s:0797 e:000796 CFUNC  :public_send
c:0117 p:0042 s:0790 e:000789 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionview-7.0.5/lib/action_view/base.rb:244
c:0116 p:0025 s:0776 e:000775 BLOCK  /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionview-7.0.5/lib/action_view/template.rb:157
c:0115 p:0034 s:0773 e:000772 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/activesupport-7.0.5/lib/active_support/notifications.rb:208
c:0114 p:0024 s:0767 e:000766 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionview-7.0.5/lib/action_view/template.rb:361
c:0113 p:0021 s:0762 e:000761 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionview-7.0.5/lib/action_view/template.rb:155
c:0112 p:0013 s:0751 e:000750 BLOCK  /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionview-7.0.5/lib/action_view/renderer/template_renderer.rb:65
c:0111 p:0010 s:0748 e:000747 BLOCK  /home/syftet/.rvm/gems/ruby-3.0.0/gems/activesupport-7.0.5/lib/active_support/notifications.rb:206
c:0110 p:0022 s:0745 e:000744 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/activesupport-7.0.5/lib/active_support/notifications/instrumenter.rb:24
c:0109 p:0023 s:0737 e:000736 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/activesupport-7.0.5/lib/active_support/notifications.rb:206
c:0108 p:0033 s:0731 e:000730 BLOCK  /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionview-7.0.5/lib/action_view/renderer/template_renderer.rb:60
c:0107 p:0011 s:0727 e:000724 BLOCK  /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionview-7.0.5/lib/action_view/renderer/template_renderer.rb:75
c:0106 p:0010 s:0722 e:000721 BLOCK  /home/syftet/.rvm/gems/ruby-3.0.0/gems/activesupport-7.0.5/lib/active_support/notifications.rb:206
c:0105 p:0022 s:0719 e:000718 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/activesupport-7.0.5/lib/active_support/notifications/instrumenter.rb:24
c:0104 p:0023 s:0711 e:000710 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/activesupport-7.0.5/lib/active_support/notifications.rb:206
c:0103 p:0050 s:0705 e:000704 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionview-7.0.5/lib/action_view/renderer/template_renderer.rb:74
c:0102 p:0012 s:0695 e:000694 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionview-7.0.5/lib/action_view/renderer/template_renderer.rb:59
c:0101 p:0048 s:0687 e:000686 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionview-7.0.5/lib/action_view/renderer/template_renderer.rb:11
c:0100 p:0020 s:0680 e:000679 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionview-7.0.5/lib/action_view/renderer/renderer.rb:61
c:0099 p:0023 s:0674 e:000673 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionview-7.0.5/lib/action_view/renderer/renderer.rb:29
c:0098 p:0009 s:0668 e:000667 BLOCK  /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionview-7.0.5/lib/action_view/rendering.rb:117
c:0097 p:0089 s:0664 e:000663 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionview-7.0.5/lib/action_view/base.rb:270
c:0096 p:0051 s:0656 e:000655 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionview-7.0.5/lib/action_view/rendering.rb:116
c:0095 p:0044 s:0646 e:000645 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionpack-7.0.5/lib/action_controller/metal/streaming.rb:216
c:0094 p:0015 s:0641 e:000640 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionview-7.0.5/lib/action_view/rendering.rb:103
c:0093 p:0010 s:0636 e:000635 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionpack-7.0.5/lib/action_controller/metal/rendering.rb:158
c:0092 p:0015 s:0631 e:000630 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionpack-7.0.5/lib/action_controller/metal/renderers.rb:141
c:0091 p:0018 s:0626 e:000625 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionpack-7.0.5/lib/abstract_controller/rendering.rb:27
c:0090 p:0033 s:0618 e:000617 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionpack-7.0.5/lib/action_controller/metal/rendering.rb:139
c:0089 p:0010 s:0613 e:000612 BLOCK  /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionpack-7.0.5/lib/action_controller/metal/instrumentation.rb:22
c:0088 p:0028 s:0610 e:000609 METHOD /home/syftet/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/benchmark.rb:308
c:0087 p:0009 s:0605 e:000603 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/activesupport-7.0.5/lib/active_support/core_ext/benchmark.rb:14
c:0086 p:0013 s:0599 e:000598 BLOCK  /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionpack-7.0.5/lib/action_controller/metal/instrumentation.rb:22
c:0085 p:0002 s:0596 e:000595 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionpack-7.0.5/lib/action_controller/metal/instrumentation.rb:91
c:0084 p:0066 s:0592 e:000591 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/activerecord-7.0.5/lib/active_record/railties/controller_runtime.rb:34
c:0083 p:0008 s:0585 e:000583 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionpack-7.0.5/lib/action_controller/metal/instrumentation.rb:21
c:0082 p:0021 s:0578 e:000577 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionpack-7.0.5/lib/action_controller/metal/implicit_render.rb:35
c:0081 p:0020 s:0573 e:000572 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionpack-7.0.5/lib/action_controller/metal/basic_implicit_render.rb:7
c:0080 p:0011 s:0566 e:000565 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionpack-7.0.5/lib/abstract_controller/base.rb:215
c:0079 p:0022 s:0560 e:000559 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionpack-7.0.5/lib/action_controller/metal/rendering.rb:165
c:0078 p:0009 s:0555 e:000554 BLOCK  /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionpack-7.0.5/lib/abstract_controller/callbacks.rb:234
c:0077 p:0048 s:0552 E:002550 BLOCK  /home/syftet/.rvm/gems/ruby-3.0.0/gems/activesupport-7.0.5/lib/active_support/callbacks.rb:118
c:0076 p:0013 s:0542 E:002590 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actiontext-7.0.5/lib/action_text/rendering.rb:20
c:0075 p:0021 s:0536 E:0025d0 BLOCK  /home/syftet/.rvm/gems/ruby-3.0.0/gems/actiontext-7.0.5/lib/action_text/engine.rb:69 [FINISH]
c:0074 p:---- s:0531 e:000530 CFUNC  :instance_exec

mardi 19 septembre 2023

Insert many json file inside one document in mongoDB

i have a question: but how can i insert many json files inside one document collection? I have a ruby script connected with mongoDB which generate json files for each ID product. In mongo i should want a structure like this:

Id(document's name) : {

many json for same ID

} 

how can i get this structure in ruby?

DB's name is "test_db" and collection's name is "test_coll"

mardi 12 septembre 2023

URI Error with RUBY when trying to run an application

so for some reason my ruby encounter this error when I try to create a new application on Windows 10:

rails aborted! URI::InvalidURIError: bad URI(is not URI?): C:\Ruby\bin;C:\sqlite; C:/Users/Lies/demo42/Rakefile:6:in <main>' <internal:C:/Ruby/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in require' <internal:C:/Ruby/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in require' bin/rails:4:in <main>' (See full trace by running task with --trace) rails turbo:install stimulus:install rails aborted! URI::InvalidURIError: bad URI(is not URI?): C:\Ruby\bin;C:\sqlite; C:/Users/Lies/demo42/Rakefile:6:in <main>' <internal:C:/Ruby/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in require' <internal:C:/Ruby/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in require' bin/rails:4:in <main>' (See full trace by running task with --trace)

I've searched everywhere on Google and so far I've try reinstalling twice, changing the path varible to C:\ruby and adding it to path and DATABASE variable.

My ruby, rails is on the latest version.

So far running "rails new demo --minimal" is the only one that work in helping me creating the application but when I try to run the server it show this: localhost:3000 output

Has anyone encountered this and figure out how to fix? I asked my professor, and it also picked his brain trying to figure out.

Thank you!

jeudi 7 septembre 2023

Ruby on Rails - Double Render Error - Redirect and Return

Error: AbstractController::DoubleRenderError (Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like "redirect_to(...) and return".)

On update, model checks for template.exists?, if true, download the report AND redirect to parent object. Else, just redirect.

I'm using 'and return' on the tangential side of the 'if' statement, so why isn't that working as expected?

def update
  template = resource.check_changes(params[:well_master])
  paramString = resource.to_json

  update! do |format|
    if resource.errors.present?
      return render :edit
    else
      if template != ''
        generateWellLetter(template, 'Rpt_Farm_Name', paramString) 
      else
        rec = resource.PERMIT
        format.html { redirect_to admin_well_master_path(rec) }
      end
    end
  end
 end
end

def generateWellLetter(template, letterName, params)
    @URL = "#{ENV["API_HOST"]}/api/Document/Generate/#{template}"
    response = HTTParty.post(@URL,
                             :body => params,
                             :headers => { "Content-Type" => "application/json" })

Zip::InputStream.open(StringIO.new(response)) do |io|
  while entry = io.get_next_entry
    report = io.read
    send_data report, :filename => letterName + '.docx', :type => 'docx'
  end
end

respond_to do |format|
  rec = resource.PERMIT
  format.html { redirect_to admin_well_master_path(rec) } and return
end

end

mercredi 6 septembre 2023

Ruby 1.8.7 on Rails 2.3.5 application rendering speed slows down overtime

Previously, the application worked on a shared hosting without a docker container and the performance was good. After transferring to a dedicated server, the application was made through a docker container and a performance problem appeared. The developer assured that there was a problem with the old Ruby, but if before everything worked within the normal range, now the application restarts every 6 hours trough cron (docker-compose down) to maintain normal speed. Application handles concurrency poorly.

The main problem is that initial rendering speed is:

Processing CatalogController#index (for 127.0.0.1 at 2023-09-06 19:22:06) [GET] Parameters: {"controller"=>"catalog", "language"=>"ru", "action"=>"index"} Rendering template within layouts/main Rendering catalog/index Completed in 330ms (View: 300, DB: 30) | 200 OK [http://localhost/]

Than after 300 requests it slows to:

Processing CatalogController#index (for 127.0.0.1 at 2023-09-06 19:22:06) [GET] Parameters: {"controller"=>"catalog", "language"=>"ru", "action"=>"index"} Rendering template within layouts/main Rendering catalog/index Completed in 1266ms (View: 1233, DB: 37) | 200 OK [http://localhost/]

When I try to use ab -n 100 http://localhost:3000/ it shows result like:

Concurrency Level:      1
Time taken for tests:   33.883 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      6796500 bytes
HTML transferred:       6764800 bytes
Requests per second:    2.95 [#/sec] (mean)
Time per request:       338.831 [ms] (mean)
Time per request:       338.831 [ms] (mean, across all concurrent requests)
Transfer rate:          195.89 [Kbytes/sec] received

Code in Dockerfile that builds application:

FROM centos:7
SHELL ["/bin/bash", "-c"] 

RUN yum update -y && yum -y install gpg curl which wget ImageMagick-devel mysql mysql-devel libxml2-devel libxslt libxslt-devel

#Install RVM
RUN gpg --keyserver keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
RUN \curl -sSL https://get.rvm.io | bash -s stable

#Install Ruby
RUN source /etc/profile.d/rvm.sh && rvm install 1.8.7

#Install Ruby Gems
RUN source /etc/profile.d/rvm.sh && rvm use 1.8.7 && gem install -v=2.3.5 rails && gem install bundler -v=1.3.5 && gem install rubygems-update -v 1.3.7 && update_rubygems --version=1.3.7 && gem install mime-types -v=1.17.2 && gem install russian -v=0.2.7 && gem install httparty -v=0.7.2 && gem install mini_mime -v=1.1.2 && gem install yandex_inflect -v=0.1.0 && PATH="/app/ImageMagick-6.8.0-10/Magick++/bin:$PATH" gem install rmagick -v=2.13.2 && gem install mechanize -v=0.8.5 && gem install geoip -v 1.1.2 && gem install rdoc -v=3.9.2 && gem install mysql -v=2.9.1 && gem install nokogiri -v=1.4.4 && gem install daemons -v=1.1.0 && gem install thin -v=1.7.0

WORKDIR /app

RUN mkdir /app/tmp

CMD source /etc/profile.d/rvm.sh && rvm use 1.8.7 && script/server thin -p 3000 -e production

Maybe someone knows what can cause such a behavior?

I have tried to install thin server instead of a WebBrick but it didn't resolve the problem. And only solution for now is docker-compose down command but it restarts application entirely for almost 16 seconds. Lookes through a code and didn't find code that can slow down the application.

Possible solutions to the problem:

  1. Correctly configure the docker container (the application did not work on docker before, so the problem may be in its settings)
  2. Install unicorn or passenger (it worked on webrick during the transfer, then transferred to thin, but it didn't help much)
  3. Install some additional gems (before, more gems were installed on the hosting, but now only the most necessary ones).
  4. It is necessary to transfer the application to a new version of Ruby on Rails (if there is no other way out, then you have to do it)

lundi 4 septembre 2023

Move static asset folder of rails application to S3 Bucket

i want to cdn my static asset of rails application,i have gone through the AWS documentation for it and have created my distribution also now i want to ask how i can move my static asset folder to S3 bucket so that i can cdn them? I am following this link for it text