loading...

[Video] Asynchronous tasks in Django with Django Q (Part 3)

twitter logo github logo ・1 min read

Django Q (3 Part Series)

1) [Video] Asynchronous tasks in Django with Django Q (Part 1) 2) [Video] Asynchronous tasks in Django with Django Q (Part 2) 3) [Video] Asynchronous tasks in Django with Django Q (Part 3)

Django Q is a scheduler and a task queue for Django. In this series you'll learn how to use Django Q in your Django applications for queuing long-running tasks.

In this episode:

  • hands on Django Q
  • using async_task

Enjoy!

twitter logo DISCUSS (1)
markdown guide
 

Hey, first of all thanks for sharing!

I'm trying to populate my database using a Data Migration.

In my populate function I have 2 api calls, so the shape is something like this:

async def populate_table(apps, schema_editor):
    some stuff...
    an api call like: await get_info()...
    an api call inside a for loop (any problem with this?)
    for i in range():
       an api call like: await get_another_info()...
    more stuff...
    model.save()

And then, I have my migration class:

class Migration(migrations.Migration):

    dependencies = [
        ('app', 'the previous migration'),
    ]

    operations = [
        migrations.RunPython(populate_table)
    ]

Running the migration a Runtime Warning is raised:

RuntimeWarning: coroutine 'populate_table' was never awaited

So I try to decorate my Migration with Async Await without success.

How should I do that? And again, any problem to have async tasks inside a sync for loop?

Classic DEV Post from Jun 21 '19

Is Ubuntu Or Fedora A Better Distro For Programmers?

Valentino Gagliardi profile image
Coding instructor | Django lover | The Little JavaScript Book
JOIN DEV NOW

We are a community