Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed task output stream #22

Merged
merged 1 commit into from
Sep 20, 2019
Merged

Fixed task output stream #22

merged 1 commit into from
Sep 20, 2019

Conversation

matllubos
Copy link
Collaborator

No description provided.

@matllubos matllubos force-pushed the FixTasksOutputStream branch 4 times, most recently from b26e22f to 9e2ba75 Compare September 19, 2019 16:30
@@ -7,13 +7,13 @@
base=LoggedTask,
bind=True,
name='sum_task')
def sum_task(self, task_id, a, b):
def sum_task(self, a, b):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

task_id už není nutné přenášet, dá se získat z self.request.id, to je objekt, který drží kontext k danému tasku

@@ -83,28 +83,28 @@ def test_request_body_should_be_truncated(self):
self.post('/admin/login/', data={'username': 20 * 'a', 'password': 20 * 'b'})
input_logged_request = InputLoggedRequest.objects.get()
assert_equal(len(input_logged_request.request_body), 10)
assert_true(input_logged_request.request_body.endswith('...'))
assert_true(input_logged_request.request_body.endswith(''))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

posunul jsme django

@@ -2,6 +2,8 @@
import json
from json import JSONDecodeError

from datetime import timedelta
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chybička se vloudila

output_stream = self.request.output_stream
super().push_request(*args, **kwargs)
self.request.id = task_id
self.request.output_stream = output_stream
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tohle je velká sranda, dělá to jen když je zapnuto CELERY_ALWAYS_EAGER. Prostě přes spuštěním commandu to přepíše context a odstraní i task_id což dost dobře nechápu proč to je takto blbě napsané. Nicméně já si to tam prostě vrátil zpět


def get_task(self, task_id):
return CeleryTaskLog.objects.get(pk=task_id)

def __call__(self, *args, **kwargs):
# Every set attr is send here
self.request.output_stream = StringIO()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

před zavoláním commandu si tam přidáme stream

@@ -62,10 +58,13 @@ def on_start(self, task_id, args, kwargs):
self._call_callback('start', task_id, args, kwargs)

def on_success(self, retval, task_id, args, kwargs):
if retval:
self.request.output_stream.write('Return value is "{}"'.format(retval))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pokud task vrátí nějakou hodnotu tak to dáme do výpisu

@@ -126,7 +120,7 @@ def log_and_retry(self, attempt, exception_message=None, *args, **kwargs):
args=args,
kwargs={**kwargs, 'attempt': attempt+1},
countdown=self.repeat_timeouts[attempt - 1] * 60,
queue=self.queue
queue=queue or getattr(self, 'queue', settings.CELERY_DEFAULT_QUEUE)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tady jsem fixnul nastavení fronty, jde jí nyní i změnit

@matllubos matllubos merged commit 9305703 into master Sep 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant