Rails Dreamhost Cron Job - ruby-on-rails

I'm trying to get some cron jobs going through Dreamost using their panel. I'm also using rake to execute these jobs
My rake files are located in
app/lib/tasks/example.rake
But I don't know what code to give the panel to execute them

My recommendation would be to avoid trying to do that in the first place.
Editing cron jobs manually is a pain in the ass, and rails has some nice utilities to avoid it.
There's a railscast on using the wheneverize gem to prvent these problems.
http://asciicasts.com/episodes/164-cron-in-ruby
If you want these cron jobs to be automatically updated every time you deploy to dreamhost, just put it in as part of your Capistrano deploy.rb
If you're not using Capistrano, I strongly recommend you look into:
http://www.capify.org/index.php/Capistrano
EDIT
If you do want to take the DH cron route, the following should work
cd /full/path/to/your/project && rake example

if you're using rake, you could put
rake whatevertask
in the command field

Related

How to have Rails migrations run automatically on Heroku

I have more than 10 different Ruby on Rails apps where I have to deploy the same code. I have connected the git repo to my Heroku apps, so whenever I push new changes it deploys on all of them.
The issue is with the database migration step. I want to run migrations automatically after each deployment. None of custom build pack is working. Can someone please help me? I am using rails 4 and spree.
So far, I have tried:
https://github.com/heroku/heroku-buildpack-ruby.git
https://github.com/gunpowderlabs/buildpack-ruby-db-migrate.git
This solution is not working.
Is there any other solution to run Rails migrations on Heroku automatically?
No need to use gems or write scripts.
Heroku have a 'release' phase features (https://devcenter.heroku.com/articles/release-phase).
Thank to this, you just have to add to your Procfile some code to automatically run rake db:migrate to all your push :
Procfile (root app)
release: rake db:migrate
You can use Travis-ci. Pretty simple to setup and provides the desired functionality
Add gem 'iconv', '~> 1.0.3' to your gemfile and then try it will work as worked for me!
I take this as a duplicate of this answer
If you are looking for alternative then you can write a deploy script in .sh file and run it everytime like bash script.

What is the scope of rake in Rails

I am very new to ruby on rails. What is the function of rake. For example here one command like
rake db:create
Here this command which is used to create the new database. But before we use rake. Why we use rake word here, what it is function.
And what is the different between rake rake-task & rakefile.
Thanks for your advice.
Rake is a Ruby build command. When you invoke rake, you are actually using the Rake tool and you ask Rake to read and use the Rakefile available in your Rails application folder.
Rake is used to automate several tasks, from the creation of a database, to a database migration, to the generation of new models or controllers.
I encourage you to read this article about Rake to learn more about this tool. It will be one of the fundamental tools you'll use working with Rails, so you really need to understand what it is before moving forward.
Rake is a gem that acts like make in the *nix world. You use it to run scripts, usually the Rakefile. You use it to run tests or set up databases. Rails uses it extensively because there are many steps that need to be run between deployments.
Rake can do pretty much anything you need to automate.
There is a Wikipedia article on it that is a good starting point: http://en.wikipedia.org/wiki/Rake_(software)
The main thing it does, really, is to be a central point for command-line tasks for the application. You don't really need it for half the things it's used for (and quite frequently isn't the best IMO), but by running rake -D you'll get a list of all the commands available, which is helpful.

What is the logic behind tasks in Rake versus under `rails`

I try to grasp the logic behind some tasks being "rails" whereas others, the majority, is found as rake task. Why rails server and not rake server for example?
I can understand that the bootstrapping cannot be done in rake: after all, you first need a rakefile and other requirements before you can start using rake. So creating the project with a rails binary seems only practical.
But why generate, server, console, yet not migrate or assets? I don't see the logic. Is there any?
IMO the rails scripts are for "live" console usage, like during development.
The rake tasks are more "automated" tasks, for example, that might be run as part of a build or deploy cycle, like by a CI server. Some rake tasks might group rails/etc. commands together (like tests).
A rake script is a utility/build tool for some common tasks when developing. For example, you need to do deployment, run test, database stuffs, truncate log files, compile assets .... You can create your own custom rake scripts.
A rails script is ruby file located under script directory for the purpose of the gem rails. This is what the gem does. Rails is a ruby web framework, so the command rails is for starting the rails apps, go to rails console, generate files. It's bundled when you install the gem.
You can think of rails command like bundle command for bundler. bundle install, bundle update ... all are related to resolving gem dependencies. rspec command for running tests...
Some gems has an executable script such as rails, bundler, capistrano, whenever, rspec. Some other gems doesn't have such as builder, will_paginate....
You can check this out for how to add executable to a gem, http://guides.rubygems.org/make-your-own-gem/#adding-an-executable

Rake vs. Warbler in Ruby?

I have used Warble to make .war files. That worked pretty well.
Some of the tutorials online suggest using the "rake" command at various times. If rake is for compilation, I thought Ruby didn't need compilation. Is it a substitute for Warble? Or do these two play different functions?
When is rake meant to be used?
Rake is a tool written in Ruby for automating tasks, which you also write using a Ruby syntax. Ruby program's don't have to be built, but there are still plenty of other tasks involved in development that you can automate instead of doing yourself each time.
Some examples from Rails include migrating your database to a new schema or creating a new database.
Rake lets you write tasks with a Ruby syntax, and you can also specify dependencies between tasks, so that running one task will cause all of its dependencies to be ran first.
Think of rake as a make for Ruby. For example for one of the gems I develop, the Rakefile includes several tasks, like running all the tests (rake test) or building the gem (rake gem:build). More info on the web site:
http://rake.rubyforge.org/

How is Capistrano related to Rake?

I'm starting to read up on Capistrano after using Rake tasks to deploy apps for a long time. It's really striking how similar it is to Rake. A lot of parallel commands (like cap -T) and a lot of identical concepts (namespaces, tasks).
Does anyone know the history behind that? Is Capistrano an extension of Rake, or built on top of it?
UPDATE: Capistrano v3 switched back to using a Rake DSL instead of rolling their own DSL.
Capistrano v1 and v2 had no dependencies on rake. It was written from scratch as a DSL for handling remote servers. It's evident that some aspects of capistrano were influenced by rake, but Jamis Buck felt it was necessary to make capistrano stand on its own. Capistrano tasks behave slightly differently than rake tasks and their hookable nature separates them from rake tasks.
Capistrano has received minor criticism for not building upon rake, but it is still the most popular deployment tool at least in the rails community. Other projects such as Vlad the Deployer counter capistrano's implementation by using rake and ssh directly.
Capistrano started out as a series of Rake tasks but went indie early on in its development.

Resources