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/apierr"
"blackforestbytes.com/simplecloudnotifier/api/ginresp" "blackforestbytes.com/simplecloudnotifier/api/ginresp"
ct "blackforestbytes.com/simplecloudnotifier/db/cursortoken" ct "blackforestbytes.com/simplecloudnotifier/db/cursortoken"
"blackforestbytes.com/simplecloudnotifier/db/impl/primary"
"blackforestbytes.com/simplecloudnotifier/models" "blackforestbytes.com/simplecloudnotifier/models"
"database/sql" "database/sql"
"errors" "errors"
@ -236,15 +235,7 @@ func (h APIHandler) CreateChannel(g *gin.Context) ginresp.HTTPResponse {
subscribeKey := h.app.GenerateRandomAuthKey() subscribeKey := h.app.GenerateRandomAuthKey()
cChannel := primary.CreateChanel{ channel, err := h.database.CreateChannel(ctx, u.UserID, channelDisplayName, channelInternalName, subscribeKey, b.Description)
UserId: u.UserID,
IntName: channelInternalName,
SubscribeKey: subscribeKey,
DisplayName: channelDisplayName,
Description: b.Description,
}
channel, err := h.database.CreateChannel(ctx, cChannel)
if err != nil { if err != nil {
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to create channel", err) 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, EnableLogger: true,
}, },
RequestTimeout: 16 * time.Second, RequestTimeout: 16 * time.Second,
RequestMaxRetry: 8, RequestMaxRetry: 32,
RequestRetrySleep: 100 * time.Millisecond, RequestRetrySleep: 32 * time.Millisecond,
ReturnRawErrors: false, ReturnRawErrors: false,
DummyFirebase: false, DummyFirebase: false,
FirebaseTokenURI: "https://oauth2.googleapis.com/token", FirebaseTokenURI: "https://oauth2.googleapis.com/token",

View File

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

View File

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

View File

@ -958,13 +958,13 @@
} }
}, },
"/api/v2/messages/{mid}": { "/api/v2/messages/{mid}": {
"delete": { "get": {
"description": "The user must own the message and request the resource with the ADMIN Key", "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": [ "tags": [
"API-v2" "API-v2"
], ],
"summary": "Delete a single message", "summary": "Get a single message (untrimmed)",
"operationId": "api-messages-delete", "operationId": "api-messages-get",
"parameters": [ "parameters": [
{ {
"type": "string", "type": "string",
@ -1007,13 +1007,13 @@
} }
} }
}, },
"patch": { "delete": {
"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", "description": "The user must own the message and request the resource with the ADMIN Key",
"tags": [ "tags": [
"API-v2" "API-v2"
], ],
"summary": "Get a single message (untrimmed)", "summary": "Delete a single message",
"operationId": "api-messages-get", "operationId": "api-messages-delete",
"parameters": [ "parameters": [
{ {
"type": "string", "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": { "/send": {
"post": { "post": {
"description": "All parameter can be set via query-parameter or the json body. Only UserID, UserKey and Title are required", "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": [ "parameters": [
{ {
"type": "string", "type": "string",
"example": "test",
"name": "channel",
"in": "query"
},
{
"type": "string",
"example": "This is a message",
"name": "content", "name": "content",
"in": "query" "in": "query"
}, },
{ {
"type": "string", "type": "string",
"example": "P3TNH8mvv14fm",
"name": "key",
"in": "query"
},
{
"type": "string",
"example": "db8b0e6a-a08c-4646",
"name": "msg_id", "name": "msg_id",
"in": "query" "in": "query"
}, },
{ {
"enum": [
0,
1,
2
],
"type": "integer", "type": "integer",
"example": 1,
"name": "priority", "name": "priority",
"in": "query" "in": "query"
}, },
{
"type": "string",
"example": "example-server",
"name": "sender_name",
"in": "query"
},
{ {
"type": "number", "type": "number",
"example": 1669824037,
"name": "timestamp", "name": "timestamp",
"in": "query" "in": "query"
}, },
{ {
"type": "string", "type": "string",
"example": "Hello World",
"name": "title", "name": "title",
"in": "query" "in": "query"
}, },
{ {
"type": "integer", "type": "string",
"example": "7725",
"name": "user_id", "name": "user_id",
"in": "query" "in": "query"
}, },
{ {
"type": "string", "type": "string",
"name": "user_key", "example": "test",
"in": "query" "name": "channel",
"in": "formData"
}, },
{ {
"type": "string", "type": "string",
"example": "This is a message",
"name": "content", "name": "content",
"in": "formData" "in": "formData"
}, },
{ {
"type": "string", "type": "string",
"example": "P3TNH8mvv14fm",
"name": "key",
"in": "formData"
},
{
"type": "string",
"example": "db8b0e6a-a08c-4646",
"name": "msg_id", "name": "msg_id",
"in": "formData" "in": "formData"
}, },
{ {
"enum": [
0,
1,
2
],
"type": "integer", "type": "integer",
"example": 1,
"name": "priority", "name": "priority",
"in": "formData" "in": "formData"
}, },
{
"type": "string",
"example": "example-server",
"name": "sender_name",
"in": "formData"
},
{ {
"type": "number", "type": "number",
"example": 1669824037,
"name": "timestamp", "name": "timestamp",
"in": "formData" "in": "formData"
}, },
{ {
"type": "string", "type": "string",
"example": "Hello World",
"name": "title", "name": "title",
"in": "formData" "in": "formData"
}, },
{
"type": "integer",
"name": "user_id",
"in": "formData"
},
{ {
"type": "string", "type": "string",
"name": "user_key", "example": "7725",
"name": "user_id",
"in": "formData" "in": "formData"
} }
], ],
@ -2702,7 +2848,7 @@
"200": { "200": {
"description": "OK", "description": "OK",
"schema": { "schema": {
"$ref": "#/definitions/handler.SendMessageCompat.response" "$ref": "#/definitions/handler.SendMessage.response"
} }
}, },
"400": { "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": { "definitions": {
@ -2964,6 +3047,9 @@
"handler.CreateChannel.body": { "handler.CreateChannel.body": {
"type": "object", "type": "object",
"properties": { "properties": {
"description": {
"type": "string"
},
"name": { "name": {
"type": "string" "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": { "handler.Sleep.response": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -3449,7 +3500,7 @@
} }
} }
}, },
"handler.UptimeKumaWebHook.uptimeKumaWebhookBody": { "handler.UptimeKuma.body": {
"type": "object", "type": "object",
"properties": { "properties": {
"heartbeat": { "heartbeat": {
@ -3461,6 +3512,9 @@
"msg": { "msg": {
"type": "string" "type": "string"
}, },
"status": {
"type": "integer"
},
"time": { "time": {
"type": "string" "type": "string"
}, },
@ -3488,6 +3542,14 @@
} }
} }
}, },
"handler.UptimeKuma.response": {
"type": "object",
"properties": {
"message_id": {
"type": "string"
}
}
},
"handler.pingResponse": { "handler.pingResponse": {
"type": "object", "type": "object",
"properties": { "properties": {

View File

@ -139,6 +139,8 @@ definitions:
type: object type: object
handler.CreateChannel.body: handler.CreateChannel.body:
properties: properties:
description:
type: string
name: name:
type: string type: string
subscribe: subscribe:
@ -376,29 +378,6 @@ definitions:
suppress_send: suppress_send:
type: boolean type: boolean
type: object 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: handler.Sleep.response:
properties: properties:
duration: duration:
@ -458,7 +437,7 @@ definitions:
user_id: user_id:
type: integer type: integer
type: object type: object
handler.UptimeKumaWebHook.uptimeKumaWebhookBody: handler.UptimeKuma.body:
properties: properties:
heartbeat: heartbeat:
properties: properties:
@ -466,6 +445,8 @@ definitions:
type: string type: string
msg: msg:
type: string type: string
status:
type: integer
time: time:
type: string type: string
timezone: timezone:
@ -483,6 +464,11 @@ definitions:
msg: msg:
type: string type: string
type: object type: object
handler.UptimeKuma.response:
properties:
message_id:
type: string
type: object
handler.pingResponse: handler.pingResponse:
properties: properties:
info: info:
@ -1418,7 +1404,7 @@ paths:
summary: Delete a single message summary: Delete a single message
tags: tags:
- API-v2 - API-v2
patch: get:
description: |- description: |-
The user must either own the message and request the resource with the READ or ADMIN Key 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 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) summary: Update a subscription (e.g. confirm)
tags: tags:
- API-v2 - 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: /send:
post: post:
description: All parameter can be set via query-parameter or the json body. 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. description: All parameter can be set via query-parameter or form-data body.
Only UserID, UserKey and Title are required Only UserID, UserKey and Title are required
parameters: parameters:
- in: query - example: test
in: query
name: channel
type: string
- example: This is a message
in: query
name: content name: content
type: string type: string
- in: query - example: P3TNH8mvv14fm
in: query
name: key
type: string
- example: db8b0e6a-a08c-4646
in: query
name: msg_id name: msg_id
type: string type: string
- in: query - enum:
- 0
- 1
- 2
example: 1
in: query
name: priority name: priority
type: integer type: integer
- in: query - example: example-server
in: query
name: sender_name
type: string
- example: 1669824037
in: query
name: timestamp name: timestamp
type: number type: number
- in: query - example: Hello World
in: query
name: title name: title
type: string type: string
- in: query - example: "7725"
in: query
name: user_id name: user_id
type: integer
- in: query
name: user_key
type: string type: string
- in: formData - example: test
in: formData
name: channel
type: string
- example: This is a message
in: formData
name: content name: content
type: string type: string
- in: formData - example: P3TNH8mvv14fm
in: formData
name: key
type: string
- example: db8b0e6a-a08c-4646
in: formData
name: msg_id name: msg_id
type: string type: string
- in: formData - enum:
- 0
- 1
- 2
example: 1
in: formData
name: priority name: priority
type: integer type: integer
- in: formData - example: example-server
in: formData
name: sender_name
type: string
- example: 1669824037
in: formData
name: timestamp name: timestamp
type: number type: number
- in: formData - example: Hello World
in: formData
name: title name: title
type: string type: string
- in: formData - example: "7725"
in: formData
name: user_id name: user_id
type: integer
- in: formData
name: user_key
type: string type: string
responses: responses:
"200": "200":
description: OK description: OK
schema: schema:
$ref: '#/definitions/handler.SendMessageCompat.response' $ref: '#/definitions/handler.SendMessage.response'
"400": "400":
description: Bad Request description: Bad Request
schema: schema:
@ -2601,49 +2689,6 @@ paths:
summary: Send a new message (compatibility) summary: Send a new message (compatibility)
tags: tags:
- External - 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" swagger: "2.0"
tags: tags:
- name: External - name: External