Skip to main content

Provides ability calculate average time of tasks

Project description

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)

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jobtastic-mixins-0.1.tar.gz (5.2 kB view details)

Uploaded Source

File details

Details for the file jobtastic-mixins-0.1.tar.gz.

File metadata

File hashes

Hashes for jobtastic-mixins-0.1.tar.gz
Algorithm Hash digest
SHA256 0880b6e82e3a6d87b4bca80cfbde5673052c45e23395c72e44b4facd0736eb4d
MD5 45c76cd8f2bd3d3670143f460beb797a
BLAKE2b-256 6c43aa1111aa9c8ce3e3874692df3accc00786adbc4c3609f7239b25dd08d007

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page