Add delay on federation
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
nemunaire 2024-07-29 11:16:51 +02:00
parent 5f2a515437
commit 25e5362d01
4 changed files with 65 additions and 15 deletions

View File

@ -7,7 +7,8 @@ import (
) )
type FederationSettings struct { type FederationSettings struct {
URL string `json:"url"` URL string `json:"url"`
Delay uint `json:"delay"`
} }
// Settings represents the settings panel. // Settings represents the settings panel.

View File

@ -3,12 +3,35 @@ package player
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"log"
"net/http" "net/http"
"time"
"git.nemunai.re/nemunaire/reveil/model" "git.nemunai.re/nemunaire/reveil/model"
) )
func FederatedWakeUp(srv reveil.FederationSettings, seed int64) error { func FederatedWakeUp(k string, srv reveil.FederationSettings, seed int64) {
if srv.Delay == 0 {
err := federatedWakeUp(srv, seed)
if err != nil {
log.Printf("Unable to do federated wakeup on %s: %s", k, err.Error())
} else {
log.Printf("Federated wakeup on %s: launched!", k)
}
} else {
go func() {
time.Sleep(time.Duration(srv.Delay) * time.Millisecond)
err := federatedWakeUp(srv, seed)
if err != nil {
log.Printf("Unable to do federated wakeup on %s: %s", k, err.Error())
} else {
log.Printf("Federated wakeup on %s: launched!", k)
}
}()
}
}
func federatedWakeUp(srv reveil.FederationSettings, seed int64) error {
req := map[string]interface{}{"seed": seed} req := map[string]interface{}{"seed": seed}
req_enc, err := json.Marshal(req) req_enc, err := json.Marshal(req)
if err != nil { if err != nil {

View File

@ -58,12 +58,7 @@ func WakeUp(cfg *config.Config, routine []reveil.Identifier, federated bool) (er
} }
for k, srv := range settings.Federation { for k, srv := range settings.Federation {
err = FederatedWakeUp(srv, seed) FederatedWakeUp(k, srv, seed)
if err != nil {
log.Printf("Unable to do federated wakeup on %s: %s", k, err.Error())
} else {
log.Printf("Federated wakeup on %s: launched!", k)
}
} }
} }

View File

@ -2,8 +2,12 @@
import { createEventDispatcher } from 'svelte'; import { createEventDispatcher } from 'svelte';
import { import {
Button,
Col, Col,
Icon,
Input, Input,
InputGroup,
InputGroupText,
Row, Row,
} from '@sveltestrap/sveltestrap'; } from '@sveltestrap/sveltestrap';
@ -27,7 +31,7 @@
{#if value} {#if value}
{#each Object.keys(value) as key} {#each Object.keys(value) as key}
<Row> <Row class="mb-3">
<Col> <Col>
<Input <Input
type="string" type="string"
@ -37,12 +41,31 @@
/> />
</Col> </Col>
<Col> <Col>
<Input <InputGroup>
type="string" <Input
placeholder="https://reveil.fr/" type="string"
bind:value={value[key].url} placeholder="https://reveil.fr/"
on:change={() => dispatch("input")} bind:value={value[key].url}
/> on:change={() => dispatch("input")}
/>
<Button
href={value[key].url}
target="_blank"
>
<Icon name="globe" />
</Button>
</InputGroup>
</Col>
<Col>
<InputGroup>
<Input
type="number"
placeholder="60"
bind:value={value[key].delay}
on:change={() => dispatch("input")}
/>
<InputGroupText>ms</InputGroupText>
</InputGroup>
</Col> </Col>
</Row> </Row>
{/each} {/each}
@ -65,4 +88,12 @@
value="" value=""
/> />
</Col> </Col>
<Col>
<Input
type="number"
placeholder="60"
disabled
value=""
/>
</Col>
</Row> </Row>