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

Feature/add pre and post process hooks #71

Merged

Conversation

jimjshields
Copy link
Contributor

@jimjshields jimjshields commented Jun 9, 2020

This is a proof of concept for #70

I haven't figured out how best to test this, it might require a more end-to-end test.

Works like:

from pyqs import task

def print_pre_process(context):
    print({"pre_process": context})

def print_post_process(context):
    print({"pre_process": context})

task.set_hooks({"pre_process": print_pre_process, "post_process": print_post_process})

@task(queue="my_queue")
def send_email(subject):
    pass
pyqs email.tasks.send_email
# {"pre_process": {"task_name": "send_email", ...}}
# {"post_process": {"task_name": "send_email", "status": "success", ...}}

@jimjshields jimjshields marked this pull request as draft June 9, 2020 22:04
@coveralls
Copy link

coveralls commented Jun 9, 2020

Coverage Status

Coverage increased (+0.2%) to 97.872% when pulling 0d456c0 on jimjshields:feature/add-pre-and-post-process-hooks into 2f1b02d on spulec:master.

@jimjshields jimjshields force-pushed the feature/add-pre-and-post-process-hooks branch from d710205 to 750fb45 Compare June 15, 2020 16:21
@jimjshields
Copy link
Contributor Author

jimjshields commented Jun 15, 2020

Changed the suggested API after discussing with @spulec (inspiration from botocore's event registry):

from pyqs import task, events

def print_pre_process(context):
    print({"pre_process": context})

def print_post_process(context):
    print({"pre_process": context})

events.register_event("pre_process", print_pre_process)
events.register_event("post_process", print_post_process)

@task(queue="my_queue")
def send_email(subject):
    pass
pyqs email.tasks.send_email
# {"pre_process": {"task_name": "send_email", ...}}
# {"post_process": {"task_name": "send_email", "status": "success", ...}}

Still no tests, but what do you think about this API @spulec? If it's good, I can work on tests.

@spulec
Copy link
Owner

spulec commented Jun 16, 2020

I like this!

If we can add some tests, I'll be happy to merge.

@jimjshields jimjshields force-pushed the feature/add-pre-and-post-process-hooks branch from 779ddcd to f557af1 Compare June 16, 2020 16:32
@jimjshields
Copy link
Contributor Author

Refactored & renamed a few things, and added unit / functional tests.

@spulec do you think there are uncovered cases? I know there aren't any end-to-end tests, but I don't think it's necessary to come up with a way to do those for this change.

@jimjshields jimjshields marked this pull request as ready for review June 16, 2020 19:52
@jimjshields jimjshields force-pushed the feature/add-pre-and-post-process-hooks branch from 95d540b to 6c4204d Compare June 16, 2020 22:27
@jimjshields
Copy link
Contributor Author

Bumping this @spulec — if you're not sure about merging yet, is there a suggested way to test a beta version from a branch?

@jimjshields jimjshields force-pushed the feature/add-pre-and-post-process-hooks branch from 6c4204d to d2d19a7 Compare June 25, 2020 15:55
@jimjshields jimjshields force-pushed the feature/add-pre-and-post-process-hooks branch from eaef60f to 0d456c0 Compare June 25, 2020 18:24
@spulec spulec merged commit b0415a2 into spulec:master Jun 25, 2020
@spulec
Copy link
Owner

spulec commented Jun 25, 2020

Thanks @jimjshields !

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.

None yet

3 participants