Skip to content

Import a models.Model custom database entity model. Error:KeyError: 'export_zip_task' #1671

Open
@vnsun

Description

@vnsun

hi, I introduced the django_uwsgi library in my project
Simple tasks are executing fine, when I introduce the database model class in the task.py file, it starts reporting errors
no import model success
image

import model error
image

  • Environment: uwsgi+django

Here is my configuration and code

config uwsgi.ini

`
socket=127.0.0.1:18089

django_projects_dir = /mnt/qa

my_project = qa

processes=4

threads=2
workers=4
master=True
wsgi-file=qa/wsgi.py
module=django.core.handlers:WSGIHandler()
spooler=%(chdir)/mytasks
import=task
`

code

`
from task import export_zip_task

export_zip_task.spool(v1=base64.b64encode(serialized_q_object).decode('utf-8'), v2='This is param test')

`

`
import base64
import pickle

from django_uwsgi.decorators import spool

from qc.models import TaskLog

@spool
def export_zip_task(arguments):
print("----1111111111111:", arguments)
for i in range(10):
print(i)
print(f'---------2222222222', arguments['v2'])
base64_decode = base64.b64decode(arguments['v1'])
# 反序列化 Q 对象
v1_obj = pickle.loads(base64_decode)
file_id = v1_obj['file_id']
file_path = v1_obj['file_path']
print(f'-------3333333333 file_id:{file_id} file_path:{file_path}')
task_operate_log = TaskLog(file_id=file_id, task_name='downlioad',
file_name=file_path[file_path.rfind('/')+1:],
process_total=200)
task_operate_log.save()

`

I don't know how to manipulate the database model in the spool task
I hope this can be answered, preferably with an example, because I've tried a lot but it doesn't work!
Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions