Sidekiq server not loading configuration file - ruby

I'm trying to setup sidekiq with my sinatra application, and I'm having
trouble starting up the sidekiq workers to run in the daemon mode, with a configuration file.
My project has the following structure:
project
- config
-- sidekiq.yml #Sidekiq Config File
- app
-- app.rb #Sinatra Application File
- Rakefile
- Gemfile
- etc.
The ultimate goal is to create some rake tasks to handle all sidekiq tasks.
For now, I'm just trying to the get things to work correctly via the command line, and then I'll get it working via rake.
sidekiq.yml
# Sidekiq Configuration
---
development:
logile: ./log/sidekiq_development.log
verbose: true
pidfile: ./tmp/pids/sidekiq.pid
concurrency: 1
queues:
- [household_import, 7]
When I run this command in the project directory:
bundle exec sidekiq -C './config/sidekiq.yml' -e 'development' -d
I get the following:
You really should set a logfile if you're going to daemonize
/Users/gutter007/git/webapps/project/vendor/bundle/gems/sidekiq-2.16.1/lib/sidekiq/cli.rb:141:in
`daemonize'
/Users/gutter007/git/webapps/project/vendor/bundle/gems/sidekiq-2.16.1/lib/sidekiq/cli.rb:39:in
`parse'
/Users/gutter007/git/webapps/project/vendor/bundle/gems/sidekiq-2.16.1/bin/sidekiq:7:in
`<top (required)>'
/Users/gutter007/git/webapps/project/vendor/bundle/bin/sidekiq:23:in
`load'
/Users/gutter007/git/webapps/project/vendor/bundle/bin/sidekiq:23:in
`<main>'
My confusion is that I have the logfile set in the config file. My assumption is that it's not picking up or reading the cofig file correctly.
I tried tweaking the paths, and using full paths with the config file, but it did not seem to change anything the error message. I've also tweaked the config file itself, assuming the format might be off, but no dice.
Does anyone see what I'm doing wrong here?
Please let me know if you need any more information.
thanks.

I dug into the sidekiq code, and debugged my config file issues.
There were two issues:
I spelled logfile incorrectly ... doh!
You need to setup each row
with a colon(:) to symbolize the value. It pulls the yaml file into
a hash, and without the symbol it won't recognize the key
So
development:
logfile: ./log/sidekiq_development.log
won't work, but
development:
:logfile: ./log/sidekiq_development.log
#notice the ':' infront of the logfile
does!
Here is my updated working logfile.
# Sidekiq Configuration
---
development:
:logfile: ./log/sidekiq_development.log
:verbose: true
:pidfile: ./log/tmp/pids/sidekiq.pid
:concurrency: 1
:queues:
- [household_import, 7]

Following command helped me,
sidekiq -d -q carrierwave -l sidekiq.log
you can omit "-q carrierwave" part, if yuo're not using 'carrierwave'

Related

Ruby Rake ActiveRecord Migrate

I'm trying to build a simple ruby script that connects to a database and runs some basic queries.
The code is here: https://github.com/mastermindg/rack-activrecord-example
It's not a service - only a script that is run manually to do batch jobs. My problem is that I need to populate the database for testing purposes. I know how to do this in Sinatra and Rails but it's failing as-is:
NoMethodError: undefined method `set' for main:Object
Did you mean? send
/usr/src/app/app.rb:7:in `<top (required)>'
/usr/src/app/Rakefile:2:in `<top (required)>'
I've got the database.yml but I can't tell how to load it since set is failing.
How do I connect to and query a database using ActiveRecord with basic Rack?
1) Add this to your Rakefile after the requires:
DatabaseTasks.database_configuration = YAML.load(File.read(File.join(root, 'config/database.yml')))
2) Remove set :database_file, 'config/database.yml' from your app.rb file (I think set is a sinatra/activerecord method).
Running rake db:create may give you an error on your project now,because you're using json instead of JSON in your app.rb file (depending on your local versions), so. . .
3) Change puts json Resource.select('id', 'name').all to puts JSON Resource.select('id', 'name').all in your app.rb file.
Now rake db:create will throw a database error, but that's an error related to your specific database configuration, make an appropriate adjustment to that (this is off-topic from the original question, so I won't address it further) and your app should run as you desire.
More info:
This gist shows example contents of a Rakefile that you could use to run Active Record tasks without using Rails or Sinatra.

Where does Puma log to

I have been using Thin to run my ruby Sinatra applications but I am now switching over to Puma. Thin creates its own log log/thin.log which I use. I noticed that Puma doesn't produce a log file (not that I can see). I have tried googling for documentation around this but not really found anything.
I was wondering if/how you can specify a log path in Puma.
Any help would be much appreciated.
Alex
Check the example config.rb as recommended on the repo's README.
As shown there:
# Redirect STDOUT and STDERR to files specified. The 3rd parameter
# (“append”) specifies whether the output is appended, the default is “false”.
stdout_redirect '/u/apps/lolcat/log/stdout', '/u/apps/lolcat/log/stderr'
stdout_redirect '/u/apps/lolcat/log/stdout', '/u/apps/lolcat/log/stderr', true

Heroku load error on require?

My Ruby application runs fine on my nitrous.io box, but when I push it to Heroku and it attempts to run a scheduled process, the logs show this error:
2013-12-23T22:37:11.902160+00:00 heroku[scheduler.4283]: State changed from starting to up
2013-12-23T22:37:12.178751+00:00 app[scheduler.4283]: from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:53:in `require'
2013-12-23T22:37:12.178751+00:00 app[scheduler.4283]: from /app/bin/rbtc:3:in `<main>'
2013-12-23T22:37:12.178751+00:00 app[scheduler.4283]: /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:53:in `require': cannot load such file -- rbtc_arbitrage (LoadError)
2013-12-23T22:37:13.432972+00:00 heroku[scheduler.4283]: Process exited with status 1
2013-12-23T22:37:13.461438+00:00 heroku[scheduler.4283]: State changed from up to complete
This is the code in /app/bin/rbtc:3
#!/usr/bin/env ruby
require 'rbtc_arbitrage'
RbtcArbitrage::CLI.start ARGV
File structure link
I tried changing this to require_relative as in a answer to someone else on Stack Overflow to no avail.
I'm kinda at a loss here. Any help is appreciated!
Please, make sure that this file exists: lib/rbtc_arbitrage.rb which loads other files in your repo like this (syntax is valid if you are using bundler):
require 'rbtc_arbitrage/version'
require 'rbtc_arbitrage/file1'
# .. and so on
Now, adding this file should work alone, but if this does not work, try adding your lib directory to the LOAD PATH in your bin/rbtc file before any require statments, like this:
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
This explicitly tells ruby to add the lib directory to the load path, and should solve your problem.

AppFog background worker 'failed to start'

I'm trying to follow the AppFog guide on creating a background worker in ruby, and I'm running into some (probably noob) issues. The example uses Rufus-scheduler, which (according to the Ruby docs on AppFog) means I need to use Bundler to include/manage within my app. Nonetheless, I've run bundle install, pushed everything to AppFog in the appropriate ('standalone') fashion, and still can't seem to get it running.
my App & Gemfile:
...and via the AF CLI:
$ af push
[...creating/uploading/etc. etc... - removed to save space]
Staging Application 'chservice-dev': OK
Starting Application 'chservice-dev': .
Error: Application [chservice-dev] failed to start, logs information below.
====> /logs/staging.log <====
# Logfile created on 2013-06-27 20:22:23 +0000 by logger.rb/25413
Need to fetch tzinfo-1.0.1.gem from RubyGems
Adding tzinfo-1.0.1.gem to app...
Adding rufus-scheduler-2.0.19.gem to app...
Adding bundler-1.1.3.gem to app...
====> /logs/stdout.log <====
2013-06-27 20:22:28.841 - script executed.
Delete the application? [Yn]:
How can I fix (or troubleshoot) this? I'm probably missing a large step/concept... very new to ruby =)
Thanks in advance.
I think the app might be exiting immediately. The scheduler needs to be joined to the main thread in order to keep that app running.
require 'rubygems'
require 'rufus/scheduler'
scheduler = Rufus::Scheduler.start_new
scheduler.every '10s' do
puts 'Log this'
end
### join the scheduler to the main thread ###
scheduler.join
I created a sample rufus scheduler app that works on appfog: https://github.com/tsantef/appfog-rufus-example

Can't access Heroku console with app name

I just started a new app and I was able to push it to Heroku, But I it seems, that I can't access the console.
The command, that I am running is:
heroku run console --app myappname
What I get, is:
Running `console` attached to terminal... up, run.3951 Usage: rails
new APP_PATH [options]
Options: -r, [--ruby=PATH] # Path to the Ruby binary of
your choice
# Default: /app/vendor/ruby-1.9.3/bin/ruby -b, [--builder=BUILDER] #
Path to a application builder (can be a filesystem path or URL) -m,
[--template=TEMPLATE] # Path to an application template (can be a
filesystem path or URL)
[--skip-gemfile] # Don't create a Gemfile
[--skip-bundle] # Don't run bundle install -G, [--skip-git] # Skip Git ignores and keeps -O,
[--skip-active-record] # Skip Active Record files -S,
[--skip-sprockets] # Skip Sprockets files -d,
[--database=DATABASE] # Preconfigure for selected database
(options:
mysql/oracle/postgresql/sqlite3/frontbase/ibm_db/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc)
# Default: sqlite3 -j, [--javascript=JAVASCRIPT] # Preconfigure for selected JavaScript
library
# Default: jquery -J, [--skip-javascript] # Skip JavaScript files
[--dev] # Setup the application with Gemfile pointing to your Rails checkout
[--edge] # Setup the application with Gemfile pointing to Rails repository -T, [--skip-test-unit] # Skip
Test::Unit files
[--old-style-hash] # Force using old style hash (:foo = 'bar') on Ruby >= 1.9
Runtime options: -f, [--force] # Overwrite files that already
exist -p, [--pretend] # Run but do not make any changes -q,
[--quiet] # Suppress status output -s, [--skip] # Skip files
that already exist
Rails options: -h, [--help] # Show this help message and quit
-v, [--version] # Show Rails version number and quit
Description:
The 'rails new' command creates a new Rails application with a default
directory structure and configuration at the path you specify.
You can specify extra command-line arguments to be used every time
'rails new' runs in the .railsrc configuration file in your home directory.
Note that the arguments specified in the .railsrc file don't affect the
defaults values shown above in this help message.
Example:
rails new ~/Code/Ruby/weblog
This generates a skeletal Rails installation in ~/Code/Ruby/weblog.
See the README in the newly created application to get going.
I know, that the application name is correct, as I just pushed it and it is loaded.
When I look at the logs on Heroku for the moment, when I tried to hit the console, I see following:
2013-07-01T16:21:58.780979+00:00 heroku[api]: Starting process with command `bundle exec rails console` by mzaragoza#myemail.com
2013-07-01T16:22:09.000482+00:00 heroku[run.2993]: Awaiting client
2013-07-01T16:22:09.055474+00:00 heroku[run.2993]: Starting process with command `bundle exec rails console`
2013-07-01T16:22:10.342966+00:00 heroku[run.2993]: State changed from starting to up
2013-07-01T16:22:13.870963+00:00 heroku[run.2993]: Process exited with status 0
2013-07-01T16:22:13.889703+00:00 heroku[run.2993]: State changed from up to complete
What about heroku run rails c? Does it make any difference if you add rails?
PS: I'm unsure if you want to access Rails' console or just a normal shell, from the comments.
The correct form is => heroku run "any rails command here"
I had this problem when I upgraded to Rails > 4.0.0. The solution is to run locally the following command rake rails:update:bin. This will generate a bin directory in the root of your application. Make sure that it is not in your .gitignore file. Commit and then push the changes to Heroku.
For 3.2.x apps:
This also just happened to me when I removed script/rails from my repo and pushed to Heroku. Reverting the commit and pushing that change made things work again.

Resources