Created
July 5, 2011 14:44
-
-
Save thanos/1064964 to your computer and use it in GitHub Desktop.
Simple Daemon Django Command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from extend_optparser import make_option | |
| from django.core.management.base import BaseCommand | |
| class DaemonCommand(BaseCommand): | |
| help = 'Runs a process as a daemon' | |
| VERSION="Please Set!!!!" | |
| option_list = BaseCommand.option_list + ( | |
| make_option('--daemon', dest='daemon', action="store_true", default=False), | |
| make_option('--delay', dest='delay', type='int', default=20), | |
| make_option('--dryrun', dest='dryrun', action="store_true"), | |
| make_option('--datetime', type='datetime'), | |
| ) | |
| def get_version(self): | |
| return self.VERSION | |
| def handle(self, *args, **options): | |
| while True: | |
| self.process(*args, **options) | |
| if options['daemon']: | |
| sleep(options['delay']) | |
| else: | |
| break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment