JobtasticMixins
===============
## Package includes:
#### AVGTimeRedis class
The class that helps automate calculate an avarage time
for different kind tasks and saves result into Redis DB
## Install
Install from Github
```pip install https://github.com/abbasovalex/JobtasticMixins/archive/master.zip```
## Usage
1. You must will add the mixin class as first argument
2. You should set ```default_avg_time``` in the seconds
3. You must use ```self.update_progress()``` without arguments
```python
class YourTask(AVGTimeRedis, JobtasticTask):
default_avg_time = 60 # 1 minute
...
def calculate_result(self, ..., **kwargs):
...
```
```default_avg_time``` used when task still never calculated
It will be encompass arithmetical mean after task was executed.
Forecast accuracy depends from count executed tasks
### Example with AVGTimeRedis class
The class that helps automate calculate an avarage time for different kind
tasks and saves result into Redis DB
Let's take a look at the example task using with JobtasticMixins and
AVGTimeRedis class:
``` python
from time import sleep
from jobtastic import JobtasticTask
from jobtasticmixins import AVGTimeRedis
class LotsOfDivisionTask(AVGTimeRedis, JobtasticTask):
"""
Division is hard. Make Celery do it a bunch.
"""
significant_kwargs = [
('numerators', str),
('denominators', str),
]
herd_avoidance_timeout = 60
cache_duration = 0
# optional variable was added. by default is 30 seconds
default_avg_time = 90
def calculate_result(self, numerators, denominators, **kwargs):
results = []
for count, divisors in enumerate(zip(numerators, denominators)):
numerator, denominator = divisors
results.append(numerator / denominator)
# it will be auto calculated
self.update_progress()
sleep(0.1)
# set finish=True for avoid trouble
self.update_progress(finish=True)
return results
```
Under the hood:
1. AVGTimeRedis gets settings.BROKER_URL and connects to Redis
2. It counts the tasks and the workers and uses to calculating
More details you can see into [source](https://github.com/abbasovalex/JobtasticMixins/blob/master/jobtasticmixins/mixins.py)
===============
## Package includes:
#### AVGTimeRedis class
The class that helps automate calculate an avarage time
for different kind tasks and saves result into Redis DB
## Install
Install from Github
```pip install https://github.com/abbasovalex/JobtasticMixins/archive/master.zip```
## Usage
1. You must will add the mixin class as first argument
2. You should set ```default_avg_time``` in the seconds
3. You must use ```self.update_progress()``` without arguments
```python
class YourTask(AVGTimeRedis, JobtasticTask):
default_avg_time = 60 # 1 minute
...
def calculate_result(self, ..., **kwargs):
...
```
```default_avg_time``` used when task still never calculated
It will be encompass arithmetical mean after task was executed.
Forecast accuracy depends from count executed tasks
### Example with AVGTimeRedis class
The class that helps automate calculate an avarage time for different kind
tasks and saves result into Redis DB
Let's take a look at the example task using with JobtasticMixins and
AVGTimeRedis class:
``` python
from time import sleep
from jobtastic import JobtasticTask
from jobtasticmixins import AVGTimeRedis
class LotsOfDivisionTask(AVGTimeRedis, JobtasticTask):
"""
Division is hard. Make Celery do it a bunch.
"""
significant_kwargs = [
('numerators', str),
('denominators', str),
]
herd_avoidance_timeout = 60
cache_duration = 0
# optional variable was added. by default is 30 seconds
default_avg_time = 90
def calculate_result(self, numerators, denominators, **kwargs):
results = []
for count, divisors in enumerate(zip(numerators, denominators)):
numerator, denominator = divisors
results.append(numerator / denominator)
# it will be auto calculated
self.update_progress()
sleep(0.1)
# set finish=True for avoid trouble
self.update_progress(finish=True)
return results
```
Under the hood:
1. AVGTimeRedis gets settings.BROKER_URL and connects to Redis
2. It counts the tasks and the workers and uses to calculating
More details you can see into [source](https://github.com/abbasovalex/JobtasticMixins/blob/master/jobtasticmixins/mixins.py)
Metadata
Release files for jobtastic-mixins 0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| jobtastic-mixins-0.1.tar.gz | 5.2 kB | Details |
Release files / jobtastic-mixins-0.1.tar.gz
| Download URL | jobtastic-mixins-0.1.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0880b6e82e3a6d87b4bca80cfbde5673052c45e23395c72e44b4facd0736eb4d
|
|
BLAKE2b-256 checksum How to use checksums |
6c43aa1111aa9c8ce3e3874692df3accc00786adbc4c3609f7239b25dd08d007
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |