Add delay on federation
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
5f2a515437
commit
25e5362d01
@ -8,6 +8,7 @@ import (
|
||||
|
||||
type FederationSettings struct {
|
||||
URL string `json:"url"`
|
||||
Delay uint `json:"delay"`
|
||||
}
|
||||
|
||||
// Settings represents the settings panel.
|
||||
|
@ -3,12 +3,35 @@ package player
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"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_enc, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
|
@ -58,12 +58,7 @@ func WakeUp(cfg *config.Config, routine []reveil.Identifier, federated bool) (er
|
||||
}
|
||||
|
||||
for k, srv := range settings.Federation {
|
||||
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)
|
||||
}
|
||||
FederatedWakeUp(k, srv, seed)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,8 +2,12 @@
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
|
||||
import {
|
||||
Button,
|
||||
Col,
|
||||
Icon,
|
||||
Input,
|
||||
InputGroup,
|
||||
InputGroupText,
|
||||
Row,
|
||||
} from '@sveltestrap/sveltestrap';
|
||||
|
||||
@ -27,7 +31,7 @@
|
||||
|
||||
{#if value}
|
||||
{#each Object.keys(value) as key}
|
||||
<Row>
|
||||
<Row class="mb-3">
|
||||
<Col>
|
||||
<Input
|
||||
type="string"
|
||||
@ -37,12 +41,31 @@
|
||||
/>
|
||||
</Col>
|
||||
<Col>
|
||||
<InputGroup>
|
||||
<Input
|
||||
type="string"
|
||||
placeholder="https://reveil.fr/"
|
||||
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>
|
||||
</Row>
|
||||
{/each}
|
||||
@ -65,4 +88,12 @@
|
||||
value=""
|
||||
/>
|
||||
</Col>
|
||||
<Col>
|
||||
<Input
|
||||
type="number"
|
||||
placeholder="60"
|
||||
disabled
|
||||
value=""
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
|
Loading…
Reference in New Issue
Block a user