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

Missing docs and samples for Sdk v3 #1924

Open
snavarropino opened this Issue Sep 21, 2018 · 20 comments

Comments

Projects
None yet
9 participants
@snavarropino

snavarropino commented Sep 21, 2018

Sdk v3 is already released on nuget. Unfortunately documentation has not been updated, neither in Microsoft docs nor in github readme .md

Where can we find guidance? This version introduced severe changes that prevent previous code (and current doc code) to compile

Regards

@jairov4

This comment has been minimized.

jairov4 commented Sep 21, 2018

I agree, I noticed the nuget package was released for v3 but no docs about the breaking changes is easy to find

@mathewc

This comment has been minimized.

Contributor

mathewc commented Sep 21, 2018

Yes you guys are right - we're behind on doc updates. We're hoping to get some updated docs/wiki content out soon.

In the mean time, there is the sample app https://github.com/Azure/azure-webjobs-sdk/blob/dev/sample/SampleHost/Program.cs which shows new way to start a JobHost.

@johnkwaters

This comment has been minimized.

johnkwaters commented Sep 24, 2018

The sample app does not show how to set up and configure timer based jobs.

@mathewc

This comment has been minimized.

Contributor

mathewc commented Sep 24, 2018

The SDK sample referenced above just shows usage of the core extensions in that repo. For some of the other extensions, you can see their usage in the Extensions repo sample here. Specifically, you can see the builder.AddTimers() call here and that method takes an overload allowing you to specify a TimersOptions.

@johnkwaters

This comment has been minimized.

johnkwaters commented Sep 24, 2018

Thanks, that is helpful!

@johnkwaters

This comment has been minimized.

johnkwaters commented Sep 24, 2018

What happened to where you configure connection strings?
I had code like this:

config.StorageConnectionString = cfg["AzureWebJobsStorage"];
config.DashboardConnectionString = cfg["AzureWebJobsDashboard"];

I have a QueueTrigger and want to set the connection string for where to read from
I also need to set where to log to for the dashboard?

@johnkwaters

This comment has been minimized.

johnkwaters commented Sep 24, 2018

One more: in my code, I was injecting an IServiceScopeFactory into my web methods class (the one that has the timer methods to call). But now this class only takes a default constructor, so I can't inject anything. If I need to inject into my methods, with a scope that is the same as that of the timer trigger, how do I do that?

    public async Task TripDepartureTimerAsync(
        [TimerTrigger("0 */10 * * * *", RunOnStartup = true)]
        TimerInfo timerInfo,
        TextWriter log)
    {
        using (var scope = _serviceScopeFactory.CreateScope())
        {
            var ttp = scope.ServiceProvider.GetRequiredService<ITimedTaskProcessor>();
            await ttp.CheckLateDeparturesAsync();
        }
    }
@johnkwaters

This comment has been minimized.

johnkwaters commented Sep 24, 2018

One more issue - my webjob has a continuous method (ProcessMethod) below... so that await never returns and I don't get to host.RunAsync...

        var host = builder.Build();
        using (host)
        {
            var jobHost = (JobHost)host.Services.GetService<IJobHost>();
            await jobHost.CallAsync(typeof(WebJobsMethods).GetMethod("ProcessMethod"));
            await host.RunAsync();
        }

If I remove the await, it works... but the compiler warns me. Is there a better pattern now for a continous jobloop?

@maxpower720

This comment has been minimized.

maxpower720 commented Sep 25, 2018

One more: in my code, I was injecting an IServiceScopeFactory into my web methods class (the one that has the timer methods to call). But now this class only takes a default constructor, so I can't inject anything. If I need to inject into my methods, with a scope that is the same as that of the timer trigger, how do I do that?

    public async Task TripDepartureTimerAsync(
        [TimerTrigger("0 */10 * * * *", RunOnStartup = true)]
        TimerInfo timerInfo,
        TextWriter log)
    {
        using (var scope = _serviceScopeFactory.CreateScope())
        {
            var ttp = scope.ServiceProvider.GetRequiredService<ITimedTaskProcessor>();
            await ttp.CheckLateDeparturesAsync();
        }
    }

You need to set up an IJobActivator - referenced in #1917 (workaround in #1915) for the time being to inject your dependencies.

@snavarropino

This comment has been minimized.

snavarropino commented Sep 27, 2018

Any news on this?

@garyapps

This comment has been minimized.

garyapps commented Sep 28, 2018

I too have the same question as @johnkwaters

What happened to where you configure connection strings?
I had code like this:

config.StorageConnectionString = cfg["AzureWebJobsStorage"];
config.DashboardConnectionString = cfg["AzureWebJobsDashboard"];

Where does one set these connection strings now? I've tried looking at the SampleHost sample code but don't see these anywhere.

@mathewc Any estimate on when the docs or wiki will be ready? I had everything working perfectly before the update to core, now I am completely lost and confused; even partially completed docs would be better than nothing.

@johnkwaters

This comment has been minimized.

johnkwaters commented Sep 28, 2018

What about my question about the continuous job - is there a pattern?

@kevin645

This comment has been minimized.

kevin645 commented Oct 1, 2018

        var builder = new HostBuilder()
            .UseEnvironment(Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"))
            .ConfigureAppConfiguration((context, config) =>
            {
                config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                      .AddJsonFile($"appsettings.{context.HostingEnvironment.EnvironmentName}.json", optional: false, reloadOnChange: true);

                // Load in Azure Key Vault Secrets
                var builtConfig = config.Build();                    
                config.AddAzureKeyVault(
                    $"https://{builtConfig["AzureAdAuthentication:VaultName"]}.vault.azure.net/",
                    builtConfig["AzureAdAuthentication:ClientId"],
                    builtConfig["AzureAdAuthentication:ClientSecret"]);

                builtConfig = config.Build();

                // Setup Web Job Specific Secrets to be setup as in memory objects so Web Jobs SDK can pick them up
                Dictionary<string, string> azureWebJobsSecrets = new Dictionary<string, string>();          
                azureWebJobsSecrets["AzureWebJobsStorage"] = builtConfig["JobStorage"];
                azureWebJobsSecrets["AzureWebJobsDashboard"] = builtConfig["DashboardStorage"];

                // Add in Memory Collection to allow for Web Jobs SDK to pick up required configs
                config.AddInMemoryCollection(azureWebJobsSecrets);
            })
            .ConfigureLogging((context, logging) =>
            {
                logging.AddConfiguration(context.Configuration.GetSection("Logging"));
                logging.AddConsole();                    
                string appInsightsKey = context.Configuration["InstrumentationKey"];
                if (!string.IsNullOrEmpty(appInsightsKey))
                {
                    logging.AddApplicationInsights(o => o.InstrumentationKey = appInsightsKey);
                }
            })
            .ConfigureWebJobs((context) =>
            {
                context.AddTimers();
                context.AddDashboardLogging();
                context.AddAzureStorageCoreServices();                    
            })
            .UseConsoleLifetime();
        var host = builder.Build();

        using (host)
        {
            host.RunAsync().Wait();
        }

This is how I had setup the everything for my app in WebJobs SDK 3.0. After some digging through the code i figured out how to load in the webjobs specific information. I used key vault here to build a inmemory configuration object that web jobs could use, so didn't have to put any secrets in my appsettings during deployment. It will also work if you just have the appsettings within your appsettings.json file as this:

{
// Other Settings
"AzureWebJobsStorage": "connectionstring",
"AzureWebJobsDashboard": "connectionstring"
}

@johnkwaters

This comment has been minimized.

johnkwaters commented Oct 1, 2018

So ultimately it seems you just need two config settings with the same names as before, AzureWebJobsStorage and AzureWebJobsDashboard, that you can pull from wherever you want. And then you need to add context.AddDashoardLogging and context.AddAzureStorageCoreServices. Right?

@kevin645

This comment has been minimized.

kevin645 commented Oct 1, 2018

Correct. I currently have 2 web jobs on separate apps tied to one of my storage accounts which doesn't seem to be working. This I believe is a user error on my part and I plan to resolve this today.

AzureStorageCoreServices is the method for the storage account used by WebJobs/Functions to acquire blob leases in table storage to support singletons or timers or any lease based extension for its core functionality. I believe this was mentioned (Breaking Changes) where they separated table storage core services from other table storage extensions, to support independent versioning.

@johnkwaters

This comment has been minimized.

johnkwaters commented Oct 1, 2018

Looks like context.AddDashboardLogging; is obsolete now.

@johnkwaters

This comment has been minimized.

johnkwaters commented Oct 1, 2018

i still haven't seen a pattern for how to call a continuous job - this was present in 2.0. What's the replacement?

@snavarropino

This comment has been minimized.

snavarropino commented Oct 11, 2018

3 weeks ago sdk 3.0 was released. No guidance or samples are available, so this sdk is from my point of view unusable.
Do you have any target date to release them?

Almost every OS project have at least a Readme instructing users how they must use it ... this is very frustrating coming from Microsoft

@oising

This comment has been minimized.

oising commented Oct 23, 2018

Upgraded to 3.x from the 1.x template that ships with the "latest" azure web jobs sdk for visual studio 2017, and QueueTrigger and JobHostConfiguration just disappeared from the earth. Sigh..

I think it was a mistake to update the project template to use net 4.7.1 yet keep the 1.x webjobs code. If you guys had left the project at 4.5 or something beneath netstandard 2.0, then the upgrade path would have limited us to 2.x and kept the template code functional.

@gregnehus

This comment has been minimized.

gregnehus commented Nov 6, 2018

What happened to where you configure connection strings?
I had code like this:

config.StorageConnectionString = cfg["AzureWebJobsStorage"];
config.DashboardConnectionString = cfg["AzureWebJobsDashboard"];

I have a QueueTrigger and want to set the connection string for where to read from
I also need to set where to log to for the dashboard?

I was having an issue with the AzureWebJobsServiceBus connection string, but after some digging in the source:
image
I found that they had changed the connection string name to just ServiceBus. Maybe they followed the same pattern for AzureWebJobsStorage->Storage & AzureWebJobsDashboard->Dashboard.

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