fix(mulesoft/exporter): status vars, perf, style, format#173
Conversation
* fix(mdc): calculate correct checksums * chore(mdc): calculate and verify checksum inline
* fix type mismatch between switcher size and IO * fix missing parser reference
posts booking information to a URL
also reject very old data
Looks good to me, thanks!
* feat(hitachi): initial projector commit * feat(hitachi): add basic spec * fix(hitachi): remove whitespace before conversion * fix(hitachi): move internal states to instance vars * feat(hitachi): add specs for connected * feat(hitachi): add more specs * chore(hitachi): run crystal tool format * fix(hitachi): remove stable instance vars * chore(hitachi_proj): neaten logs Co-authored-by: Caspian Baska <caspianbaska@gmail.com> * fix(hitachi_proj): use QueryRequests from driver * refactor(hitachi_proj): store all commands in NamedTuple * chore(hitachi_proj): crystal tool format * fix(hitachi_proj): don't use class method Co-authored-by: Caspian Baska <caspianbaska@gmail.com>
for implementing custom services
fixes office365 groups requests
adds support for mapping groups onto user accounts
* feat(smtp): add setting to ignore cert validation * fix(smtp): add check for setting to ignore ssl verify
* build(shard.lock): bump driver and exec_from * build(Dockerfile): improve layer caching * ci(github): add github ci * ci(github): use `docker exec` instead of `docker-compose exec` * ci(docker-compose): mount .git for purpose of server specs
* fix: clear schedules on connect to test if disconnect is not being called * fix(nexia): clear schedule on connect Co-authored-by: Viv Briffa <viv@place.technology>
| subscription = system.subscribe(:Bookings_1, :bookings) do |_subscription, mulesoft_bookings| | ||
| logger.debug { "DETECTED changed in Mulesoft Bookings.." } | ||
| logger.debug { "DETECTED change in Mulesoft Bookings..." } | ||
| @bookings = Array(Hash(String, Int64 | String | Nil)).from_json(mulesoft_bookings) |
There was a problem hiding this comment.
Doing something along these lines instead of the Hash would be much easier to maintain, faster, and ensures correctness
record MulesoftBooking,
getter title : String?,
getter recurring_master_id : Int64,
getter event_start : Int64,
getter event_end : Int64,
getter body : String do
include JSON::Serializable
@[JSON::Field(ignore: true)]
# Not sure about the efficiency of doing this pattern in a struct.
getter resolved_title : String do
"#{recurring_master_id} #{title.presence || body}"
end
def matches?(booking)
booking = booking.as_h if booking.is_a?(JSON::Any)
event_start == booking["event_start"]? && event_end == booking["event_end"]? && resolved_title == booking["title"]?
end
def to_place_calendar(
timezone : String,
system_email : String,
system_name : String,
)
{
title: resolved_title,
event_start: event_start,
event_end: event_end,
timezone: timezone,
description: body,
user_id: system_email,
location: system_name,
attendees: [{email: system_email, name: system_name}],
}
end
endThere was a problem hiding this comment.
Thanks so much, I'll grok this after some other tasks, then see if anything else should change and then test.
Yeah I was originally intending the booking hash and calendar event to be the same object but couldn't get that to work just due to my crystal inexperience. Ran out of time due to a delivery deadline so just implemented it this way.
Now that I have time it'll be great (and very educational for me) to implement it properly.
| subscription = system.subscribe(:Bookings_1, :bookings) do |_subscription, mulesoft_bookings| | ||
| logger.debug { "DETECTED changed in Mulesoft Bookings.." } | ||
| logger.debug { "DETECTED change in Mulesoft Bookings..." } | ||
| @bookings = Array(Hash(String, Int64 | String | Nil)).from_json(mulesoft_bookings) |
There was a problem hiding this comment.
| @bookings = Array(Hash(String, Int64 | String | Nil)).from_json(mulesoft_bookings) | |
| @bookings = Array(MulesoftBooking).from_json(mulesoft_bookings) |
| location: system.name.not_nil!, | ||
| } | ||
| logger.debug { ">>> EXPORTING booking #{new_event}" } | ||
| logger.debug { ">>> EXPORTING booking as: #{new_event}" } |
There was a problem hiding this comment.
protected def export_booking(booking : MulesoftBooking)
unless event_already_exists?(booking, @existing_events)
new_event = booking.to_place_calendar(@time_zone_string, system.email, system.name)
logger.debug { ">>> EXPORTING booking as: #{new_event}" }
calendar.create(**new_event)
end
end| protected def event_already_exists?(booking : Hash(String, Int64 | String | Nil), existing_events : Array(JSON::Any)) | ||
| existing_events.any? { |existing_event| booking_matches_event?(booking, existing_event.as_h) } | ||
| end | ||
|
|
||
| protected def events_match?(event_a : Hash(String, Int64 | String | Nil), event_b : Hash(String, JSON::Any)) | ||
| event_a.select("event_start", "event_end", "title") == event_b.select("event_start", "event_end", "title") | ||
| protected def booking_matches_event?(booking : Hash(String, Int64 | String | Nil), event : Hash(String, JSON::Any)) | ||
| booking.select("event_start", "event_end", "title") == event.select("event_start", "event_end", "title") | ||
| end |
There was a problem hiding this comment.
protected def event_already_exists?(booking : MulesoftBooking, existing_events : Array(JSON::Any))
logger.debug { "Checking for existing events that match: #{booking.resolved_title}" }
existing_events.any? { |event| booking.matches?(event) }
end|
@w-le I can whack in the suggestions I made if that's good for you? |
c8f3f18 to
a5f35f4
Compare
Thanks for these recommendations! The changes here should address them. Do let me know if anything else.
Apologies for committing directly to main branch instead of a PR from feat>main. I was in the middle of a client deployment change window and realised that the UAT instance was running off my fork of drivers while the PROD instance was on placeos/drivers. Will make sure to have new drivers reviewed in a PR PRIOR to deployments in the future.