-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make api to call fw headless sync (#1252)
* add crdt sync passthrough endpoint to call crdt sync on fw headless, setup service discovery to simplify configuration * fix issue with cookie port number not working when in the host parameter * log errors from fw headless, and return a problem from the lexbox api * Add button for triggering CRDT sync * increase request timeout on the sync endpoint, change the path to not be redundant --------- Co-authored-by: Tim Haasdyk <[email protected]>
- Loading branch information
Showing
17 changed files
with
120 additions
and
11 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
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
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,19 @@ | ||
using LexCore.Sync; | ||
|
||
namespace LexBoxApi.Services; | ||
|
||
public class FwHeadlessClient(HttpClient httpClient, ILogger<FwHeadlessClient> logger) | ||
{ | ||
public async Task<SyncResult?> CrdtSync(Guid projectId) | ||
{ | ||
var response = await httpClient.PostAsync($"/api/crdt-sync?projectId={projectId}", null); | ||
if (response.IsSuccessStatusCode) | ||
return await response.Content.ReadFromJsonAsync<SyncResult>(); | ||
logger.LogError("Failed to sync CRDT: {StatusCode} {StatusDescription}, projectId: {ProjectId}, response: {Response}", | ||
response.StatusCode, | ||
response.ReasonPhrase, | ||
projectId, | ||
await response.Content.ReadAsStringAsync()); | ||
return null; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -77,5 +77,12 @@ | |
"From": "Lexbox <[email protected]>", | ||
"EmailRenderHost": "localhost:3000", | ||
"BaseUrl": "http://localhost:3000" | ||
}, | ||
"Services": { | ||
"fwHeadless": { | ||
"http": [ | ||
"localhost:5275" | ||
] | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -70,5 +70,10 @@ | |
}, | ||
"Email": { | ||
"CreateProjectEmailDestination": "[email protected]" | ||
}, | ||
"Services": { | ||
"fwHeadless": { | ||
"http": ["fw-headless"] | ||
} | ||
} | ||
} |
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,3 @@ | ||
namespace LexCore.Sync; | ||
|
||
public record SyncResult(int CrdtChanges, int FwdataChanges); |
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
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
43 changes: 43 additions & 0 deletions
43
frontend/src/routes/(authenticated)/project/[project_code]/CrdtSyncButton.svelte
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,43 @@ | ||
<script lang="ts"> | ||
import {Button} from '$lib/forms'; | ||
import {Icon} from '$lib/icons'; | ||
import {useNotifications} from '$lib/notify'; | ||
export let projectId: string; | ||
const {notifySuccess, notifyWarning} = useNotifications(); | ||
let syncing = false; | ||
async function triggerSync(): Promise<void> { | ||
syncing = true; | ||
try { | ||
const response = await fetch(`/api/crdt/sync/${projectId}`, { | ||
method: 'POST', | ||
}); | ||
if (response.ok) { | ||
const { crdtChanges, fwdataChanges } = await response.json(); | ||
notifySuccess(`Synced successfully (${fwdataChanges} FwData changes. ${crdtChanges} CRDT changes)`); | ||
} else { | ||
const error = `Failed to sync: ${response.statusText} (${response.status})`; | ||
notifyWarning(error); | ||
console.error(error, await response.text()); | ||
} | ||
} finally { | ||
syncing = false; | ||
} | ||
} | ||
</script> | ||
|
||
<Button | ||
variant="btn-primary" | ||
class="gap-1" | ||
on:click={triggerSync} | ||
loading={syncing} | ||
customLoader | ||
> | ||
FwData | ||
<Icon icon="i-mdi-sync" spin={syncing} spinReverse /> | ||
CRDT | ||
</Button> |