GithubHelp home page GithubHelp logo

Comments (5)

walterrenner avatar walterrenner commented on June 3, 2024

When i want an existing function to become a background tasks, i proceed as follows:

tasks.py

from background_task import background

@background(schedule=1)
def often_used_function_in_background(my_arg):
    # code from utils.py goes here

utils.py

from .tasks import often_used_function_in_background

def often_used_function(my_arg):
    # forwarding the arguments to the new background task
    often_used_function_in_background(my_arg)

from django-background-tasks.

gregpinero avatar gregpinero commented on June 3, 2024

Thanks. That might work.

from django-background-tasks.

TeddJohnson avatar TeddJohnson commented on June 3, 2024

this really should not be closed. with commit 4cf5c08 it seems to suggest that limiting things to tasks.py is "the wrong way" (and I agree). You're basically forcing code to be written in the tasks.py file when often it needs to be broke out (I have a few different scripts in my utils directory, but I shouldn't have to put all that code in a single tasks.py file)

from django-background-tasks.

walterrenner avatar walterrenner commented on June 3, 2024

@Jawnz Why not simply calling your utils scripts/functions from tasks.py?

A tasks.py file is just a very simple way to "autodiscover" what code to run in background.

from django-background-tasks.

TeddJohnson avatar TeddJohnson commented on June 3, 2024

@walterrenner that's actually what I ended up doing! Great suggestions. I misunderstood the earlier post and thought that they were saying the opposite:
Create the actual function in tasks.py and just create a dummy function in utils/scripts (Which seemed superfluous).

I tried tweaking the auto-discover, but alas made it nowhere. The tasks.py being a pointer to my other functions works well though.

from django-background-tasks.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.