Skip to content

fix(mulesoft/exporter): status vars, perf, style, format#173

Draft
w-le wants to merge 646 commits into
masterfrom
fix/mulesoft_exporter
Draft

fix(mulesoft/exporter): status vars, perf, style, format#173
w-le wants to merge 646 commits into
masterfrom
fix/mulesoft_exporter

Conversation

@w-le
Copy link
Copy Markdown
Contributor

@w-le w-le commented May 24, 2021

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.

pkheav and others added 30 commits November 30, 2020 13:31
* 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
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
stakach and others added 7 commits May 4, 2021 09:25
* 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>
@w-le w-le self-assigned this May 24, 2021
@w-le w-le requested a review from caspiano May 24, 2021 14:36
Comment thread drivers/mulesoft/calendar_exporter.cr
caspiano
caspiano previously approved these changes May 25, 2021
Comment thread drivers/mulesoft/calendar_exporter.cr Outdated
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)
Copy link
Copy Markdown
Contributor

@caspiano caspiano Jun 2, 2021

Choose a reason for hiding this comment

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

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
end

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
@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}" }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Comment on lines +99 to 105
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
Copy link
Copy Markdown
Contributor

@caspiano caspiano Jun 2, 2021

Choose a reason for hiding this comment

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

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

@caspiano
Copy link
Copy Markdown
Contributor

@w-le I can whack in the suggestions I made if that's good for you?

@caspiano caspiano added the type: enhancement new feature or request label Jul 11, 2021
@w-le w-le requested review from caspiano and removed request for caspiano September 22, 2023 06:10
@w-le w-le marked this pull request as draft September 22, 2023 06:10
@w-le w-le requested a review from KesterJJ September 22, 2023 06:11
@stakach stakach force-pushed the fix/mulesoft_exporter branch from c8f3f18 to a5f35f4 Compare May 8, 2026 01:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.