herokuでworkerだけをrestartする方法

heroku ps -a myapp

まずはプロセスを確認

$ heroku ps -a myapp
=== web (Standard-1X): bundle exec puma -C config/puma.rb (1)
web.1: up 2017/03/06 00:00:00 +0900 (~ 10h ago)

=== worker (Standard-1X): bundle exec sidekiq -C config/sidekiq.yml (1)
worker.1: up 2017/03/06 00:00:00 +0900 (~ 10h ago)

heroku restart worker.1 -a myapp

プロセスを指定して再起動

$ heroku restart worker.1 -a myapp
Restarting worker.1 dynos on ⬢ myapp... done

複数のworkerを同時に再起動する方法

$ heroku ps -a myapp
=== web (Standard-1X): bundle exec puma -C config/puma.rb (1)
web.1: up 2017/03/06 00:00:00 +0900 (~ 10h ago)

=== worker (Standard-1X): bundle exec sidekiq -C config/sidekiq.yml (3)
worker.1: up 2017/03/06 00:00:00 +0900 (~ 10h ago)
worker.2: up 2017/03/06 00:00:00 +0900 (~ 10h ago)
worker.3: up 2017/03/06 00:00:00 +0900 (~ 10h ago)

複数workerがある場合、下記のようにすれば一括で再起動。

$ heroku restart worker -a myapp
Restarting worker dynos on ⬢ myapp... done

constantizeした時にactive_support/inflector/methods.rb:268:in `const_get': uninitialized constant Hoge (NameError)と怒られる問題[Rails]

h = 'Hoge'.constantize
h.create(fuga: 'fuga')

した時に

active_support/inflector/methods.rb:268:in `const_get': uninitialized constant Hoge (NameError)

Hogeという定数、クラスがなかったため怒られてしまった。

safe_constantizeで回避

safe_constantizeを使うと存在しなかった場合 nil が返されます nilチェックしてから実行して回避

h = 'Hoge'.safe_constantize
h.create(fuga: 'fuga') unless h.nil?

rake taskの中断はreturnではなくnextだった[Rails]

task :test do
  puts 'hoge'
  return
  puts 'moge'
end

実行する

rake aborted!
LocalJumpError: unexpected return

怒られた…

rake taskの中断はreturnじゃなくてnextとのこと

task :test do
  puts 'hoge'
  next
  puts 'moge'
end

以下の場合はreturnとのこと

task :foo do
  do_something
end

def do_something
  puts "startd"
  return
  puts "end"
end

http://stackoverflow.com/questions/2316475/how-do-i-return-early-from-a-rake-task

brew updateしたら/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directoryと怒られる問題

brew update

brew update したら

$  brew update                       
/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directory
/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directory
/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directory
/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directory
/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directory
/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directory
/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directory
/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directory
/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directory
/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directory
/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directory
/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directory
/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directory
/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directory
/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directory
/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directory
/usr/local/Library/brew.sh: line 32: /usr/local/Library/ENV/scm/git: No such file or directory
==> Homebrew has enabled anonymous aggregate user behaviour analytics.
Read the analytics documentation (and how to opt-out) here:
  http://docs.brew.sh/Analytics.html

Error: update-report should not be called directly!

めっちゃ怒られた

対応

他の方のブログでは brew prune で解消らしいが…

3回目の brew update で普通にupdateされました

なんだったのだろう…

getCurrentPosition() and watchPosition() no longer work on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS. See https://goo.gl/rStTGz for more details.

GoogleMapAPIを使って現在地情報を取得しようとしたところ Chrome

getCurrentPosition() and watchPosition() no longer work on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS. See https://goo.gl/rStTGz for more details.

Safari

[blocked] Access to geolocation was blocked over insecure connection to http://xxx.com.

とのエラーが…

GoogleMapAPIからの返り値を見ると下記のエラー文

getCurrentPosition() and watchPosition() no longer work on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS. See https://goo.gl/rStTGz for more details.

原因としては、 セキュリティの関係上SSLになっているか、ドメインlocalhostなど限られた条件でないと現在地情報を使えないようになっているようです。
ローカル環境で開発しているならドメインlocalhostに設定してデバッグすれば動作します。
もしくはFirefoxならドメイン関係なく現在地情報を使えるため問題なくデバッグできました。