I'd like to use VScode as an integrated debugger with Ruby on Rails. There seem to be pretty good guides on how to do this, whether launching the process in VScode or attaching to a running debug server.
However, I cannot find good guides on how to do this when running unicorn. Consider this typical command to start the debug server:
rdebug-ide --host 0.0.0.0 --port 1234 --dispatcher-port 1234 -- ./bin/rails s
It's expecting bin/rails s to start the rails server. This is the command we currently use to start unicorn:
bundle exec unicorn_rails -E "develop_against_staging" -p 3010 -c "${PWD}/config/unicorn.rb"
Is there a way to start unicorn from within rails? Or is there another way to tell rdebug-ide what to do? I can't even find good documentation for rdebug-ide. I'll keep fiddling and answer this myself if I figure something out.
First you need to install Ruby
extension
Add following gems in your Gemfile:
gem 'debase'
gem 'ruby-debug-base', :platforms => [:jruby, :ruby_18, :mingw_18]
gem 'ruby-debug-base19x', '>= 0.11.30.pre4', :platforms => [:ruby_19, :mingw_19]
gem 'ruby-debug-ide' , "~>0.6.1"
Then you need to let rdebug-ide know you are using unicorn (multi-process app) by providing the --dispatcher-port option. Please take a look at rdebug-ide file to see all the available options.
--dispatcher-port: It is a same port that you will use to run unicorn. In your case 3010.
So it should look like this:
bundle exec rdebug-ide --debug --port 1234 --dispatcher-port 3010 -- vendor/bundle/ruby/2.6.0/bin/unicorn -E "develop_against_staging" -p 3010 -c "${PWD}/config/unicorn.rb
Running above command alone wont start the debugging, infact your Unicorn server wont be starting yet. When looking at the logs after running the above command in the terminal window you will notice a message something like this
Fast Debugger (ruby-debug-ide 0.6.1, debase 0.2.4.1, file filtering is supported) listens on 127.0.0.1:1234
The logs telling us rdebug-ide is ready to be connected at port 1234. Create a launch.json file if it is not already created and add this configuration.
{
"version": "0.2.0",
"configurations": [
{
"name": "1234 Listen for rdebug-ide",
"type": "Ruby",
"request": "attach",
"remoteHost": "127.0.0.1",
"remotePort": "1234",
"remoteWorkspaceRoot": "${workspaceRoot}",
"cwd": "${workspaceRoot}"
}
]
}
Once you add the entry, go ahead and click on Play Image here button to start debugging.
Now that your unicorn server is started, if you try to access your application you wont be able to access it because the worker process haven't started yet.
Continue to look at logs carefully you will notice
122: Ide process dispatcher notified about sub-debugger which listens on 34865. This is telling us a new sub-debugging process is started on port 34865. This is a randomly generated port find_free_port.
Note: There will a one port per unicorn-worker.
Once you see the above log add another entry into your launch.json file and copy the newly generated port into the file. Like this
{
"version": "0.2.0",
"configurations": [
{
"name": "1234 Listen for rdebug-ide",
"type": "Ruby",
"request": "attach",
"remoteHost": "127.0.0.1",
"remotePort": "1234",
"remoteWorkspaceRoot": "${workspaceRoot}",
"cwd": "${workspaceRoot}"
},
{
"name": "34865 Listen for sub-rdebug-ide",
"type": "Ruby",
"request": "attach",
"remoteHost": "127.0.0.1",
"remotePort": "34865",
"remoteWorkspaceRoot": "${workspaceRoot}",
"cwd": "${workspaceRoot}"
}
]
}
Once added, select the new configuration and click play button. If you had set number of worker to one only in your unicorn.config file, you should see the the log something like this.
I, [2022-07-13T19:44:26.914412 #122] INFO -- : worker=0 ready. Now put a breakpoint and start using your application, it will break once it reach that code path.
If you have successfully setup everything and got to this point, there will be some gotcha that you may need to deal with.
Worker timing out
Re-linking to sub-debugger with different random port.
...
This complexity is because of unicorn master-worker design.
Answering this in a bit rush, please let me know if you have any questions. I apologies if I made this more confusion for you.
Related
I've set up the ruby-debug-ide and debase gems in my Rails application so that I can use VS Code's built-in debugging tools.
During development, I would like any exception to trigger a breakpoint and start the debugger in VS Code. How can I set this up?
I was unable to do this using debase and recommend using gem debug instead, along with extension "VSCode rdbg Ruby Debugger".
You'll get a "rescue any exception" breakpoint which works (though I wasn't able to get it to rescue only uncaught exceptions).
See https://github.com/ruby/vscode-rdbg and https://github.com/ruby/debug
This is the launch.json for my rails application
{
"type": "rdbg",
"name": "Debug Rails with rdbg",
"rdbgPath": "bundle exec rdbg",
"request": "launch",
"cwd": "${workspaceFolder}",
"command": "${workspaceFolder}/bin/rails",
"script": "server",
"args": [
"-p",
"8080"
]
}
I am using Emqx V3.1.1 i have enabled emqx_lwm2m plugin and i installed wakaama client.I am able to connect to my lwm2m with 5783 port using wakaama client.(./lwm2mclient -n ep1 -h localhost -p 5783 -4).i am testing with different msg types like read discover,write,execute etc..,. I am getting proper response while sending read and discover commands. Now i am planning to test write,execute and another msg types. for this I don't have below parameters to test .
"type": {?ValueType},"value": {?Value},"args": {?Arguments},"pmin": {?PeriodMin},
"pmax": {?PeriodMax},
"gt": {?GreaterThan},
"lt": {?LessThan},
"st": {?Step}
An example write command to set the 'Current Time':
{
"path": '/3/0/13',
"type": "Time",
"value": 100
}
An example write-attr command to set the 'Minimum Period' to 10:
{
"path": "/3/0/13",
"pmin": "10"
}
Check out http://www.openmobilealliance.org/release/LightweightM2M to get the details of the spec.
I have the following systemd config
[Service]
WorkingDirectory=/srv/www/project_a/project_a/
Environment=JSON_SETTINGS=/srv/www/project_a/project_a.json
ExecStart=/srv/www/project_a/bin/daphne -b 0.0.0.0 -p 8000 project_a.asgi:channel_layer
Restart=always
KillSignal=SIGTERM
NotifyAccess=all
StandardOut=file:/tmp/daphne-access.log
StandardError=file:/tmp/daphne-error.log
But the daphne-access.log and daphone-error.log files are both empty, I thought daphne's default logging out be outputting to stdout?
Tried: --access-log=/tmp/daphne-access.log which worked for access logs, but don't know where to get django errors when they happen.
Just add the following to your LOGGING['loggers'] settings:
'daphne': {
'handlers': [
'console',
],
'level': 'DEBUG'
},
For django errors you need to define django logs. please refer the documentation for more information.
https://docs.djangoproject.com/en/2.2/topics/logging/
I am trying to set up VsCode to run my spec tests in debug mode.
I have added the following launch.json file to the project. I am using rvm and have installed the necessary gems in that location such as rspec.
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "RSpec - all",
"type": "Ruby",
"request": "launch",
"program": "<home>.rvm/gems/ruby-2.4.5/gems/rspec",
"args": [
"-I",
"${workspaceRoot}/spec/*_spec.rb"
]
}
]
}
When I run in debug mode the following displays in the console.
Uncaught exception: cannot load such file --
home-directory/.rvm/gems/ruby-2.4.5/gems/rspec
I've installed the necessary extension based on the documentation I found.
ruby, solargraph, and rubicon
Any help would be greatly appreciated.
Thank you,
Joe
Set the output from which rspec command as "program" parameter.
The problem is that the path "home-directory/.rvm/gems/ruby-2.4.5/gems/rspec" is not a valid path. You can test that theory by simply pasting into your console and executing.
In order to locate the actual rspec binary, you can use run which rspec. However, while it is possible to hard code this path into your launch config, you don't want to do that because when you upgrade the version, the path will change and you'll have problems running your tests again.
A better way is to use the environment variable that points to the GEM_HOME that includes rspec.
Here are the settings that worked for me, on ruby 3.0.3 managed by rvm on OSX.
Gemfile includes:
group :development do
gem 'ruby-debug-ide'
gem 'debase', "~> 0.2.5.beta2"
end
(the stable version of debase didn't support ruby v3, hence the beta)
Launch config use the GEM_HOME environment variable to specify the rspec binary:
{
"name": "RSpec - all",
"type": "Ruby",
"request": "launch",
"program": "${env:GEM_HOME}/bin/rspec",
"args": [
"-I",
"${workspaceRoot}"
]
}
I'm new to Google cloud and I'm trying to do my first deploy to it. My first deploy is a Ruby on Rails project.
I'm basically following this guide in the google cloud documentation. The only difference being that I'm using my own project instead of the 'hello world' project they supply.
This is my app.yaml file
runtime: custom
vm: true
entrypoint: bundle exec rackup -p 8080 -E production config.ru
resources:
cpu: 0.5
memory_gb: 1.3
disk_size_gb: 10
When I go to my project directory and run gcloud preview app deploy it starts the deploy but appears to eventually time out. It gives the error (gcloud.preview.app.deploy) Error Response: [4] DEADLINE_EXCEEDED.
Doing some research I found running gcloud preview app deploy with --verbosity debug gives extra debug info but it doesn't help me find whats causing it to timeout.
Here is the last chunk of the console log.
Bundle complete! 35 Gemfile dependencies, 102 gems now installed.
Bundled gems are installed into ./vendor/bundle.
Post-install message from rdoc:
Depending on your version of ruby, you may need to install ruby rdoc/ri data:
<= 1.8.6 : unsupported
= 1.8.7 : gem install rdoc-data; rdoc-data --install
= 1.9.1 : gem install rdoc-data; rdoc-data --install
>= 1.9.2 : nothing to do! Yay!
Post-install message from compass:
Compass is charityware. If you love it, please donate on our behalf at http://umdf.org/compass Thanks!
DEBUG: Operation [operations/build/guidir-1286/MmFkZjNmOGYtZDhhZi00NTJmLTk0YWEtMmQzMjBmM2JkOTg2OlVT] complete. Result: {
"metadata": {
"#type": "type.googleapis.com/google.devtools.cloudbuild.v1.BuildOperationMetadata",
"build": {
"finishTime": "2016-04-20T01:55:44.961635Z",
"status": "TIMEOUT",
"timeout": "600.000s",
"projectId": "guidir-1286",
"id": "2adf3f8f-d8af-452f-94aa-2d320f3bd986",
"source": {
"storageSource": {
"object": "us.gcr.io/guidir-1286/appengine/default.20160420t110030:latest",
"bucket": "staging.guidir-1286.appspot.com"
}
},
"steps": [
{
"args": [
"us.gcr.io/guidir-1286/appengine/default.20160420t110030:latest"
],
"name": "gcr.io/cloud-builders/dockerizer"
}
],
"startTime": "2016-04-20T01:45:43.216420Z",
"logsBucket": "staging.guidir-1286.appspot.com",
"images": [
"us.gcr.io/guidir-1286/appengine/default.20160420t110030:latest"
],
"createTime": "2016-04-20T01:45:41.861657Z"
}
},
"done": true,
"name": "operations/build/guidir-1286/MmFkZjNmOGYtZDhhZi00NTJmLTk0YWEtMmQzMjBmM2JkOTg2OlVT",
"error": {
"message": "DEADLINE_EXCEEDED",
"code": 4
}
}
DEBUG: (gcloud.preview.app.deploy) Error Response: [4] DEADLINE_EXCEEDED
Traceback (most recent call last):
File "/Users/Robert/google-cloud-sdk/lib/googlecloudsdk/calliope/cli.py", line 654, in Execute
result = args.cmd_func(cli=self, args=args)
File "/Users/Robert/google-cloud-sdk/lib/googlecloudsdk/calliope/backend.py", line 1401, in Run
resources = command_instance.Run(args)
File "/Users/Robert/google-cloud-sdk/lib/surface/preview/app/deploy.py", line 507, in Run
config_cleanup)
File "/Users/Robert/google-cloud-sdk/lib/googlecloudsdk/api_lib/app/deploy_command_util.py", line 195, in BuildAndPushDockerImages
storage_client)
File "/Users/Robert/google-cloud-sdk/lib/googlecloudsdk/api_lib/app/deploy_command_util.py", line 245, in _BuildImagesWithCloudBuild
image.tag, cloudbuild_client)
File "/Users/Robert/google-cloud-sdk/lib/googlecloudsdk/api_lib/app/cloud_build.py", line 181, in ExecuteCloudBuild
retry_callback=log_tailer.Poll)
File "/Users/Robert/google-cloud-sdk/lib/googlecloudsdk/api_lib/app/api/operations.py", line 69, in WaitForOperation
encoding.MessageToPyValue(completed_operation.error)))
OperationError: Error Response: [4] DEADLINE_EXCEEDED
ERROR: (gcloud.preview.app.deploy) Error Response: [4] DEADLINE_EXCEEDED
This is the furthest its gone, but sometimes its mid way through installing the gems before it times out and other times it doesn't even get upto installing the gems.
How can I stop this from occurring?
There's a 10 minute default timeout for Docker builds (the mechanism by which runtime: custom App Engine builds work). You can increase this by running gcloud config set app/cloud_build_timeout [NUMBER OF SECONDS].
You could also work around by performing the build yourself:
docker build . -t gcr.io/myapp/myimage
gcloud docker push gcr.io/myapp/myimage
gcloud preview app deploy app.yaml --image-url=gcr.io/myapp/myimage
However, in general, your Docker builds shouldn't be taking this long. It's usually better to have a base image with all of your dependencies already built in, and just have the final build derive from that image and install your app. This way, your builds will be much quicker.
This error is raised when the overall request times out.
The execution limit is 10 minutes for task queue requests.
You can increase this timeout limit on google cloud shell, by typing gcloud config set app/cloud_build_timeout [TIMEOUT_SECONDS]
Example
gcloud config set app/cloud_build_timeout 1000