Class: RubyWorker::Service
- Inherits:
-
Revund::Worker::V1::Worker::Service
- Object
- Revund::Worker::V1::Worker::Service
- 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.
Constant Summary collapse
- NAME =
'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.
29 30 31 |
# File 'lib/ruby_worker/service.rb', line 29 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.
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ruby_worker/service.rb', line 36 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
50 51 52 53 54 55 56 57 |
# File 'lib/ruby_worker/service.rb', line 50 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
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/ruby_worker/service.rb', line 59 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 |