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

Using the app macro with one variable cause one can't capture dynamic environment in a fn item #250

Closed
yageek opened this issue Jul 6, 2021 · 3 comments · Fixed by #251

Comments

@yageek
Copy link

yageek commented Jul 6, 2021

I tried to use the app macro to instantiate the Celery struct from some String variable :

 let broker_connection_string = config.broker.connection_string();
    let jobs_queue = celery::app!(
        broker = AMQPBroker {
            broker_connection_string // does not work
        },
        tasks = [jobs::fetch_parcelle],
        task_routes = [],
    )
    .await?;

This does not compile an I got one can't capture dynamic environment in a fn item error.

I tries to replace the the macro with the generated code but now I'm not able to register the task since I can not retrieve the generated type created by the task macro :

  let broker_connection_string = config.broker.connection_string();
    let mut builder = Celery::<AMQPBroker>::builder("celery", &broker_connection_string);

    let app = builder.build().await?;


    app.register_task::<some_module::func>(); // How to retreive the type ?

I'm using the main branch as source for celery.

Am I misusing something?

@epwalsh
Copy link
Member

epwalsh commented Jul 7, 2021

Thanks for bringing this up @yageek! This is definitely a bug, but luckily there was a simple fix. See #251.

@theashguy
Copy link

theashguy commented Aug 29, 2021

@epwalsh Hey there Pete! Thanks for the fix above :). Just ran into this same thing trying to use vars for other values inside my !app definition-- in my case the default queue (I want to be able to define my default queue in env vars...). It seems the fix only works with broker URLs.

I'm wondering if there is a broader fix that needs to be done to the macro to automatically import any vars required somehow... Or maybe just take the body contents as a formatted struct so this requirement is removed... Just a thought... (I'm working around this for now).

@epwalsh
Copy link
Member

epwalsh commented Aug 30, 2021

Hey @theashguy, thanks for pointing that out! I think I found a good solution that doesn't involve introducing a struct: #267

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants