Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Webjobs - call method with parameter and invoke binding

I´m playing a bit more with the web Jobs sdk and I just need to call a method via a scheduler and it should write 1-n files to the storage. The good part of the WebJobs SDK is that I don´t need to include the Azure Storage SDK and everything is "binded". It works when I specify the filename, but my "WriteCustomFile" method just writes a file called "{name}"

Code:

class Program
{
    static void Main(string[] args)
    {
        JobHost host = new JobHost();
        host.Call(typeof(Program).GetMethod("WriteFile"));
        host.Call(typeof(Program).GetMethod("WriteCustomFile"), new { name = "Helloworld1.txt" });
        host.Call(typeof(Program).GetMethod("WriteCustomFile"), new { name = "Helloworld2.txt" });
        host.Call(typeof(Program).GetMethod("WriteCustomFile"), new { name = "Helloworld3.txt" });
        //host.RunAndBlock();
    }

    [NoAutomaticTrigger]
    public static void WriteFile([Blob("container/foobar.txt")]TextWriter writer)
    {
        writer.WriteLine("Hello World..." + DateTime.UtcNow.ToShortDateString() + " - " + DateTime.UtcNow.ToShortTimeString());
    }

    [NoAutomaticTrigger]
    public static void WriteCustomFile(string name, [Blob("container/{name}")] TextWriter writer)
    {
        writer.WriteLine("Hello World New ..." + name + ":" + DateTime.UtcNow.ToShortDateString() + " - " + DateTime.UtcNow.ToShortTimeString());
    }
}

What I would like to achieve is just to call the "WriteCustomFile" with a given filename. All samples that I found are using the "Blob Input / Output" idea in mind. I found this sample, but it seems more like a hack ;) http://thenextdoorgeek.com/post/WAWS-WebJob-to-upload-FREB-files-to-Azure-Storage-using-the-WebJobs-SDK

Is there currently a way to do this?

like image 907
Robert Muehsig Avatar asked Feb 12 '23 14:02

Robert Muehsig


1 Answers

WebJobs SDK 3.0.1 does not support the "fancy" parameter binding for Host.Call (and invoke from dashboard) - we'll add that in a future version.

For now, the workaround is to explicitly specify the path to the blob:

static void Main(string[] args)
{
    JobHost host = new JobHost();
    host.Call(
        typeof(Program).GetMethod("WriteCustomFile"), 
        new { 
            name = "Helloworld1.txt", 
            writer = "container/Helloworld1.txt" });
}

[NoAutomaticTrigger]
public static void WriteCustomFile(string name, [Blob("container/{name}")] TextWriter writer)
{
    writer.WriteLine("Hello World New ..." + name + ":" + DateTime.UtcNow.ToShortDateString() + " - " + DateTime.UtcNow.ToShortTimeString());
}
like image 76
Victor Hurdugaci Avatar answered Feb 19 '23 20:02

Victor Hurdugaci