2021-10-09 13:22:14 +02:00
|
|
|
# standard imports
|
2021-10-09 14:18:10 +02:00
|
|
|
import os
|
2021-10-09 13:22:14 +02:00
|
|
|
import logging
|
2021-10-09 13:24:57 +02:00
|
|
|
import mmap
|
|
|
|
|
|
|
|
# standard imports
|
|
|
|
import tempfile
|
2021-10-09 13:22:14 +02:00
|
|
|
|
|
|
|
# external imports
|
|
|
|
import celery
|
|
|
|
|
|
|
|
#logg = logging.getLogger(__name__)
|
|
|
|
logg = logging.getLogger()
|
|
|
|
|
|
|
|
celery_app = celery.current_app
|
|
|
|
|
2021-10-09 14:18:10 +02:00
|
|
|
|
2021-10-09 13:22:14 +02:00
|
|
|
class CallbackTask(celery.Task):
|
2021-10-09 13:24:57 +02:00
|
|
|
|
|
|
|
mmap_path = tempfile.mkdtemp()
|
2021-10-09 13:22:14 +02:00
|
|
|
|
2021-10-09 14:18:10 +02:00
|
|
|
|
2021-10-09 13:22:14 +02:00
|
|
|
@celery_app.task(bind=True, base=CallbackTask)
|
2021-10-09 14:18:10 +02:00
|
|
|
def test_callback(self, a, b, c):
|
2021-10-09 13:22:14 +02:00
|
|
|
s = 'ok'
|
|
|
|
if c > 0:
|
|
|
|
s = 'err'
|
|
|
|
|
2021-10-09 13:24:57 +02:00
|
|
|
fp = os.path.join(self.mmap_path, b)
|
2021-10-09 14:18:10 +02:00
|
|
|
f = open(fp, 'wb+')
|
|
|
|
f.write(b'\x00')
|
|
|
|
f.seek(0)
|
|
|
|
m = mmap.mmap(f.fileno(), length=1)
|
2021-10-09 13:24:57 +02:00
|
|
|
m.write(c.to_bytes(1, 'big'))
|
|
|
|
m.close()
|
|
|
|
f.close()
|
2021-10-09 13:22:14 +02:00
|
|
|
|
2021-10-09 14:18:10 +02:00
|
|
|
logg.debug('test callback ({}): {} {} {}'.format(s, a, b, c))
|