Increase RequestMaxRetry and decrease RequestRetrySleep (also remove CreateChanel struct from 77cfe750)
All checks were successful
Build Docker and Deploy / Build Docker Container (push) Successful in 1m37s
Build Docker and Deploy / Deploy to Server (push) Successful in 10s

This commit is contained in:
Mike Schwörer 2024-05-26 19:30:13 +02:00
parent 77cfe75043
commit 97a834ae6a
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
6 changed files with 321 additions and 230 deletions

View File

@ -4,7 +4,6 @@ import (
"blackforestbytes.com/simplecloudnotifier/api/apierr"
"blackforestbytes.com/simplecloudnotifier/api/ginresp"
ct "blackforestbytes.com/simplecloudnotifier/db/cursortoken"
"blackforestbytes.com/simplecloudnotifier/db/impl/primary"
"blackforestbytes.com/simplecloudnotifier/models"
"database/sql"
"errors"
@ -236,15 +235,7 @@ func (h APIHandler) CreateChannel(g *gin.Context) ginresp.HTTPResponse {
subscribeKey := h.app.GenerateRandomAuthKey()
cChannel := primary.CreateChanel{
UserId: u.UserID,
IntName: channelInternalName,
SubscribeKey: subscribeKey,
DisplayName: channelDisplayName,
Description: b.Description,
}
channel, err := h.database.CreateChannel(ctx, cChannel)
channel, err := h.database.CreateChannel(ctx, u.UserID, channelDisplayName, channelInternalName, subscribeKey, b.Description)
if err != nil {
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to create channel", err)
}

View File

@ -395,8 +395,8 @@ var configProd = func() Config {
EnableLogger: true,
},
RequestTimeout: 16 * time.Second,
RequestMaxRetry: 8,
RequestRetrySleep: 100 * time.Millisecond,
RequestMaxRetry: 32,
RequestRetrySleep: 32 * time.Millisecond,
ReturnRawErrors: false,
DummyFirebase: false,
FirebaseTokenURI: "https://oauth2.googleapis.com/token",

View File

@ -66,7 +66,7 @@ type CreateChanel struct {
Description *string
}
func (db *Database) CreateChannel(ctx db.TxContext, channel CreateChanel) (models.Channel, error) {
func (db *Database) CreateChannel(ctx db.TxContext, userid models.UserID, dispName string, intName string, subscribeKey string, description *string) (models.Channel, error) {
tx, err := ctx.GetOrCreateTransaction(db)
if err != nil {
return models.Channel{}, err
@ -74,11 +74,11 @@ func (db *Database) CreateChannel(ctx db.TxContext, channel CreateChanel) (model
entity := models.ChannelDB{
ChannelID: models.NewChannelID(),
OwnerUserID: channel.UserId,
DisplayName: channel.DisplayName,
InternalName: channel.IntName,
SubscribeKey: channel.SubscribeKey,
DescriptionName: channel.Description,
OwnerUserID: userid,
DisplayName: dispName,
InternalName: intName,
SubscribeKey: subscribeKey,
DescriptionName: description,
TimestampCreated: time2DB(time.Now()),
TimestampLastSent: nil,
MessagesSent: 0,

View File

@ -4,7 +4,6 @@ import (
scn "blackforestbytes.com/simplecloudnotifier"
"blackforestbytes.com/simplecloudnotifier/api/apierr"
"blackforestbytes.com/simplecloudnotifier/api/ginresp"
"blackforestbytes.com/simplecloudnotifier/db/impl/primary"
"blackforestbytes.com/simplecloudnotifier/db/simplectx"
"blackforestbytes.com/simplecloudnotifier/google"
"blackforestbytes.com/simplecloudnotifier/models"
@ -332,13 +331,7 @@ func (app *Application) GetOrCreateChannel(ctx *AppContext, userid models.UserID
subscribeKey := app.GenerateRandomAuthKey()
channel := primary.CreateChanel{
UserId: userid,
IntName: intChanName,
SubscribeKey: subscribeKey,
DisplayName: displayChanName,
}
newChan, err := app.Database.Primary.CreateChannel(ctx, channel)
newChan, err := app.Database.Primary.CreateChannel(ctx, userid, displayChanName, intChanName, subscribeKey, nil)
if err != nil {
return models.Channel{}, err
}

View File

@ -958,13 +958,13 @@
}
},
"/api/v2/messages/{mid}": {
"delete": {
"description": "The user must own the message and request the resource with the ADMIN Key",
"get": {
"description": "The user must either own the message and request the resource with the READ or ADMIN Key\nOr the user must subscribe to the corresponding channel (and be confirmed) and request the resource with the READ or ADMIN Key\nThe returned message is never trimmed",
"tags": [
"API-v2"
],
"summary": "Delete a single message",
"operationId": "api-messages-delete",
"summary": "Get a single message (untrimmed)",
"operationId": "api-messages-get",
"parameters": [
{
"type": "string",
@ -1007,13 +1007,13 @@
}
}
},
"patch": {
"description": "The user must either own the message and request the resource with the READ or ADMIN Key\nOr the user must subscribe to the corresponding channel (and be confirmed) and request the resource with the READ or ADMIN Key\nThe returned message is never trimmed",
"delete": {
"description": "The user must own the message and request the resource with the ADMIN Key",
"tags": [
"API-v2"
],
"summary": "Get a single message (untrimmed)",
"operationId": "api-messages-get",
"summary": "Delete a single message",
"operationId": "api-messages-delete",
"parameters": [
{
"type": "string",
@ -2449,6 +2449,104 @@
}
}
},
"/external/v1/uptime-kuma": {
"post": {
"description": "All parameter can be set via query-parameter or the json body. Only UserID, UserKey and Title are required",
"tags": [
"External"
],
"summary": "Send a new message",
"parameters": [
{
"type": "string",
"name": "channel",
"in": "query"
},
{
"type": "string",
"name": "channel_down",
"in": "query"
},
{
"type": "string",
"name": "channel_up",
"in": "query"
},
{
"type": "string",
"example": "P3TNH8mvv14fm",
"name": "key",
"in": "query"
},
{
"type": "integer",
"name": "priority",
"in": "query"
},
{
"type": "integer",
"name": "priority_down",
"in": "query"
},
{
"type": "integer",
"name": "priority_up",
"in": "query"
},
{
"type": "string",
"name": "senderName",
"in": "query"
},
{
"type": "string",
"example": "7725",
"name": "user_id",
"in": "query"
},
{
"description": " ",
"name": "post_body",
"in": "body",
"schema": {
"$ref": "#/definitions/handler.UptimeKuma.body"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/handler.UptimeKuma.response"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/ginresp.apiError"
}
},
"401": {
"description": "The user_id was not found or the user_key is wrong",
"schema": {
"$ref": "#/definitions/ginresp.apiError"
}
},
"403": {
"description": "The user has exceeded its daily quota - wait 24 hours or upgrade your account",
"schema": {
"$ref": "#/definitions/ginresp.apiError"
}
},
"500": {
"description": "An internal server error occurred - try again later",
"schema": {
"$ref": "#/definitions/ginresp.apiError"
}
}
}
}
},
"/send": {
"post": {
"description": "All parameter can be set via query-parameter or the json body. Only UserID, UserKey and Title are required",
@ -2629,72 +2727,120 @@
"parameters": [
{
"type": "string",
"example": "test",
"name": "channel",
"in": "query"
},
{
"type": "string",
"example": "This is a message",
"name": "content",
"in": "query"
},
{
"type": "string",
"example": "P3TNH8mvv14fm",
"name": "key",
"in": "query"
},
{
"type": "string",
"example": "db8b0e6a-a08c-4646",
"name": "msg_id",
"in": "query"
},
{
"enum": [
0,
1,
2
],
"type": "integer",
"example": 1,
"name": "priority",
"in": "query"
},
{
"type": "string",
"example": "example-server",
"name": "sender_name",
"in": "query"
},
{
"type": "number",
"example": 1669824037,
"name": "timestamp",
"in": "query"
},
{
"type": "string",
"example": "Hello World",
"name": "title",
"in": "query"
},
{
"type": "integer",
"type": "string",
"example": "7725",
"name": "user_id",
"in": "query"
},
{
"type": "string",
"name": "user_key",
"in": "query"
"example": "test",
"name": "channel",
"in": "formData"
},
{
"type": "string",
"example": "This is a message",
"name": "content",
"in": "formData"
},
{
"type": "string",
"example": "P3TNH8mvv14fm",
"name": "key",
"in": "formData"
},
{
"type": "string",
"example": "db8b0e6a-a08c-4646",
"name": "msg_id",
"in": "formData"
},
{
"enum": [
0,
1,
2
],
"type": "integer",
"example": 1,
"name": "priority",
"in": "formData"
},
{
"type": "string",
"example": "example-server",
"name": "sender_name",
"in": "formData"
},
{
"type": "number",
"example": 1669824037,
"name": "timestamp",
"in": "formData"
},
{
"type": "string",
"example": "Hello World",
"name": "title",
"in": "formData"
},
{
"type": "integer",
"name": "user_id",
"in": "formData"
},
{
"type": "string",
"name": "user_key",
"example": "7725",
"name": "user_id",
"in": "formData"
}
],
@ -2702,7 +2848,7 @@
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/handler.SendMessageCompat.response"
"$ref": "#/definitions/handler.SendMessage.response"
}
},
"400": {
@ -2731,69 +2877,6 @@
}
}
}
},
"/webhook/uptime-kuma": {
"post": {
"description": "All parameter can be set via query-parameter or the json body. Only UserID, UserKey and Title are required",
"tags": [
"External"
],
"summary": "Send a new message",
"parameters": [
{
"type": "string",
"example": "P3TNH8mvv14fm",
"name": "key",
"in": "query"
},
{
"type": "string",
"example": "7725",
"name": "user_id",
"in": "query"
},
{
"description": " ",
"name": "post_body",
"in": "body",
"schema": {
"$ref": "#/definitions/handler.UptimeKumaWebHook.uptimeKumaWebhookBody"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/ginresp.apiError"
}
},
"401": {
"description": "The user_id was not found or the user_key is wrong",
"schema": {
"$ref": "#/definitions/ginresp.apiError"
}
},
"403": {
"description": "The user has exceeded its daily quota - wait 24 hours or upgrade your account",
"schema": {
"$ref": "#/definitions/ginresp.apiError"
}
},
"500": {
"description": "An internal server error occurred - try again later",
"schema": {
"$ref": "#/definitions/ginresp.apiError"
}
}
}
}
}
},
"definitions": {
@ -2964,6 +3047,9 @@
"handler.CreateChannel.body": {
"type": "object",
"properties": {
"description": {
"type": "string"
},
"name": {
"type": "string"
},
@ -3323,41 +3409,6 @@
}
}
},
"handler.SendMessageCompat.response": {
"type": "object",
"properties": {
"errhighlight": {
"type": "integer"
},
"error": {
"$ref": "#/definitions/apierr.APIError"
},
"is_pro": {
"type": "boolean"
},
"message": {
"type": "string"
},
"messagecount": {
"type": "integer"
},
"quota": {
"type": "integer"
},
"quota_max": {
"type": "integer"
},
"scn_msg_id": {
"type": "integer"
},
"success": {
"type": "boolean"
},
"suppress_send": {
"type": "boolean"
}
}
},
"handler.Sleep.response": {
"type": "object",
"properties": {
@ -3449,7 +3500,7 @@
}
}
},
"handler.UptimeKumaWebHook.uptimeKumaWebhookBody": {
"handler.UptimeKuma.body": {
"type": "object",
"properties": {
"heartbeat": {
@ -3461,6 +3512,9 @@
"msg": {
"type": "string"
},
"status": {
"type": "integer"
},
"time": {
"type": "string"
},
@ -3488,6 +3542,14 @@
}
}
},
"handler.UptimeKuma.response": {
"type": "object",
"properties": {
"message_id": {
"type": "string"
}
}
},
"handler.pingResponse": {
"type": "object",
"properties": {

View File

@ -139,6 +139,8 @@ definitions:
type: object
handler.CreateChannel.body:
properties:
description:
type: string
name:
type: string
subscribe:
@ -376,29 +378,6 @@ definitions:
suppress_send:
type: boolean
type: object
handler.SendMessageCompat.response:
properties:
errhighlight:
type: integer
error:
$ref: '#/definitions/apierr.APIError'
is_pro:
type: boolean
message:
type: string
messagecount:
type: integer
quota:
type: integer
quota_max:
type: integer
scn_msg_id:
type: integer
success:
type: boolean
suppress_send:
type: boolean
type: object
handler.Sleep.response:
properties:
duration:
@ -458,7 +437,7 @@ definitions:
user_id:
type: integer
type: object
handler.UptimeKumaWebHook.uptimeKumaWebhookBody:
handler.UptimeKuma.body:
properties:
heartbeat:
properties:
@ -466,6 +445,8 @@ definitions:
type: string
msg:
type: string
status:
type: integer
time:
type: string
timezone:
@ -483,6 +464,11 @@ definitions:
msg:
type: string
type: object
handler.UptimeKuma.response:
properties:
message_id:
type: string
type: object
handler.pingResponse:
properties:
info:
@ -1418,7 +1404,7 @@ paths:
summary: Delete a single message
tags:
- API-v2
patch:
get:
description: |-
The user must either own the message and request the resource with the READ or ADMIN Key
Or the user must subscribe to the corresponding channel (and be confirmed) and request the resource with the READ or ADMIN Key
@ -2414,6 +2400,70 @@ paths:
summary: Update a subscription (e.g. confirm)
tags:
- API-v2
/external/v1/uptime-kuma:
post:
description: All parameter can be set via query-parameter or the json body.
Only UserID, UserKey and Title are required
parameters:
- in: query
name: channel
type: string
- in: query
name: channel_down
type: string
- in: query
name: channel_up
type: string
- example: P3TNH8mvv14fm
in: query
name: key
type: string
- in: query
name: priority
type: integer
- in: query
name: priority_down
type: integer
- in: query
name: priority_up
type: integer
- in: query
name: senderName
type: string
- example: "7725"
in: query
name: user_id
type: string
- description: ' '
in: body
name: post_body
schema:
$ref: '#/definitions/handler.UptimeKuma.body'
responses:
"200":
description: OK
schema:
$ref: '#/definitions/handler.UptimeKuma.response'
"400":
description: Bad Request
schema:
$ref: '#/definitions/ginresp.apiError'
"401":
description: The user_id was not found or the user_key is wrong
schema:
$ref: '#/definitions/ginresp.apiError'
"403":
description: The user has exceeded its daily quota - wait 24 hours or upgrade
your account
schema:
$ref: '#/definitions/ginresp.apiError'
"500":
description: An internal server error occurred - try again later
schema:
$ref: '#/definitions/ginresp.apiError'
summary: Send a new message
tags:
- External
/send:
post:
description: All parameter can be set via query-parameter or the json body.
@ -2535,53 +2585,91 @@ paths:
description: All parameter can be set via query-parameter or form-data body.
Only UserID, UserKey and Title are required
parameters:
- in: query
- example: test
in: query
name: channel
type: string
- example: This is a message
in: query
name: content
type: string
- in: query
- example: P3TNH8mvv14fm
in: query
name: key
type: string
- example: db8b0e6a-a08c-4646
in: query
name: msg_id
type: string
- in: query
- enum:
- 0
- 1
- 2
example: 1
in: query
name: priority
type: integer
- in: query
- example: example-server
in: query
name: sender_name
type: string
- example: 1669824037
in: query
name: timestamp
type: number
- in: query
- example: Hello World
in: query
name: title
type: string
- in: query
- example: "7725"
in: query
name: user_id
type: integer
- in: query
name: user_key
type: string
- in: formData
- example: test
in: formData
name: channel
type: string
- example: This is a message
in: formData
name: content
type: string
- in: formData
- example: P3TNH8mvv14fm
in: formData
name: key
type: string
- example: db8b0e6a-a08c-4646
in: formData
name: msg_id
type: string
- in: formData
- enum:
- 0
- 1
- 2
example: 1
in: formData
name: priority
type: integer
- in: formData
- example: example-server
in: formData
name: sender_name
type: string
- example: 1669824037
in: formData
name: timestamp
type: number
- in: formData
- example: Hello World
in: formData
name: title
type: string
- in: formData
- example: "7725"
in: formData
name: user_id
type: integer
- in: formData
name: user_key
type: string
responses:
"200":
description: OK
schema:
$ref: '#/definitions/handler.SendMessageCompat.response'
$ref: '#/definitions/handler.SendMessage.response'
"400":
description: Bad Request
schema:
@ -2601,49 +2689,6 @@ paths:
summary: Send a new message (compatibility)
tags:
- External
/webhook/uptime-kuma:
post:
description: All parameter can be set via query-parameter or the json body.
Only UserID, UserKey and Title are required
parameters:
- example: P3TNH8mvv14fm
in: query
name: key
type: string
- example: "7725"
in: query
name: user_id
type: string
- description: ' '
in: body
name: post_body
schema:
$ref: '#/definitions/handler.UptimeKumaWebHook.uptimeKumaWebhookBody'
responses:
"200":
description: OK
schema:
type: object
"400":
description: Bad Request
schema:
$ref: '#/definitions/ginresp.apiError'
"401":
description: The user_id was not found or the user_key is wrong
schema:
$ref: '#/definitions/ginresp.apiError'
"403":
description: The user has exceeded its daily quota - wait 24 hours or upgrade
your account
schema:
$ref: '#/definitions/ginresp.apiError'
"500":
description: An internal server error occurred - try again later
schema:
$ref: '#/definitions/ginresp.apiError'
summary: Send a new message
tags:
- External
swagger: "2.0"
tags:
- name: External