I have a rails application that needs to communicate with a background java application using DBus. Is it possible to do this on heroku or will I need VPS hosting?
To use DBus, both applications need to be running inside the same operating system
I have only run rake jobs on herokus cron that is called 'Heroku Scheduler' but if you can load the java app on heroku you should be able to do it
Heroku handles Cron jobs via its own add on called Scheduler. You can read how to use it here: https://addons.heroku.com/scheduler
Related
I am using this command
bundle exec sidekiq -d
to run sidekiq server on the background. getting this error message
ERROR: Daemonization mode was removed in Sidekiq 6.0, please use a proper process supervisor to start and manage your services.
sidekiq run but not in the background. After closing the console sidekiq automatically close.
You may also think about using process manager like overmind which will help you manage multiple processes (for instance server and sidekiq)
https://github.com/DarthSim/overmind
There are other tools around the web, this is my personal choice.
You need to open another terminal tab, in ubuntu ctrl + shift + T and run command
bundle exec sidekiq start
It is removed from the latest versions of Sidekiq to promote users to learn the newer, better ways. Here is the link to the discussion on the same.
The discussion suggested using a process supervisor like systemd, upstart, foreman, etc. to manage Sidekiq.
So you need to write your own service file to start, stop sidekiq. For the reference, here is the link to example service of sidekiq.
https://github.com/mperham/sidekiq/blob/master/examples/systemd/sidekiq.service
You didn't mention the operating system so I'll just go with ubuntu production VM. You're going to want to setup sidekiq with something like systemd or upstart. Sidekiq has some example configurations to get you started https://github.com/mperham/sidekiq/tree/master/examples.
I haven't done this on a mac before, but a quick google and found this Start sidekiq automatically on OSX.
I want to have a separate instance for running Sidekiq in my production environment.
Currently I have db, web and app instances and the app instance is taking care of sidekiq which is proving to be a wrong move.
I created a new instance with roles redis, redis_master and sidekiq but then when I SSH into it there is nothing running and if I do a cap deploy to it, during bundle install it says "dotenv" is only for instances with role app and it rolled back.
How do I set things up? Do I need to add app role to the Sidekiq instance for it to work?
EDIT:
Okay I've made it work by adding the app role to instance running sidekiq. Also I removed the passenger and apache roles from it manually so it does not start an app server. The only problem Im facing now is the fact that rubber is not automatically starting and stopping and restarting sidekiq during deploys. Need to figure that out.
Looking good though.
Are these ansible roles?
I'd recommend setting up a rails and ruby role (separately) in your ansible playbook, run the playbook in your new sidekiq-prod instance, then do a cap prod deploy
If you are using a rails app with capistrano to do your sidekiq deploys, you can access the rails env in your setup of lib/capistrano/tasks/sidekiq.cap:
export RAILS_ENV=<%= fetch(:rails_env) %>
This is my first time scheduling a task and I am not sure of the best implementation (or the proper implementation).
My Goal:
I have a ruby on rails 4 app setup with twilio and deployed on Heroku. I want the app to automatically text all of my users once a week with a customized text message (which is written and created by information in the database).
From research I have come down to the following Gems: Whenever and Rufus-Scheduler.
I believe that both these gems can get the Job done, but upon reading on the Rufus' docs: "please note: rufus-scheduler is not a cron replacement" I got stuck trying to understand if what I want is indeed a cron job or a "Rufus-Scheduler".
I am left with the following questions: What is a cron job and when is the appropriate time to use it? Why is Rufus-Scheduler not a cron replacement and what does it do differently? Which one should I use?
About Cron:
Cron is name of program which does scheduled tasks on nix systems. what Scheduled Tasks are in Windows, Cron does something similar for Linux at the conceptual level.Cron is one of the most useful tool in Linux or UNIX like operating systems. The cron service (daemon) runs in the background and constantly checks the /etc/crontab file, and /etc/cron./ directories. It also checks the /var/spool/cron/ directory.
For Scheduling tasks on Heroku
Good news is that on Heroku there is a thing called Scheduler which is an add-on for running jobs on your app at scheduled time intervals, much like cron in a traditional server environment. so you really don't need to fiddle/player with cron or gems like whenever. just use the Scheduler addon on Heroku.
For More info see: https://devcenter.heroku.com/articles/scheduler
A cron job is a program run on an automated time schedule, using the cron software.
Rufus-Scheduler is different from cron because it runs inside of Ruby processes.
For what you're describing I believe either would be fine.
rufus-scheduler is not a cron replacement
can be expanded to "rufus-scheduler was never written as a drop-in replacement for cron". The bigger message is "you are a developer and as a developer you should know the environment you inherit and the tools it comes with. You should know when to use them, when to imitate them, when to replace them."
Rufus-scheduler understands the "* * * * *" syntax of Cron. This has led some people to say "rufus-scheduler tries to be a Cron replacement". It could better be formulated as "some people have abused rufus-scheduler instead of thinking (knowing) that old faithful Cron would have been better in that situation".
To become a good developer you should think seriously about some *nix sysadmin skills, else you'll be a pain to work with. It can be as easy as "install, run and manage a linux box in a VirtualBox in your system".
A rufus-scheduler schedule runs in a Ruby process. In a vanilla world, one runs rufus-scheduler in the same Ruby process that services http requests (Rails or Sinatra web application), and, oh, oops, the schedules don't run when the application doesn't run.
Cron is a service provided by your *nix operating system. Other applications and services on your host rely on it. Cron reads its crontab and runs the script indicated in it at the given times. Thanks to the excellent Whenever, Cron can be told to run scripts in your Rails application.
This might interest you as well: https://devcenter.heroku.com/articles/clock-processes-ruby
whenever allows you to write ruby code that would be transformed in a crontab file, which is a file specifying a set of commands and a frequency for each command. This file is used by cron.
rufus-scheduler is pure ruby, you write ruby and jobs are running in ruby, for example inside your application loop calling scheduler.join, or in another thread calling ruby your/rufus_scheduler_script.rb.
In my opinion they do the same things, with cron you are using a linux command, but I don't see any other difference.
There are other options too, in my experience I have had problems with rufus-scheduler, and whenever (they did not find classes in my Rails app, but maybe was just a quirk), on the other side clockwork worked for me.
I currently have a rails 3.2 app that I am going to use thin as a web server for. I haven't found a way or know if what I am even attempting is possible which is why I came here to ask. What i'm trying to do is after I start my rails app with the usual bundle exec thin start to afterward execute a ruby file/script to load up another web event based mini application(pure ruby non web framework) that will uses the same server/ data store as the main rails app. Is there such a hook either with thin configs or rails start up configs to accomplish such a thing?
-edit-
to clarify, the mini application is within the rails app in its own directory, it is not an external app which is why it will share resources.
Have you tried Foreman? It is a tool used for describing and launching all the individual processes your application requires (potentially covering both your main web server, thin, and the secondary Ruby process you mentioned). You would just install Foreman, then write a Procfile describing both processes to run at startup.
I am building an application that will only be run on a local network and am looking for the best way to restart my server from within the application itself. For the time being this is only running on Windows using WEBrick.
Look at Capistrano as others have suggested, it's fantastic :)
$ cap deploy
That's all you have to do. It'll grab the latest source from your git/SVN repo (lots more supported ofc), deploy, and restart your app server.