Class: DiasporaFederation::Federation::Sender::HydraWrapper

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/diaspora_federation/federation/sender/hydra_wrapper.rb

Overview

A wrapper for [Typhoeus::Hydra]

Uses parallel http requests to send out the salmon-messages

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

included

Constructor Details

#initialize(sender_id, obj_str) ⇒ HydraWrapper

Create a new instance for a message

Parameters:

  • sender_id (String)

    sender diaspora-ID

  • obj_str (String)

    object string representation for logging (e.g. type@guid)



32
33
34
35
36
# File 'lib/diaspora_federation/federation/sender/hydra_wrapper.rb', line 32

def initialize(sender_id, obj_str)
  @sender_id = sender_id
  @obj_str = obj_str
  @urls_to_retry = []
end

Class Method Details

.hydra_optsHash

Hydra default opts

Returns:

  • (Hash)

    hydra opts



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/diaspora_federation/federation/sender/hydra_wrapper.rb', line 12

def self.hydra_opts
  @hydra_opts ||= {
    maxredirs:    DiasporaFederation.http_redirect_limit,
    timeout:      DiasporaFederation.http_timeout,
    method:       :post,
    verbose:      DiasporaFederation.http_verbose,
    cainfo:       DiasporaFederation.certificate_authorities,
    forbid_reuse: true,
    headers:      {
      "Expect"            => "",
      "Transfer-Encoding" => "",
      "User-Agent"        => DiasporaFederation.http_user_agent
    }
  }
end

Instance Method Details

#insert_job(url, xml) ⇒ Object

Prepares and inserts job into the hydra queue

Parameters:

  • url (String)

    the receive-url for the xml

  • xml (String)

    xml salmon message



41
42
43
44
45
# File 'lib/diaspora_federation/federation/sender/hydra_wrapper.rb', line 41

def insert_job(url, xml)
  request = Typhoeus::Request.new(url, HydraWrapper.hydra_opts.merge(body: {xml: xml}))
  prepare_request(request)
  hydra.queue(request)
end

#sendArray<String>

Sends all queued messages

Returns:

  • (Array<String>)

    urls to retry



49
50
51
52
# File 'lib/diaspora_federation/federation/sender/hydra_wrapper.rb', line 49

def send
  hydra.run
  @urls_to_retry
end