Skip to content

Commit

Permalink
Fixed issue with started and error email templates from #2
Browse files Browse the repository at this point in the history
- Added the CachedFieldTypeFromName function which returns the CachedFieldType from the given name (19/04/2023 - 11:15:26)
- Added the ScoutState.GetIterableCachedFieldFromName + ScoutState.GetCachedFieldFromName methods to ScoutScate that utilise the CachedFieldTypeFromName function (19/04/2023 - 11:16:09)
- Updated the started and error email templates to use these new methods rather than passing in the underlying integer representing a CachedFieldType (19/04/2023 - 11:16:56)
  • Loading branch information
andygello555 committed Apr 19, 2023
1 parent 374822e commit dad6a30
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
20 changes: 20 additions & 0 deletions cached_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -1057,3 +1057,23 @@ func (cft CachedFieldType) Types() []CachedFieldType {
StateType,
}
}

// CachedFieldTypeFromName returns the CachedFieldType whose name is the given string. This is a case-insensitive match.
func CachedFieldTypeFromName(name string) CachedFieldType {
switch strings.ToLower(name) {
case "usertweettimestype":
return UserTweetTimesType
case "reddituserposttimestype":
return RedditUserPostTimesType
case "developersnapshotstype":
return DeveloperSnapshotsType
case "redditdevelopersnapshotstype":
return RedditDeveloperSnapshotsType
case "gameidstype":
return GameIDsType
case "deleteddeveloperstype":
return DeletedDevelopersType
default:
return StateType
}
}
8 changes: 4 additions & 4 deletions email/templates/error.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{ $start := mustGet (.State.GetCachedField 4) "Start" }}
{{ $batchSize := mustGet (.State.GetCachedField 4) "BatchSize" }}
{{ $discoveryTweets := mustGet (.State.GetCachedField 4) "DiscoveryTweets" }}
{{ $phase := mustGet (.State.GetCachedField 4) "Phase" }}
{{ $start := mustGet (.State.GetCachedFieldFromName "State") "Start" }}
{{ $batchSize := mustGet (.State.GetCachedFieldFromName "State") "BatchSize" }}
{{ $discoveryTweets := mustGet (.State.GetCachedFieldFromName "State") "DiscoveryTweets" }}
{{ $phase := mustGet (.State.GetCachedFieldFromName "State") "Phase" }}
Robo-scout has encountered an error during the Scout procedure which started at {{ stamp $start }} with batchSize = {{ $batchSize }}, and discoveryTweets = {{ $discoveryTweets }}.

The error occurred in the {{ $phase.String }} phase at {{ stamp .Time }}:
Expand Down
6 changes: 3 additions & 3 deletions email/templates/started.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{ $start := mustGet (.State.GetCachedField 4) "Start" }}
{{ $batchSize := mustGet (.State.GetCachedField 4) "BatchSize" }}
{{ $discoveryTweets := mustGet (.State.GetCachedField 4) "DiscoveryTweets" }}
{{ $start := mustGet (.State.GetCachedFieldFromName "State") "Start" }}
{{ $batchSize := mustGet (.State.GetCachedFieldFromName "State") "BatchSize" }}
{{ $discoveryTweets := mustGet (.State.GetCachedFieldFromName "State") "DiscoveryTweets" }}
Robo-scout has started the Scout procedure at {{ stamp $start }} with batchSize = {{ $batchSize }}, and discoveryTweets = {{ $discoveryTweets }}.

{{ if .State.Loaded }}Current state was loaded from disk:{{ else }}Current state was just created, so we are probably starting from scratch today:{{ end }}
Expand Down
12 changes: 12 additions & 0 deletions state.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ func (state *ScoutState) GetCachedField(fieldType CachedFieldType) CachedField {
return state.cachedFields[fieldType]
}

// GetCachedFieldFromName will return the CachedField of the given name of a CachedFieldType using
// CachedFieldTypeFromName.
func (state *ScoutState) GetCachedFieldFromName(fieldTypeName string) CachedField {
return state.cachedFields[CachedFieldTypeFromName(fieldTypeName)]
}

// GetIterableCachedFields will return a mapping of all the CachedField that are IterableCachedField. The mapping will
// have keys that are CachedFieldType.
func (state *ScoutState) GetIterableCachedFields() map[CachedFieldType]IterableCachedField {
Expand All @@ -93,6 +99,12 @@ func (state *ScoutState) GetIterableCachedField(fieldType CachedFieldType) Itera
return state.GetCachedField(fieldType).(IterableCachedField)
}

// GetIterableCachedFieldFromName will return the IterableCachedField of the given name of a CachedFieldType using
// CachedFieldTypeFromName.
func (state *ScoutState) GetIterableCachedFieldFromName(fieldTypeName string) IterableCachedField {
return state.GetCachedFieldFromName(fieldTypeName).(IterableCachedField)
}

// MergeIterableCachedFields will merge each IterableCachedField in the given ScoutState into the referred to ScoutState
// using the IterableCachedField.Merge method.
func (state *ScoutState) MergeIterableCachedFields(stateToMerge *ScoutState) {
Expand Down

0 comments on commit dad6a30

Please sign in to comment.