This repository has been archived by the owner on Jan 12, 2022. It is now read-only.
forked from felipelerena/FlightDeck
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
103 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
registered = {} | ||
|
||
|
||
def register(f): | ||
"""Decorator to add the function to the cronjob library.""" | ||
registered[f.__name__] = f | ||
return f |
Empty file.
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import sys | ||
|
||
from django.conf import settings | ||
from django.core.management.base import BaseCommand | ||
|
||
import commonware.log | ||
|
||
import cronjobs | ||
|
||
log = commonware.log.getLogger('z.cron') | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Run a script, often a cronjob' | ||
args = '[name args...]' | ||
|
||
def handle(self, *args, **opts): | ||
# Load up all the cron scripts. | ||
for app in settings.INSTALLED_APPS: | ||
try: | ||
__import__('%s.cron' % app) | ||
except ImportError: | ||
pass | ||
|
||
registered = cronjobs.registered | ||
|
||
if not args: | ||
log.error("Cron called but doesn't know what to do.") | ||
print 'Try one of these:\n%s' % '\n'.join(sorted(registered)) | ||
sys.exit(1) | ||
|
||
script, args = args[0], args[1:] | ||
if script not in registered: | ||
log.error("Cron called with unrecognized command: %s %s" % (script, args)) | ||
print 'Unrecognized name: %s' % script | ||
sys.exit(1) | ||
|
||
log.info("Beginning job: %s %s" % (script, args)) | ||
registered[script](*args) | ||
log.info("Ending job: %s %s" % (script, args)) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import os | ||
import shutil | ||
import stat | ||
import time | ||
|
||
from django.conf import settings | ||
|
||
import commonware | ||
import cronjobs | ||
|
||
length = 60 * 60 * 24 # one day | ||
log = commonware.log.getLogger('z.cron') | ||
|
||
|
||
def find_files(): | ||
files = [] | ||
tmp_dir = os.path.dirname(settings.SDKDIR_PREFIX) | ||
for filename in os.listdir(tmp_dir): | ||
full = os.path.join(tmp_dir, filename) | ||
|
||
if full.startswith(settings.SDKDIR_PREFIX): | ||
files.append(full) | ||
return files | ||
|
||
|
||
@cronjobs.register | ||
def clean_tmp(length=length): | ||
older = time.time() - length | ||
for filename in find_files(): | ||
if (os.stat(filename)[stat.ST_MTIME] < older): | ||
shutil.rmtree(filename) | ||
log.info('Deleted: %s' % filename) |
This file contains 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
This file contains 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