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
let job = new TxJob();
job.add(TxMountPointRegistry.instance.get('GITHUB::GIST::C1'));
job.add(TxMountPointRegistry.instance.get('GITHUB::GIST::C2'));
job.add(TxMountPointRegistry.instance.get('GITHUB::GIST::C3'));
job.execute(new TxTask(
'create',
'something',
{something: 'more data here'})
);
How A Task Looks like
A task is a generic object of head and data.
export class TxTask<T> {
head: T;
data: any;
...
}
interface Head {
source: string;
method: string;
status: string;
}
interface Data {
data: string
}
let t = new TxTask<Head>(
{source: 'other', method: 'doit', status: 'ok'},
{data: 'this is again my data'});
let h: Head = t.head;
let d: Data = t.data;
Last updated