Skip to content
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

Creating scheduled WebJobs #1452

Closed
AndreiBarsan opened this issue Feb 6, 2015 · 23 comments

Comments

Projects
None yet
3 participants
@AndreiBarsan
Copy link

commented Feb 6, 2015

The existing API allows us to create and run triggered and and continuous WebJobs.

However, using the Azure Portal GUI, scheduled jobs can also be added manually. However, they require a script/program to be manually uploaded (in .zip format), which is inconvenient given that you probably want your WebJob code to be updated automatically every time you deploy your website (as is the case with triggered and continuous jobs).

Would it be possible to add the option of adding source-controlled scheduled WebJobs to websites?

@davidebbo

This comment has been minimized.

Copy link
Member

commented Feb 6, 2015

The way to do this is via an ARM template which sets up both the site and the scheduler pointing to the WebJobs. But we need to get a sample out there, as it's not straightforward to write. I'll put that on my list. :)

@AndreiBarsan

This comment has been minimized.

Copy link
Author

commented Feb 6, 2015

Oh, that would be pretty nice! Thank you very much for the response.

I currently have a pretty hacky solution that does this (I have a scheduled runbook that contains a bit of PowerShell needed to invoke my "manual" WebJob"), but I was hoping that there was a better way.

Any reason why the current solution requires a zip upload? Is there a clever way to maybe build something, put the binaries onto Azure Storage, zip them, and set them up from there automatically?

@davidebbo

This comment has been minimized.

Copy link
Member

commented Feb 6, 2015

It does not require a zip upload. It just a matter of getting the files in the right place by whatever mean (details here). You can do this via WebDeploy, FTP, git, etc... See this article for info on doing it from VS.

But the scheduler part is mostly orthogonal, and that's where the ARM template comes in.

@AndreiBarsan

This comment has been minimized.

Copy link
Author

commented Feb 6, 2015

Yeah, I was referring to the fact that something like adding something like site\wwwroot\App_Data\jobs\scheduled\myjob will currently not work (i.e. this is a situation where you have to use a zip upload); or am I mistaken?

@davidebbo

This comment has been minimized.

Copy link
Member

commented Feb 6, 2015

Not following you. There is no need to upload a zip. YOu can get the files in those folder by any deployment mean. e.g. VS does it for you, or you can write custom deployment script, or simply have your repo match that shape if you like. In the end, it's just a folder convention with no prescription on how to get the files there.

@AndreiBarsan

This comment has been minimized.

Copy link
Author

commented Feb 6, 2015

I see. I'm actually using the third option (I have an App_Data\Jobs\triggered\mycronthing tree inside my repo). But this only works for triggered and continuous jobs, right?

@davidebbo

This comment has been minimized.

Copy link
Member

commented Feb 6, 2015

Technically, these are the only two types of jobs we have. :) Scheduled jobs work by having an external scheduler pointing at them, but Kudu itself doesn't care who is making the call (e.g. you could use a 3rd partu scheduler).

Ad this is where the ARM template comes in, to set up both the scheduler and the Webjobs.

@AndreiBarsan

This comment has been minimized.

Copy link
Author

commented Feb 9, 2015

I see. Interesting. So it would seem that my "hack" isn't that much of a hack after all, haha.
Thanks for the clarifications! I'll keep an eye on the project for when the appropriate ARM templates are added.

@davidebbo

This comment has been minimized.

Copy link
Member

commented Feb 17, 2015

Here is a sample repo that shows what this looks like: https://github.com/davidebbo-test/CloudDeploymentProjectWebJob. Specifically, the template logic that sets up the schedule is here.

@AndreiBarsan

This comment has been minimized.

Copy link
Author

commented Feb 17, 2015

Awesome! Thanks for the example!

@davidebbo

This comment has been minimized.

Copy link
Member

commented Feb 17, 2015

More info about Cloud Deployment Projects here. It's still a bit rough and requires manual editing of the ARM template, but it's the general direction that things are going in. Let me know if you have questions/feedback.

@AndreiBarsan

This comment has been minimized.

Copy link
Author

commented Feb 17, 2015

Awesome. I'm not able to use Visual Studio at this point, but thank you for the info!

@yogsgit

This comment has been minimized.

Copy link

commented May 26, 2016

Considering that the above discussion took place over a year back, do we now have a way that a scheduled job can be deployed using ARM template and without the need for an external scheduler? My exact scenario is that i am deploying a website and a webjob with it using the 'Deploy to Azure' button in Github. As mentioned in this thread, the only way i am able to have a scheduled webjob is by using a Scheduler Job. I want to get rid of this external scheduler and make it work the way a scheduled web job works when we upload the files in a zip using the management portal. Is it possible using the ARM template and 'Deploy to Azure'?

@davidebbo

This comment has been minimized.

Copy link
Member

commented May 26, 2016

Indeed, there is now a very simple way of doing it, by just including a settings.job with a cron expression with your WebJobs files. See documentation for details.

@yogsgit

This comment has been minimized.

Copy link

commented May 26, 2016

Thanks. I set a schedule in the settings.job file and it got deployed along with all other webjob files (checked on kudu) but still the webjob remained as 'on demand' and didn't run even once. My Github repository which i am deploying https://github.com/yogsgit/AzureResourceUsageDashboard_RatecardAPI .

@davidebbo

This comment has been minimized.

Copy link
Member

commented May 26, 2016

The fact that it still shows as On Demand in portal is a known issue that will be addressed soon. But that doesn't affect how it actually runs.

Please use Kudu Console to check whether your seetings file got deployed next to your webjob. What cron expression did you use?

@yogsgit

This comment has been minimized.

Copy link

commented May 26, 2016

I checked in Kudu Console and i can see the settings.job file deployed with other webjob files at D:\home\site\wwwroot\app_data\jobs\triggered\MyWebJob>.
I used the cron expression from the documentation
{
"schedule": "0 */2 * * * *"
}

@davidebbo

This comment has been minimized.

Copy link
Member

commented May 26, 2016

Can you share your web app name, either directly or indirectly? This will help us investigate. Thanks!

@yogsgit

This comment has been minimized.

Copy link

commented May 27, 2016

@davidebbo

This comment has been minimized.

Copy link
Member

commented May 27, 2016

Your settings.jobs in your repo is corrupted with HTML markup:

<p>
    { &quot;schedule&quot;: &quot;0 */2 * * * *&quot; }</p>

Do you know how you got into such state?

@yogsgit

This comment has been minimized.

Copy link

commented May 27, 2016

Now that is bad. Yes that was the issue. Actually i just copied the settings.job CRON expression from the documentation. I did it in Visual Studio and pushed it to Github from there. Its showing fine in Visual Studio though, no HTML markup! Thanks for your help and apologies for wasting your time.

@davidebbo

This comment has been minimized.

Copy link
Member

commented May 27, 2016

No problem, glad it's figured out. Though the VS behavior is very puzzling. The settings file should be treated as plain text, and I would expect it to show all this markup explicitly. I could see this happening is it's treating it as HTML, which somehow is probably what happened.

@yogsgit

This comment has been minimized.

Copy link

commented May 27, 2016

Yes not sure about the VS behaviour. From what i remember, i had created a text file only. Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.