Last active
August 29, 2015 13:56
-
-
Save mineta/9002300 to your computer and use it in GitHub Desktop.
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
# -*- coding: utf-8 -*- | |
from celery.task.schedules import crontab | |
from celery.decorators import periodic_task | |
from celery.utils.log import get_task_logger | |
from datetime import datetime | |
from myapp.models import TaskHistory | |
logger = get_task_logger(__name__) | |
# A periodic task that will run every minute (the symbol "*" means every) | |
@periodic_task(run_every=(crontab(hour="*", minute="*", day_of_week="*")), | |
ignore_result=True) | |
def scraper_example(): | |
logger.info("Start task") | |
now = datetime.now() | |
date_now = now.strftime("%d-%m-%Y %H:%M:%S") | |
# Perform all the operations you want here | |
result = 2+2 | |
# The name of the Task, use to find the correct TaskHistory object | |
name = "scraper_example" | |
taskhistory = TaskHistory.objects.get_or_create(name=name)[0] | |
taskhistory.history.update({date_now: result}) | |
taskhistory.save() | |
logger.info("Task finished: result = %i" % result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment