Skip to main content

No project description provided

Project description

django-commands

PyPI - Version PyPI - Python Version


Table of Contents

Installation

pip install django-commands2

add django_commands to INSTALLED_APPS, and logging

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.

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

import datetime

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

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

UniqueCommand

UniqueCommand can assert that only one command instance is running

How it works? Every time the command executes:

  1. it will create a django_commands.models.CommandLog instance
  2. it will check if there is another Command Instance pending with the same UNIQUE_NAME
import time
from django_commands.commands import UniqueCommand

class Command(UniqueCommand):
    def handle(self):
        print("I'm running. In the next 5 seconds, you cannot execute this command. It will exist directly")
        time.sleep(5)
        print("I'm running")
        raise Exception("even error occurs, this task will be set finished")

License

django-commands is distributed under the terms of the ONLY USE NO PRIVATE CHANGE LICENSE license.

Anyone can use pip install django-commands to use this project by any meaning as long as you keep the source code unchanged.
You are not allowed to change the source code without publishing your change.
Here publishing means you: fork this project from github and keep your change available to public on the github

Project details


Download files

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

Source Distribution

django_commands2-0.5.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_commands2-0.5.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file django_commands2-0.5.0.tar.gz.

File metadata

  • Download URL: django_commands2-0.5.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.25.0

File hashes

Hashes for django_commands2-0.5.0.tar.gz
Algorithm Hash digest
SHA256 e407757c7074f06af2a3ef494d9824496717c7f14ec873ea92829f4a99965b0f
MD5 7830a93a7c082547afd0b7eb48cacd33
BLAKE2b-256 c43cd09b5633ce9278cc81c928402ab946a4cf7e67ca85ecf17a4fc15bed9cf8

See more details on using hashes here.

File details

Details for the file django_commands2-0.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_commands2-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1496bf4689efdd3065c175e7c83e175917a37066d77f3d5db5960ad119226741
MD5 b807d9aa790114302aadb96d5e4df147
BLAKE2b-256 963f6c3bf1a8b1e8b2c5eaccc016bed0f190ea7fd84449e9d45204a9560bc95e

See more details on using hashes here.

Supported by

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