Component, Job and Task
A very simple example of a component, job and a Task
How A Component Looks like
export class C1Component {
// create and register a mountpoint
mountpoint = TxMountPointRegistry.instance.create('GITHUB::GIST::C1');
constructor() {
// subscribe to a tasks incoming messages
this.mountpoint.tasks().subscribe(
(task) => {
logger.info('[C1Component:tasks] got task = ' + JSON.stringify(task, undefined, 2));
this.run(tasks)
},
(error) => {
logger.info('[C1Component:error] got error = ' + JSON.stringify(error, undefined, 2));
this.error(task);
}
);
// subscribe to a undos incoming messages
this.mountpoint.undos().subscribe(
(task) => {
logger.info('[C1Component:undos] undo got task = ' + JSON.stringify(task, undefined, 2));
this.undo(task);
}
);
}
run(task) {
// run the logic ..
// just send the reply to whom is 'setting' on this reply subject
this.mountpoint.reply().next(new TxTask({method: 'from C1', status: 'ok'}, task['data']))
}
error(task) {
// clean up whats ever needs to clean ..
// just send the reply to whom is 'setting' on this reply subject
this.mountpoint.reply().error(new TxTask({method: 'from C1', status: 'ERROR'}, error['data']))
}
undos(task) {
// do undo, not this is different from error although it most likely the same
// just send the reply to whom is 'setting' on this reply subject
this.mountpoint.undos().next(new TxTask({method: 'undo from C1', status: 'ok'}, task['data']))
}
} How A Job Looks like
How A Task Looks like
A task is a generic object of head and data.
Last updated