clean state cache in 30 seconds

This commit is contained in:
2020-01-14 17:03:14 +08:00
parent f06a6f4e78
commit 790c95ffc3
2 changed files with 16 additions and 9 deletions

View File

@ -8,7 +8,7 @@ All you need to do is:
- Find out the selectors for target data
- Type scripts in the console of `extension backgroud page`, as introduced bellow.
![](images/console.png)
![](template/assets/console.png)
## Qucik Start
@ -52,10 +52,7 @@ function (itemsSelector:string, fieldSelectors:string[], urls:ExtractResult)
## Stop Tasks
The only way to stop tasks before its finish, is `Closing the target tab`.
> Tasks wait for their target elements' appearance, given some elements were loaded asynchronously.
> If you typed wrong selectors, the task waits forever for elements which don't exists.
Close the target tab, in which current tasks is running.
## Extract Attributes.
@ -126,17 +123,17 @@ e.export(1)
Sometimes, it's hard to finish them in an single execution, that why we need "Continuing of Tasks".
You can always continue tasks (with following), even it stops in the middle of a task:
You can always continue tasks by start it again, not matter in what phase it stops.
```js
e.start()
```
The `Extractor` kept the state of last execution, and starts from where it stopped.
The `Extractor` kept the execution state, and starts from where it stopped.
### Restart Tasks
What should I do, if I don't like to continue from last state, but restart from certain task?
What if I don't like to continue from last state, but restart certain tasks?
```js
// restart all tasks
@ -166,12 +163,15 @@ e.save();
Load the state:
Open the popup window, upload the saved state file. Then, and in the backgoud console:
Open the popup window, upload the saved state file. Then, and in the backgroud console:
```js
e = new Extractor().load();
e.start();
```
> The uploaded state will be cleaned in 30 seconds, if you don't load it.
## Developpment
Clone this project and execute:

View File

@ -11,5 +11,12 @@ export class Caches {
setState(name: string, content: string) {
this._state = content;
logger.info(`State (${name}) recieved. To load it: some_var = new Extractor().load()`);
// clear cache in 30 seconds
setTimeout(() => {
if (this._state) {
logger.info(`Uploaded state is cleaned after 30 second.`);
this._state = "";
}
}, 30000);
}
}