...
Codeblock | ||
---|---|---|
| ||
/// <reference path="../../../.vscode.js"/> class MyCommitCallback extends CommitCallback { /** * @param {Entry} e */ preCommit(e) { if (e.get('entrytype') == 'customer') { console.errorlog('preCommit:', e); } } /** * @param {Entry} e */ postCommit(e) { if (e.get('entrytype') == 'customer') { console.errorlog('postCommit:', e); } } /** * @param {Entry} e */ preRemove(e) { if (e.get('entrytype') == 'customer') { console.errorlog('preRemove:', e); } } } CommitCallback.registerCallback(() => new MyCommitCallback()); |
...
Take a look at the console / shell where you started the UM: For each transaction the according Entry should be logged.
Setup a SyncQueue instance
Create a new file cmsbs-conf/cse/plugins/de.pinuts.tutorial/shared/queue.mjs
:
Codeblock | ||
---|---|---|
| ||
/// <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 = rsp.status;
})
.then(rsp => {
ret = true;
});
} else {
// Send DELETE request...
}
return ret;
}
export const queue = new SyncQueue(fn)
.setName('tutorial')
.setMaxRetries(5)
.setRunOnPush(true)
.register(); |