1
votes

I am new to Azure WJs. I have 2 projects in one solution: the actual website - Project 2 and the WebJob - Project 1. The only task the WJ has is to call an exposed method from the public class of project 2 during the scheduled time.

When the WJ was created, the classes & methods of the Project 2 - website were added as a solution reference to the Project 1 - WebJob to make them accessible.

The problem I have is:

When the WebJob is build it compiles all the dependencies at the given time. When the final .zip is uploaded into Azure WebJob portal the webjob will execute with the compiled code version. This means that any new changes to Project 2 - website do not take effect until the WJ is re-build with the updated Project 2 - website dependencies and the .zip re-uploaded.

Is there a way to create WJ (as Project 1) which would call a specific exposed method from the Project 2 and be oblivious to the changes in the project 2 as long as the called method is present?

Example:

WebJob Code (project 1):

namespace SecondProject
{
    class Program
    {
        static void Main()
        {
            var client = new WebClient();
            secondProjectMethod();
        }
    }
}

Website Code (project 2):

namespace firstProject
{
    public class someClass
    {
        public void secondProjectMethod()
        {
            // I want to make any code changes I want inside this 
            // method anytime and the WbJob should not care
            // about these changes as long as this method name exist.
            // Because all it should care about is that it should
            // call this  method name.
        }
    }
}
3
Since you are using a website, you can expose the method from Proj2 as an API, and make the WebJob invoke the API (instead of the method) at your scheduled interval. So even if you change the method in Proj2, as long as the exposed API is calling the updated method the WebJob will be independent. - Pratik Bhattacharya
Yes, this seems to be the most logical solution. I wish there would be more API code examples available. Thx. - Milan

3 Answers

1
votes

Since you are using a website, you can expose the method from Proj2 as an API, and make the WebJob invoke the API (instead of the method) at your scheduled interval. So even if you change the method in Proj2, as long as the exposed API is calling the updated method the WebJob will be independent.
You can take a look at this link, for creating a basic API

1
votes

at least two options come up in my mind:

Options 1: your WJ project do not directly reference your website project, instead, use reflection load the website dll in runtime. and use reflection to invoke the function you would like to call (assume signature will never change)

the challenge for this approach is your WJ somehow need to figure out the path to the website dll.

Options 2: since it is a website, why not expose the function you will like to call as a REST API, so your WJ just need to make a http call

0
votes

The question doesn't seem to be a Web Job Specific one but anyways...

If you need the two projects to be independent, then you should not be using project references.

What I would suggest is to publish the Project2 shared class/methods as nuget packages and use the nuget instead, so any changes to the Project2 will not affect your WebJob until the point that you publish a new nuget package and use that your web job.

Alternatively you can have a folder for your dlls like "Shared Libraries" and reference the Project2 from that location instead of project to isolate the changes to your Web job from your Project reference..