Ejemplo n.º 1
0
        private async Task RunUSQLScriptFlowAsync()
        {
            var variables = new Dictionary <string, object>();

            var jobName = ConsoleEx.ReadLine("Job Name", "MyDlaJob");
            var path    = ConsoleEx.ReadLine("Path to U-SQL File", @"c:\tmp\job.usql", s => File.Exists(s));
            var script  = File.ReadAllText(path);

            Console.WriteLine("Parameters");

            while (true)
            {
                var name = ConsoleEx.ReadLine("Parameter <Blank to Continue>");
                if (string.IsNullOrWhiteSpace(name))
                {
                    break;
                }

                var val = ConsoleEx.ReadLine($"Value for @{name}");

                variables.Add(name, val);
            }

            // Authenticate against Azure AD once and re-use for all needed purposes
            var serviceClientCredentials = await ApplicationTokenProvider.LoginSilentAsync(
                Config.Root[Config.NAH_AAD_Domain],
                new ClientCredential(Config.Root[Config.NAH_AAD_CLIENTID], Config.Root[Config.NAH_AAD_CLIENTSECRET]));

            var jm = new DataLakeAnalyticsJobManager(serviceClientCredentials,
                                                     Config.Root[Config.NAH_AZURE_SUBSCRIPTIONID], Config.Root[Config.NAH_AZURE_DLA_ACCOUNTNAME]);
            var jobId = await jm.SubmitJobAsync(jobName, script, variables);

            await jm.WaitForJobAsync(jobId);
        }
Ejemplo n.º 2
0
        private async Task StartJobSchedulerAsync()
        {
            if (s_cancellationTokenSource != null)
            {
                Console.WriteLine("Job scheduler is already running. No action performed");
                return;
            }

            s_cancellationTokenSource = new CancellationTokenSource();
            s_cancellationToken       = s_cancellationTokenSource.Token;

            // Authenticate against Azure AD once and re-use for all needed purposes
            var serviceClientCredentials = await ApplicationTokenProvider.LoginSilentAsync(
                Config.Root[Config.NAH_AAD_Domain],
                new ClientCredential(Config.Root[Config.NAH_AAD_CLIENTID], Config.Root[Config.NAH_AAD_CLIENTSECRET]));

            var storageConnectionstring = Config.Root[Config.NAH_EHLISTENER_STORAGECONNECTIONSTRING];

            var stateProvider    = new BlobJobStateProvider(storageConnectionstring);        // Responsible for state
            var runDailyAtFiveAM = new DailySchedule(05, 00, 00);
            var syncProvider     = new BlobSynchronizationProvider(storageConnectionstring); // Responsible for Singleton Implementation
            var jobExecutor      = new JobExecutor(syncProvider, stateProvider);

            await Task.Run(async() =>
            {
                while (true)
                {
                    if (s_cancellationToken.IsCancellationRequested)
                    {
                        Console.WriteLine("Cancellation Requested. Stopping job scheduler");
                        return;
                    }

                    var job1Task = jobExecutor.RunAsSingletonAsync(job1, runDailyAtFiveAM, async(d) =>
                    {
                        // variable d is of type DateTime and is set to the date and time when the job
                        // was supposed to have run, i.e. on the hour of whatever hour we should have run on

                        var jobManager = new DataLakeAnalyticsJobManager(serviceClientCredentials,
                                                                         Config.Root[Config.NAH_AZURE_SUBSCRIPTIONID], Config.Root[Config.NAH_AZURE_DLA_ACCOUNTNAME]);

                        // Set parameters and others here
                        string script = File.ReadAllText(_jobToUSQLFiles[job1]);
                        await jobManager.SubmitJobAsync(job1, script, null);
                    });

                    var job2Task = jobExecutor.RunAsSingletonAsync(job2, runDailyAtFiveAM, async(d) =>
                    {
                        var jobManager = new DataLakeAnalyticsJobManager(serviceClientCredentials,
                                                                         Config.Root[Config.NAH_AZURE_SUBSCRIPTIONID], Config.Root[Config.NAH_AZURE_DLA_ACCOUNTNAME]);
                        string script = File.ReadAllText(_jobToUSQLFiles[job2]);
                        await jobManager.SubmitJobAsync(job2, script, null);
                    });

                    var job3Task = jobExecutor.RunAsSingletonAsync(job3, runDailyAtFiveAM, async(d) =>
                    {
                        var jobManager = new DataLakeAnalyticsJobManager(serviceClientCredentials,
                                                                         Config.Root[Config.NAH_AZURE_SUBSCRIPTIONID], Config.Root[Config.NAH_AZURE_DLA_ACCOUNTNAME]);
                        string script = File.ReadAllText(_jobToUSQLFiles[job3]);
                        await jobManager.SubmitJobAsync(job3, script, null);
                    });

                    Task.WaitAll(job1Task, job2Task, job3Task);

                    await Task.Delay(_waitTimeSpan, s_cancellationToken);
                }
            }, s_cancellationToken);
        }