This repository has been archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: add notify handler for punch fails (aliyun fc) (#27)
* feat: support task fail notify * ci: add notify builder * build: bump github.com/yin1999/healthreport to 1.3.4 * fix ci
- Loading branch information
Showing
10 changed files
with
95 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# binary file | ||
tencent-serverless.zip | ||
aliyun-serverless.zip | ||
*-serverless.zip | ||
|
||
# config file | ||
/.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//go:build aliyun || !tencent | ||
//go:build aliyun || !tencent || notify | ||
|
||
package main | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
//go:build notify | ||
|
||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
"strconv" | ||
"strings" | ||
"time" | ||
|
||
"github.com/yin1999/healthreport/utils/email" | ||
) | ||
|
||
var emailCfg *email.Config | ||
|
||
func init() { | ||
port, err := strconv.Atoi(os.Getenv("PORT")) | ||
if err != nil { | ||
panic(err) | ||
} | ||
emailCfg = &email.Config{ | ||
To: strings.Split(os.Getenv("TO"), ","), | ||
SMTP: email.SmtpConfig{ | ||
Host: os.Getenv("HOST"), | ||
Port: port, | ||
TLS: os.Getenv("TLS") == "true", | ||
Username: os.Getenv("USERNAME"), | ||
Password: os.Getenv("PASSWORD"), | ||
}, | ||
} | ||
} | ||
|
||
func main() { | ||
h, err := regist() | ||
if err != nil { | ||
os.Exit(1) | ||
} | ||
startServe(h) | ||
} | ||
|
||
type message struct { | ||
ResponsePayload string | ||
} | ||
|
||
func startServe(handler handler) { | ||
for { | ||
body, id, err := handler.Next() | ||
if err != nil { | ||
Error.Log("get trigger payload failed, err: %s\n", err.Error()) | ||
continue | ||
} | ||
t := &message{} | ||
err = json.NewDecoder(body).Decode(t) | ||
body.Close() // close body | ||
if err != nil { | ||
msg := "parse request body failed, err: " + err.Error() | ||
Error.Log(msg + "\n") | ||
handler.ReportError(msg, id) | ||
continue | ||
} | ||
err = emailCfg.Send("打卡状态推送", fmt.Sprintf("打卡状态推送-%s", | ||
time.Now().Format("2006-01-02")), | ||
fmt.Sprintf("打卡失败: %s ", t.ResponsePayload)) | ||
if err != nil { | ||
handler.ReportError(err.Error(), id) | ||
} else { | ||
handler.ReportSuccess(id) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package main | ||
|
||
import "io" | ||
|
||
type handler interface { | ||
Next() (body io.ReadCloser, reqID string, err error) | ||
ReportError(msg string, id string) | ||
ReportSuccess(id string) | ||
} |