Persistence
The persistence enable you to serialize certain job, store it in some external storage then reconstruct later one and continue the execution (by continue method) exactly from the same place. To use the persistence you have two options one using the TxJobPersistAdapter or using the low level job.toJSON and job.upJSON methods.
Using TxPersistenceAdapter
create a class which implements TxJobPersistAdapter. Implement save and read method.
TxJobPersistAdapter.save(uuid: string, json: TxJobJSON, name?: string)
: this will called by the framework when a job needs to persist.TxJobPersistAdapter.read(uuid: string): TxJobJSON
: this will call by framework when it need to reconstruct a Job.register you class on the TxJobRegistry as follow:
let persist = new Persist(); // class that implements TxJobPersistAdapter TxJobRegistry.instance.driver = persist;
Note: the TxJobJSON is the job serialize type.
This will store the job state before execute each component. The method save is up to you your storage implementation. Usually persistence goes with with run-until execution option. Using execute with run-until:
// execute the job until it reach component <component-name | component Symbol>
job.execute(new TxTask({
method: 'create',
},
{something: 'more data here'}
),
{
persist: {ison: true, destroy: true},
execute: {until: <component-name | component-Symbol>}
} as TxJobExecutionOptions
);
Once a job is persist it's state saved on the storage and removed from registry (if persist.destroyis true) So to continue the exection you need to do:
// on any part in the code
let job = TxJobRegistry.instaprivate _driver: TxJobPersistAdapter = null;nce.rebuild(uuid); // rebuild the job accorsing to it's uuid;
Job.continue(new TxTask(..));
Last updated