Run ruby ​​script in rails application

This might be a dumb question, but I'm just wondering where, or if it can run a ruby ​​script that is not related to the rails application, I would like it to start. To clarify, I am working on a test automation package, which is written mainly in bash, but I want to create an interface (my rails application) that allows other users to run automated tests not from the command line. Therefore, I assume that basically I want the user to select certain parameters from the fields of the database or form, then transfer these parameters and pass them to the ruby ​​script, which causes my bash script automation. Hope this is clear. Thank!

+3
source share
4 answers

If you want to call a script from a rails application, it becomes complicated. You want to use a background task or some order to complete these tasks, because they are blocking the server, and your users will wait for the call and download results to complete, which will most likely lead to a timeout.

See delayed_job and you can try creating a small ruby ​​script wrapper that can interact with your application.

Good luck

+2
source

for short tasks you should use systemorpopen

when there are more tasks than they need, in the case of delayed_job

+2
source

script . script :

script [name here].rb

, , , script:

#!/bin/env ruby

ENV['RAILS_ENV'] = "production" # Set to your desired Rails environment name
require '/[path to your rails app on your server]/config/environment.rb'
require 'active_record'

, crontab . ( , ). , , , .

+1

Ruby- rails runner.

... , "". Report generate_rankings,

$ rails runner 'Report.generate_rankings'

Rails, Active Record .

$ rails runner 'User.pluck(:email).each { |e| puts e }'
charles.quinn@highgroove.com
me@seebq.com
bill.gates@microsoft.com
obie@obiefernandet.com

Example taken from The Rails 5 Way by Obie Fernandez .

0
source

All Articles