Skip to content

Commit

Permalink
Merge pull request #105 from intersystems-community/stage
Browse files Browse the repository at this point in the history
changed the way code extension
  • Loading branch information
nsolov authored Aug 20, 2023
2 parents 336b9b1 + a135d19 commit 3d9b15a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/trigger-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ on:
jobs:
trigger-zpm-deployment:
name: Trigger zpm-registry-deployment via REST API
runs-on: ubuntu-latest

runs-on: ubuntu-22.04
steps:
- name: REST POST call
run: |-
Expand Down
29 changes: 29 additions & 0 deletions src/cls/ZPM/Analytics/AbstractEventProcessor.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/// To execute your code immediately after the event occurs,
/// you need to create a subclass of this class and override the Process() method in it.
Class ZPM.Analytics.AbstractEventProcessor [ Abstract ]
{

Parameter SubClasses As CONFIGVALUE;

/// Override this method to run your code when event occurs
ClassMethod Process(event as ZPM.Analytics.Event) As %Status [ Abstract ]
{
Return $$$OK
}

/// Do not change or override this method
ClassMethod getSubClasses() As %String [ CodeMode = objectgenerator ]
{
Set list = ""

Set rs = ##class(%Dictionary.ClassDefinitionQuery).SubclassOfFunc("ZPM.Analytics.AbstractEventProcessor")
While (rs.%Next()) {
Set list = list _ $listbuild( rs.%GetData(1) )
}

Do $system.OBJ.UpdateConfigParam("ZPM.Analytics.AbstractEventProcessor","SubClasses",$listtostring(list,","))
Do %code.WriteLine(" return $PARAMETER(""ZPM.Analytics.AbstractEventProcessor"",""SubClasses"") ")
Return $$$OK
}

}
23 changes: 18 additions & 5 deletions src/cls/ZPM/Analytics/Event.cls
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Class ZPM.Analytics.Event Extends (%Persistent, %JSON.Adaptor)

Parameter DSTIME = "AUTO";

/// Server date and time, saving the data
/// Server date and time, saving the data
Property TS As %PosixTime(%JSONINCLUDE = "none") [ SqlComputeCode = {set {*}=##class(%Library.PosixTime).CurrentTimeStamp()}, SqlComputed, SqlComputeOnChange = %%INSERT ];

/// Event type: download, install, uninstall
Expand Down Expand Up @@ -40,6 +40,22 @@ Property Region As %String(%JSONINCLUDE = "none");

Property City As %String(%JSONINCLUDE = "none");

ClassMethod ExecuteEventProcessors(event As ZPM.Analytics.Event) As %Status
{
Set subclasses = $PARAMETER("ZPM.Analytics.AbstractEventProcessor","SubClasses")
Set list = $ListFromString(subclasses,",")
For i=1:1:$listlength(list){
Try {
$$$ThrowOnError($Classmethod($listget(list,i), "Process", event))
} Catch ex {
If (ex.Name '= "<CLASS DOES NOT EXIST>") {
Throw ex
}
}
}
return $$$OK
}

ClassMethod SaveEvent(action As %String, ip As %String = "", json As %DynamicObject) As %Status
{
Try {
Expand All @@ -48,10 +64,7 @@ ClassMethod SaveEvent(action As %String, ip As %String = "", json As %DynamicObj
Set event.IP = ip
Do event.%JSONImport(json)
$$$ThrowOnError(event.%Save())
If ##class(%Dictionary.CompiledClass).%ExistsId("ZPM.Analytics.IP") {
Do ##class(ZPM.Analytics.IP).SetGeo(event, ip)
}
$$$ThrowOnError(event.%Save())
$$$ThrowOnError(..ExecuteEventProcessors(event))
Return $$$OK
} Catch ex {
Do ex.Log()
Expand Down

0 comments on commit 3d9b15a

Please sign in to comment.