Metadata-Version: 2.1
Name: django-commands2
Version: 0.3.4
Project-URL: Documentation, https://github.com/ramwin/django-commands#readme
Project-URL: Issues, https://github.com/ramwin/django-commands/issues
Project-URL: Source, https://github.com/ramwin/django-commands
Author-email: Xiang Wang <ramwin@qq.com>
License-Expression: MIT
License-File: LICENSE.txt
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Requires-Python: >=3.7
Requires-Dist: django
Description-Content-Type: text/markdown

# django-commands

[![PyPI - Version](https://img.shields.io/pypi/v/django-commands.svg)](https://pypi.org/project/django-commands)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/django-commands.svg)](https://pypi.org/project/django-commands)

-----

**Table of Contents**

- [Installation](#installation)
- [Usage](#Usage)
- [License](#license)

## Installation

```console
pip install django-commands2
```

add django_commands to INSTALLED_APPS, and logging
```python
INSTALLED_APPS = [
    ...
    'django_commands',
]
LOGGING = {
    "loggers": {
        "django_commands": {
            ...your custom level, handles config...
        }
    }
}
```

## Usage
### AutoLogCommands
any exception will be logged in the autologcommand
```
<yourapp/management/commands/command_name.py>
from django_commands import AutoLogCommand


class Command(AutoLogCommand):

    def handle(self):
        <write your code, any exception will be logged>
```



### MultiTimesCommand
MultiTimesCommand will run multi times according to `INTERVAL` and `MAX_TIMES`. You can easily use this command to realize a crontab job every 1 second.

```python
class Command(MultiTimesCommand):
    INTERVAL = 1  # default 1
    MAX_TIMES = 60  # default 60

    def handle(self):
        <this handle function will run 60 times>
```
*This command does not consider the running time of your code. It will just run 60 times, and during each execute, wait 1 second*

### DurationCommand(AutoLogCommand):
DurationCommand will run your commands over and over again until the running time exceed the configuration
```python
import datetime

class Commmand(DurationCommand):
    INTERVAL = 1
    DURATION = datetime.timedelta(minutes=1)

    def handle(self, *args, **kwargs):
        <your code>
```

## License

`django-commands` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
