Skip to content

Conversation

@LeticiaErrandonea
Copy link
Collaborator

Notes

  • Make instruments sharing relay update status at the same time

NU-450 | Relay check update for shared schedules

Comment on lines 51 to 53
Relay.unscoped
.where(host:, outlet:, ip_port:)
.where.not(id: nil) # Exclude unsaved records
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can just be Relay.where(host:, outlet:, ip_port:)

Comment on lines 51 to 53
valid_instruments = shared_instruments.select do |inst|
inst.id.present? && inst.relay&.networked_relay?
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can safely assume all relays returned are valid. I don't see why the instrument id would be blank or there would be non-network relays with a host

Comment on lines 69 to 75
missing_ids.each do |inst_id|
missing_instrument = valid_instruments.find { |inst| inst.id == inst_id }
next unless missing_instrument

status = find_or_initialize_by(instrument: missing_instrument)
status.update!(is_on:, updated_at: now)
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: missing_ids.each { |instrument_id| find_or_initialize_by(instrument_id:).update(is_on:, updated_at: no) }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants