Class: Nexo::UpdateRemoteResourceJob

Inherits:
BaseJob
  • Object
show all
Includes:
ApiClients
Defined in:
app/jobs/nexo/update_remote_resource_job.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#elementObject (readonly)

Returns the value of attribute element.



8
9
10
# File 'app/jobs/nexo/update_remote_resource_job.rb', line 8

def element
  @element
end

#element_versionObject (readonly)

Returns the value of attribute element_version.



8
9
10
# File 'app/jobs/nexo/update_remote_resource_job.rb', line 8

def element_version
  @element_version
end

Instance Method Details

#perform(element_version) ⇒ Object

Raises:

  • Google::Apis::ClientError

  • (ActiveRecord::RecordNotUnique)

    on ElementVersion update

  • (Errno::ENETUNREACH)
    • (Network is unreachable - Network is unreachable - connect(2) for “www.googleapis.com

  • (Signet::AuthorizationError)
    • Unexpected error: #<Faraday::ConnectionFailed

      wrapped=#<Socket::ResolutionError: Failed to open TCP connection to
      oauth2.googleapis.com:443 (getaddrinfo: Name or service not known)>>"
      


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/jobs/nexo/update_remote_resource_job.rb', line 18

def perform(element_version)
  @element_version = element_version
  @element = element_version.element

  validate_element_state!

  remote_service = ServiceBuilder.instance.build_protocol_service(element.folder)

  response =
    if element.uuid.present?
      remote_service.update(element)
    else
      remote_service.insert(element).tap do |response|
        ElementService.new(element:).update_element!(uuid: response.id)
      end
    end

  ElementService.new(element_version:).update_element_version!(
    nev_status: :synced,
    etag: response.etag,
    payload: response.payload
  )
rescue Errors::ConflictingRemoteElementChange => e
  Nexo.logger.warn "    ConflictingRemoteElementChange for \#{element.to_gid}. \\\n    Enqueuing FetchRemoteResourceJob, which should lead to conflicted element\n  STR\n  FetchRemoteResourceJob.perform_later(element)\nend\n"