User bio
404 bio not found
Member since Nov 9, 2015
Pinned posts:
Replies:

A relevant note / tool I (re-?)discovered today: for critical sequences where an interrupt could leave the system in an inconsistent state, you can use the BREAK command to disable/enable Ctrl+C.

See: https://docs.intersystems.com/iris20191/csp/docbook/DocBook.UI.Page.cls?...

Here's some sample code covering both the "tracking variable" and "destructor" patterns:

Class TSL.Breakfest Extends %RegisteredObject
{
 
ClassMethod Run()
{
	Set initialInterruptState = $ZJob\4#2
	Try {
		// Should be able to break during this
		Hang 5
		Set e = 1/0
	} Catch e {
		// Should not be able to break starting here.
		Break 0
		Write !,"bad stuff happened"
		Hang 2
	}
	Break 0
	// Should not be able to break during this
	Hang 2
	Write !,"Got to the end of the critical cleanup step."
	Break initialInterruptState
}
 
ClassMethod RunObject()
{
	Set inst = ..%New()
	Hang 2
	Write !,"Killing inst..."
	Kill inst
}
 
/// This callback method is invoked by the <METHOD>%Close</METHOD> method to 
/// provide notification that the current object is being closed.
/// 
/// <P>The return value of this method is ignored.
Method %OnClose() As %Status [ Private, ServerOnly = 1 ]
{
	Set initialInterruptState = $ZJob\4#2
	// Concern: what if the <INTERRUPT> hits exactly here between Set and Break? Extremely hard to test. Not sure if this could happen.
	Break 0
	Hang 2
	Write !,"Finished %OnClose"
	Break initialInterruptState
	Quit $$$OK
}
 
}

Ended up writing my own based on https://github.com/intersystems/isc-json/blob/main/cls/_pkg/isc/json/path.cls which implements https://goessner.net/articles/JsonPath/ - syntax looks like this, where inputObject and result are both %DynamicAbstractObjects:

    Set result = ##class(%pkg.isc.json.transformer).For(inputObject
        ).Remove("$..url" // Remove URL
        ).Remove("$..requested_fields" // Remove requested_fields
        ).Remove("$..[?($IsObject(@) && (@.%Size() = 0))]" // Remove empty arrays/objects
        ).Remove("$..[?($IsObject(@) && (@.%Size() = 1) && (@.%GetTypeOf(1) = ""null""))]" // Remove one-element arrays containing only a null
        ).TransformElement("$..issue_type","$.name" // Replace issue type object with just the name
        ).TransformElement("$..priority","$.name" // Replace priority object with just the name
        ).TransformElement("$..status","$.name" // Replace status object with just the name
        ).TransformElement("$..[?($IsObject(@) && @.%IsA(""%DynamicObject"") && (@.""avatar_url"" '= """"))]","$.display_name" // Replace any user (indicated by avatar_url) with just the user's display name
        ).GetResult()

I'll probably get this into https://github.com/intersystems/isc-json at some point (subject to some process hurdles); if you're interested nag me here / via DM.

Open Exchange applications:
Certifications & Credly badges:
Global Masters badges:
Followers:
Following: