Skip to content

Commit

Permalink
0.5.7, async insert into db and async slack msg...
Browse files Browse the repository at this point in the history
  • Loading branch information
gernotstarke committed Feb 3, 2024
1 parent d561329 commit 169c8ca
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 16. use Slack to inform user about important system events

Date: 2024-02-02

## Status

Accepted

## Context

Requirement F-004 requires the owners of the system to be informed about important system events.

## Decision

Such important events are "system startup" and "acquisition of usage and repository data".
These shall be sent to a Slack channel to notify the owners.

## Consequences

- Slack app to be created
- [Slack API](https://pkg.go.dev/github.com/slack-go/[email protected]#section-readme) to be used
- Slack OAuth Token to be set at fly.io
13 changes: 12 additions & 1 deletion documentation/arc42/chapters/01_introduction_and_goals.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,22 @@ ifndef::imagesdir[:imagesdir: ../../images]

=== Requirements Overview

[glossary]
F-001:: publish current usage statistics of arc42 websites

F-002:: publish current repository statistics (like issues, bugs) of arc42 websites

F-003:: store important results and events persistently for future reference

F-004:: inform owners of important system events

=== Quality Goals

* Environmental friendly: Reduce computing resources used as much as possible.
[glossary]

Q-001:: Environmental friendly: Reduce computing resources used as much as possible.

Q-002:: Available: statics are available via the website 24x7. Short periods (hours) of downtime can be allowed, in such cases cached or dated results shall be displayed.


=== Stakeholders
Expand Down
51 changes: 22 additions & 29 deletions documentation/images/06-system-startup.puml
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,29 @@
'https://plantuml.com/activity-diagram-beta

start
:ClickServlet.handleRequest();
:new page;
if (Page.onSecurityCheck) then (true)
:Page.onInit();
if (isForward?) then (no)
:Process controls;
if (continue processing?) then (no)
stop
endif

if (isPost?) then (yes)
:Page.onPost();
else (no)
:Page.onGet();
endif
:Page.onRender();
endif
else (false)
endif

if (do redirect?) then (yes)
:redirect process;
else
if (do forward?) then (yes)
:Forward request;
else (no)
:Render page template;
endif
endif
:init logger, db, cache;

:siteStats = loadStats();

:cache siteStats, expiry 10min;

:repoStats = loadRepoStats();
:cache repoStats, expiry 1min;

stop
group API Server Process
:apiGateway.StartAPIServer();

detach

:wait for http request;

if (External Event occurs) then (yes)
:execute method B;
else (no)
:skip method B;
endif

end group
:finalize process;
@enduml
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 3 additions & 4 deletions go-app/internal/api/apiGateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,12 @@ func statsHTMLTableHandler(w http.ResponseWriter, r *http.Request) {
domain.ArcStats.FlyRegion, domain.ArcStats.WhereDoesItRun = fly.RegionAndLocation()

// 4. store request params in database
// TODO: make this async
// TODO: include real IP address
database.SaveInvocationParams(r.Host, r.RequestURI)
go database.SaveInvocationParams(r.Host, r.RequestURI)

// 4b: inform owner via Slack
// 4b: inform the owner via Slack
msg := fmt.Sprintf("Loaded arc42 statistics in %sms on %s", domain.ArcStats.HowLongDidItTake, time.Now().Format("02 Jan 15:04"))
slack.SendSlackMessage(msg)
go slack.SendSlackMessage(msg)

// 5. finally, render the template
executeTemplate(w, filepath.Join(TemplatesDir, HtmlTableTmpl), domain.ArcStats)
Expand Down
3 changes: 2 additions & 1 deletion go-app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"time"
)

const appVersion = "0.5.6"
const appVersion = "0.5.7"

// version history
// 0.5.x rate limit: limit amount of queries to external APIs
Expand All @@ -22,6 +22,7 @@ const appVersion = "0.5.6"
// 0.5.4: start with empty table on homepage
// 0.5.5: caching with zcache
// 0.5.6: send slack message for important system events, starting with data acquisition
// 0.5.7: performance optimization, initial database insert and Slack message now async
// 0.4.7 replace most inline styles by css
// 0.4.6 sortable table (a: initial, b...e: fix layout issues), f: fix #94
// 0.4.5 fix missing separators in large numbers
Expand Down

0 comments on commit 169c8ca

Please sign in to comment.