Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

THREESCALE-10697: Add debug mode for the worker and add RubyMine configurations for both worker and listener #363

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,41 @@ Additional information which is really important to how the application runs can
be found in the manifest:

> `$ bundle exec 3scale_backend manifest`

## Running from your IDE

Some IDEs like VSCode or RubyMine allow to add custom launchers for scripts. This is convenient to launch both Worker and Listener.

For that, you'll need to create the following configurations:

### Worker
lvillen marked this conversation as resolved.
Show resolved Hide resolved

| Field | Value |
|-----------------------|---------------------------------------------------------|
| Name | `worker` |
| Ruby script | `/path/to/project/apisonator/bin/3scale_backend_worker` |
| Script arguments | `--debug` |
| Working directory | `/path/to/project/apisonator` |
| Environment variables | `RACK_ENV=development` |

In case you want to run the worker in async mode you can add `CONFIG_REDIS_ASYNC=true` to the environment variables here or directly add it to your `.env` file.

### Puma Listener (sync mode)

| Field | Value |
|-----------------------|--------------------------------------------------|
| Name | `listener (puma)` |
| Ruby script | `/path/to/project/apisonator/bin/3scale_backend` |
| Script arguments | `-s puma -X start -p 3001` |
| Working directory | `/path/to/project/apisonator` |
| Environment variables | `RACK_ENV=development` |

### Falcon Listener (async mode)

| Field | Value |
|-----------------------|-------------------------------------------------------------------|
| Name | `listener (falcon)` |
| Ruby script | `/path/to/project/apisonator/bin/3scale_backend` |
| Script arguments | `-s falcon start -p 3001` |
| Working directory | `/path/to/project/apisonator` |
| Environment variables | `RACK_ENV=development;CONFIG_REDIS_ASYNC=true` |
43 changes: 28 additions & 15 deletions bin/3scale_backend_worker
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
#!/usr/bin/env ruby
require '3scale/backend'
require '3scale/backend/job_fetcher'
require 'daemons'

if ARGV.delete '--version'
STDOUT.puts "3scale_backend_worker version #{ThreeScale::Backend::VERSION}"
exit 0
def debug
ThreeScale::Backend::Worker.work(job_fetcher: ThreeScale::Backend::JobFetcher.new(fetch_timeout: 1))
end

options = {
multiple: true,
dir_mode: :normal,
dir: '/var/run/3scale'
}
def production
options = {
multiple: true,
dir_mode: :normal,
dir: "#{ENV['WORKER_PIDFILE_DIR'] || '/var/run/3scale'}"
}

# make --no-daemonize an alias of --ontop
options[:ontop] = true if ARGV.delete '--no-daemonize'
# make --no-daemonize an alias of --ontop
options[:ontop] = true if ARGV.delete '--no-daemonize'

if !File.writable? options[:dir]
require 'fileutils'
FileUtils.mkdir_p options[:dir]
if !File.writable? options[:dir]
require 'fileutils'
FileUtils.mkdir_p options[:dir]
end

Daemons.run_proc('3scale_backend_worker', options) do
ThreeScale::Backend::Worker.work
end
end

if ARGV.delete '--version'
STDOUT.puts "3scale_backend_worker version #{ThreeScale::Backend::VERSION}"
exit 0
lvillen marked this conversation as resolved.
Show resolved Hide resolved
end

Daemons.run_proc('3scale_backend_worker', options) do
ThreeScale::Backend::Worker.work
if ARGV.delete '--debug'
debug
else
production
end