Dan Nick
Dan Nick

Reputation: 426

Azure Web Jobs Calling it from C# with Parameters

I am trying to call a webjob from asp.net c# page. When I check the log it shows that it run but nothing is in the log except. It should say "Dan's Phone Number is 5551212"

[01/15/2015 14:29:18 > 898371: SYS INFO] Status changed to Initializing
[01/15/2015 14:29:20 > 898371: SYS INFO] Run script 'EncodeAsset.exe' with script host - 'WindowsScriptHost'
[01/15/2015 14:29:20 > 898371: SYS INFO] Status changed to Running
[01/15/2015 14:29:20 > 898371: SYS INFO] Status changed to Success

Here is my code:

public partial class Test : System.Web.UI.Page
{

    protected void Button1_Click(object sender, EventArgs e)
    {
        Process myProcess = new Process();
        myProcess.StartInfo.FileName = @"D:\home\site\wwwroot\app_data\jobs\triggered\EncodeAsset\EncodeAsset.exe";
        myProcess.Start();
    }
}

class Program
{
    // Please set the following connection strings in app.config for this WebJob to run:
    // AzureWebJobsDashboard and AzureWebJobsStorage
    static void Main()
    {
    }

    public static void Testing([QueueTrigger("queuejobs")]string message)
    {
        Console.WriteLine("Dan's Phone Number is:", message);
    }
}

Upvotes: 3

Views: 4198

Answers (3)

Pat
Pat

Reputation: 580

I would suggest using the Kudu API.

To run with arguments use the arguments parameters that will be added to the script when invoked. It also gets passed to the WebJob as the WEBJOBS_COMMAND_ARGUMENTS environment variable.

POST /api/triggeredwebjobs/{job name}/run?arguments={arguments}

Your url would look like this ultimately. Don't forget to pass credentials (username and password which you can find if you download your publish profile).

https://{site}.scm.azurewebsites.net/api/triggeredwebjobs/{jobname}/run?arguments={arguments}

Just depends what you want to do

Upvotes: 2

claytondus
claytondus

Reputation: 176

With a continuous WebJob, the idea is to trigger the function based off an Azure storage queue or blob event, not to directly invoke the function from your client code. Here, you have a QueueTrigger annotation, which is listening for new messages on the queuejobs queue. To invoke the WebJob function, you need to enqueue a string message on the same queue. To do this, you would do something like the following in your Button1_Click handler (From http://azure.microsoft.com/en-us/documentation/articles/storage-dotnet-how-to-use-queues):

// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
    CloudConfigurationManager.GetSetting("StorageConnectionString"));

// Create the queue client.
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();

// Retrieve a reference to a queue.
CloudQueue queue = queueClient.GetQueueReference("queuejobs");

// Create the queue if it doesn't already exist.
queue.CreateIfNotExists();

// Create a message and add it to the queue. 
CloudQueueMessage message = new CloudQueueMessage("5551212");
queue.AddMessage(message);

Upvotes: 2

Waseem Hassan
Waseem Hassan

Reputation: 231

Here's a sample on MSDN which is pretty straightforward. Hope that will help you https://code.msdn.microsoft.com/Simple-Azure-Website-with-b4391eeb

Upvotes: 1

Related Questions