# 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.destro&#x79;_&#x69;s 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(..));
```

###
