Rails run rake:scheduler after start server - ruby-on-rails-3

I need to run a rake command after starting a rails server.
However, when I try to call system(rake reque:scheduler") in config.before_initialise,
the command appears to run in an infinate loop.
I've searched other sites for an answer, but I'm not finding it.

You don't want to start that process inside Rails. Take a look at Foreman: https://github.com/ddollar/foreman

Related

Adding a new Migration File using Rake (in the command line)

I know there's a way to automatically create the barebones of a migration file by entering some rake command in the command line but I can't seem to remember exactly what it is. I know it should look something like this...
rake db:create NAME=table_name
but that keeps failing. I also tried
rake db:create_migration NAME=table_name
but no luck with this either. The first attempt returns "Don't know how to build task 'table_name' and the second says "Don't know how to build task 'migration'
rake isn't the command for this, instead you can either:
manually create the file
run rails generate migration table_name in a rails app
or in my case where I'm not using rails, pliny-generate migration table_name

How to tell github action that the job had done successfully?

I use github action to deploy my website to my server. The last ssh cmd is npm run start. It will output ready - started server on http://localhost:4000(Since i use Nextjs) finally but it seems that github doesn't know what did it mean and print :
2021/01/09 14:24:14 Error: command timeout
err: Run Command Timeout!
Although the website is successfully deployed, it shows that the Github action failed to execute.
So how to tell github action that the job had done successfully?
You should find a way to start the application in a daemon process of its own, rather than as a process within the SSH session. Perhaps this tool (pm2) might solve your problem? This question and answer is somewhat related.
There are definitely other ways to start your app in a daemon process, or perhaps as a service, but this might be the most straightforward for you since it's a Node tool.

rake jobs:work Each time I start my server?

I am using delayed jobs, because I have some long running processes running in the background.
The annoying part is that I need to run 'rake jobs:work' before I start my application everytime.
Is there any way to let my Rails application know that I want it to start every time I restart my server? or refresh my homepage?
Is this on your local machine? If so, you could just set an alias that you could run that would run 'rake jobs:work' when you use the alias. For example:
alias startserver='rake jobs:work & rails s'

does Delayed_job daemon not run in development?

I'm using delayed_job and I am able to run jobs using rake jobs:work but using the daemonized version, it does nothing although I see it in the process list.
I'm using:
rails (3.0.9)
delayed_job (2.1.4)
daemons (1.0.10)
I'm running delayed_job using:
unix>RAILS_ENV=development script/delayed_job start
It could be a problem loading a custom job class file. To test that, try this:
Enter the rails console rails console --sandbox.
Make sure you have a job in the table job = Delayed::Job.first.
Try YAML.load(job.handler). If you get an error that looks like this: ArgumentError: undefined class/module MyCustomClass, it's probably a problem loading your custom job
Still in the rails console, run require 'My_Custom_Class. Then run the YAML.load(job.handler) command again. If this returns the appropriate object it's definitely a class loading problem.
To fix the problem create the file config/initializers/custom.rb and in it put require 'My_Custom_Class'.
You should then be able to run rake jobs::workoff and get something that looks like this:
[Worker(host:my.host pid:5085)] Starting job worker
[Worker(host:my.host pid:5085)] MyCustomJob completed after 0.0774
[Worker(host:my.host pid:5085)] 1 jobs processed at 9.1935 j/s, 0 failed ...
[Worker(host:my.host pid:5085)] No more jobs available. Exiting
To answer your question we may need more information.
Are jobs added to database? Are there any errors in jobs?
What's the result of RAILS_ENV=development script/delayed_job status as I already mentioned?
Second, did you went through the most common problems Wiki page?
https://github.com/collectiveidea/delayed_job/wiki/Common-problems

Rails. "unitialized Contsant Object::Contact"

I'm working through the Ruby on Rails Bible using Windows 7 and Rails 3 + mysql.
I created a database and a table in mysql directly as per instructions.
Then I created a model called Contact
Next in irb I entered:
my_contact=Contact.new and then I get the error:
"unitialized constant Object::Contact"
I think perhaps I have to precede the code with a require statement or perhaps I need to install a gem? Except I haven't a clue beyond that at this stage as I'm a newbie...
Instead of running irb manually, run rails console, this should load all dependencies for your app. Also make sure you have run rake db:migrate before starting the console.