Versionen im Vergleich

Schlüssel

  • Diese Zeile wurde hinzugefügt.
  • Diese Zeile wurde entfernt.
  • Formatierung wurde geändert.

...

Codeblock
languagejs
/// <reference path="../../../.vscode.js"/>

import SyncQueue from "@de.pinuts.cmsbs.syncqueue/shared/SyncQueue.es6";
import HttpClientBuilder from "@de.pinuts.http/shared/HttpClientBuilder.es6";

const client = new HttpClientBuilder()
    .build();

const fn = (payload) => {
    console.error('SyncQueue:', payload);

    const e = UM.getEntryByOid(payload.oid);
    let ret;

    if (e) {
        client.post(`http://localhost:8080/tutorial/customer/${e.oid}`)
            .setJsonData({
                oid: e.oid,
                firstname: e.get('firstname'),
                lastname: e.get('lastname'),
                email: e.get('email'),
            })
            .execute()
            .catch(rsp => {
                console.error('HTTP request failed:', rsp.status);
                ret = `HTTP error: ${rsp.status}`;  // string = recoverable error
            })
            .then(rsp => {
                ret = true; // true = success
            });
    } else {
        // Send DELETE request...
    }

    return ret;
}

export const queue = new SyncQueue(fn)
    .setName('tutorial')
    .setMaxRetries(5)
    .setRunOnPush(true)
    .register();

...

Codeblock
languagejs
[...]
    /**
     * @param {Entry} e 
     */
    postCommit(e) {
        if (e.get('entrytype') == 'customer') {
            queue.push({ oid: e.oid });
        }
    }

    /**
     * @param {Entry} e 
     */
    preRemove(e) {
        if (e.get('entrytype') == 'customer') {
            queue.push({ oid: e.oid });
        }
    }
[...]

Test run

Now, edit or create a Customer entry and go to Tools / SyncQueue Dashboard.

You will notice a waiting (or failed) request for each creation or update operation you did. The HTTP requests will all fail with a 404 because there actually is no endpoint to receive our POST requests.

To make this work, you could implement a REST endpoint as a mockup and change the URL accordingly.