Skip to content

Commit

Permalink
Fix anycable logging and cable.disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
jmthomas committed Jan 30, 2025
1 parent 2ba791c commit f75ab2a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
3 changes: 3 additions & 0 deletions openc3-cosmos-cmd-tlm-api/Procfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
web: bin/rails s -b 0.0.0.0 -p 2901
# Go logging is log_level (https://docs.anycable.io/anycable-go/configuration?id=logging-settings)
ws: anycable-go --host 0.0.0.0 --port 3901 --path /openc3-api/cable --log_level error
# Ruby logging is log-level (https://docs.anycable.io/ruby/logging?id=logging)
# but Rails overrides this so we set it in config/application.rb
rpc: bundle exec anycable --broadcast_adapter http
9 changes: 8 additions & 1 deletion openc3-cosmos-cmd-tlm-api/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,16 @@ class Application < Rails::Application
)
end

puts "Starting #{$0} in #{Rails.env} environment"

# Setup structured logging
require 'openc3/utilities/cosmos_rails_formatter'
config.log_level = ENV["LOG_LEVEL"] || :info
# Don't set the anycable logger to info because it's way too much output
if $0.include?('anycable')
config.log_level = ENV["LOG_LEVEL"] || :error
else
config.log_level = ENV["LOG_LEVEL"] || :info
end
config.log_tags = {
request_id: :request_id,
token: -> request { request.headers['HTTP_AUTHORIZATION'] || request.query_parameters[:authorization] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# if purchased from OpenC3, Inc.
*/

import { createConsumer } from "@anycable/web";
import { createConsumer } from '@anycable/web'

export default class Cable {
constructor(url = '/openc3-api/cable') {
Expand All @@ -29,7 +29,8 @@ export default class Cable {
}
disconnect() {
if (this._cable) {
this._cable.disconnect()
this._cable.cable.disconnect()
this._cable = null
}
}
createSubscription(channel, scope, callbacks = {}, additionalOptions = {}) {
Expand Down
5 changes: 4 additions & 1 deletion openc3-cosmos-script-runner-api/Procfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
web: bin/rails s -b 0.0.0.0 -p 2902
ws: anycable-go --host 0.0.0.0 --port 3902 --path /script-api/cable --log_level error
# Go logging is log_level (https://docs.anycable.io/anycable-go/configuration?id=logging-settings)
ws: anycable-go --host 0.0.0.0 --port 3902 --path /script-api/cable
# Ruby logging is log-level (https://docs.anycable.io/ruby/logging?id=logging)
# but Rails overrides this so we set it in config/application.rb
rpc: bundle exec anycable --broadcast_adapter http
9 changes: 8 additions & 1 deletion openc3-cosmos-script-runner-api/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,16 @@ class Application < Rails::Application
)
end

puts "Starting #{$0} in #{Rails.env} environment"

# Setup structured logging
require 'openc3/utilities/cosmos_rails_formatter'
config.log_level = ENV["LOG_LEVEL"] || :info
# Don't set the anycable logger to info because it's way too much output
if $0.include?('anycable')
config.log_level = ENV["LOG_LEVEL"] || :error
else
config.log_level = ENV["LOG_LEVEL"] || :info
end
config.log_tags = {
request_id: :request_id,
token: -> request { request.headers['HTTP_AUTHORIZATION'] || request.query_parameters[:authorization] }
Expand Down

0 comments on commit f75ab2a

Please sign in to comment.