Class: RubyWorker::Service
- Inherits:
-
Object
- Object
- RubyWorker::Service
- Defined in:
- lib/ruby_worker/service.rb
Overview
Service implements the universal ‘revund.worker.v1.Worker` contract — the same contract ts-worker and php-worker speak.
Each handler is thin — it translates between the gRPC wire shape and the Parser domain object. The handler bodies are written against the assumed generated message shape so swapping the stub in is mechanical.
Constant Summary collapse
- NAME =
include ::Revund::Worker::V1::Worker::Service
'ruby-worker'- LANGUAGES =
['ruby'].freeze
- CAPABILITIES =
%w[parse self_fetch].freeze
- AUTH_HEADER =
AUTH_HEADER mirrors the Go-side constant in core/pkg/worker/auth.go. The bot stamps it on every outbound RPC; this worker rejects requests without a matching value when REVUND_WORKER_SECRET is configured.
'x-revund-worker-token'- AUTH_SECRET_ENV =
'REVUND_WORKER_SECRET'
Instance Method Summary collapse
-
#describe(_request, call) ⇒ Object
Describe — self-identifies.
- #health(_request, call) ⇒ Object
-
#initialize ⇒ Service
constructor
A new instance of Service.
- #parse(request, call) ⇒ Object
Constructor Details
#initialize ⇒ Service
Returns a new instance of Service.
34 35 36 |
# File 'lib/ruby_worker/service.rb', line 34 def initialize @parser = RubyWorker::Parser.new end |
Instance Method Details
#describe(_request, call) ⇒ Object
Describe — self-identifies. The bot calls this on first connect to learn what languages + capabilities this worker advertises.
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ruby_worker/service.rb', line 41 def describe(_request, call) return unauthenticated!(call) unless (call) response_class = ::Revund::Worker::V1::DescribeResponse rescue nil return nil if response_class.nil? response_class.new( name: NAME, version: Server::VERSION, languages: LANGUAGES, capabilities: CAPABILITIES, ) end |
#health(_request, call) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/ruby_worker/service.rb', line 55 def health(_request, call) return unauthenticated!(call) unless (call) response_class = ::Revund::Worker::V1::HealthResponse rescue nil return nil if response_class.nil? response_class.new(version: Server::VERSION) end |
#parse(request, call) ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/ruby_worker/service.rb', line 64 def parse(request, call) return unauthenticated!(call) unless (call) response_class = ::Revund::Worker::V1::ParseResponse rescue nil return nil if response_class.nil? repo_path = resolve_repo_path(request) parsed = @parser.parse_files(repo_path, request.files.to_a) response_class.new(files: parsed) end |