2021-10-09 13:22:14 +02:00
|
|
|
# standard imports
|
|
|
|
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
|
|
|
|
|
|
|
|
class CallbackTask(celery.Task):
|
2021-10-09 13:24:57 +02:00
|
|
|
|
|
|
|
mmap_path = tempfile.mkdtemp()
|
2021-10-09 13:22:14 +02:00
|
|
|
|
|
|
|
@celery_app.task(bind=True, base=CallbackTask)
|
|
|
|
def test_error_callback(self, a, b, c):
|
|
|
|
s = 'ok'
|
|
|
|
if c > 0:
|
|
|
|
s = 'err'
|
|
|
|
|
2021-10-09 13:24:57 +02:00
|
|
|
fp = os.path.join(self.mmap_path, b)
|
|
|
|
f = open(fp, 'wb')
|
|
|
|
m = mmap.mmap(f.fileno(), access=mmap.ACCESS_WRITE, length=1)
|
|
|
|
m.write(c.to_bytes(1, 'big'))
|
|
|
|
m.close()
|
|
|
|
f.close()
|
2021-10-09 13:22:14 +02:00
|
|
|
|
2021-10-09 13:24:57 +02:00
|
|
|
logg.debug('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> test callback ({}): {} {} {} -> {}'.format(s, a, b, c, fp))
|