The application I'm working on has to be deployable on Azure and on a Windows Server.
I'm using a Continuous Azure WebJob, that has some methods with a [TimerTrigger] attribute, that work fine on Azure. But I would like them to trigger also when deployed on premises.
Is this something supported? What would be a recommended way to have the exe with the Azure WebJob SDK running on a Windows Server continuously from a DevOps perspective?
I'm using .NET Core 3 and the Microsoft.Azure.Webjobs 3.0 SDK.
You can consider the web job project as a console project, and just click the your_webjob.exe to run it continuously(by specifying TimerTrigger). And you can follow this article to create a .NET core webjob.
Here is an example:
1.Create a .NET core 3.0 console project, and install the following nuget packages:
Microsoft.Azure.WebJobs.Extensions, version 3.0.0
Microsoft.Azure.WebJobs.Extensions.Storage, version 3.0.10
Microsoft.Extensions.Logging.Console, version 3.0.0
2.Here is the code in program.cs:
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
var builder = new HostBuilder();
builder.ConfigureWebJobs(b =>
{
b.AddTimers();
b.AddAzureStorageCoreServices();
b.AddAzureStorage();
});
builder.ConfigureLogging((context, b) =>
{
b.AddConsole();
});
var host = builder.Build();
using (host)
{
host.Run();
}
}
}
}
3.Add appsettings.json file to the project, and then right click the appsettings.json file -> select properties -> set the "Copy to Output Directory" to "Copy if newer". Here is the appsettings.json:
{
"ConnectionStrings": {
"AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=xx;AccountKey=xxx;EndpointSuffix=core.windows.net"
}
}
Add a Functions.cs to the project. And here is the code in Functions.cs:
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
namespace ConsoleApp2
{
public class Functions
{
public static void CronJob([TimerTrigger("0 */1 * * * *")] TimerInfo timer, ILogger logger)
{
logger.LogInformation("this is a test message!");
}
}
}
5.Build the project, then go to the folder where your_webjob.exe is located, just double click the .exe file, it can run continuously on local:
Related
I am using expo sdk41, react navigation 5, and vercel to deploy a web-build, built with expo build:web.
When I am developing locally, I can deep link, e.g. http://localhost:19006/sign-in. However when I deploy it to vercel and assign a domain name to it, the deep linking does not work anymore.
I am already doing the following, which allows deep linking to work in development:
export const linking = {
prefixes: [Linking.createUrl('/'),
screens: {
...
}
}
Why is deep linking working in development and not when deployed to vercel?
I am happy to add more info if needs be.
Running expo build:web bundles a SPA and you need to redirect calls to the deployed app to index.html. Vercel allows configuring redirects using a vercel.json configuration file, placed at the root of a project.
Add a web/ folder in your Expo root directory and create a vercel.json file in the web/ folder with the following content:
{
"rewrites": [{ "source": "/(.*)", "destination": "/index.html" }]
}
This file will be copied to the web-build folder when you run expo build:web.
I was able to fix this by setting the framework in the setting to create-react-app
I am using wso2/soap package from ballerina central to create a simple soap connector.
import wso2/soap;
import ballerina/io;
endpoint soap:Client soapClient {
clientConfig:{
url: "http://localhost:9000"
}
};
function main (string... args) {
xml body = xml `<m0:getQuote xmlns:m0="http://services.samples">
<m0:request>
<m0:symbol>WSO2</m0:symbol>
</m0:request>
</m0:getQuote>`;
soap:SoapRequest soapRequest = {
soapAction: "urn:getQuote",
payload: body
};
var details = soapClient->
sendReceive("/services/SimpleStockQuoteService",soapRequest);
match details {
soap:SoapResponse soapResponse => io:println(soapResponse);
soap:SoapError soapError => io:println(soapError);
}
}
This code was initially building and running successfully with ballerina-0.975.0 version. Recently I have installed ballerina-0.980.0. After this I get the following error when trying to build the code.
Compiling source
package:0.0.0
ballerina: format error: ballerina: unsupported program file version 18
This occurs as I am trying to build using 0.980.0 and old the wso2/soap package is used from the home repository. Normal logic is, we check for the package in the home folder and if not found then we fetch from the ballerina central repository. This logic fails in this scenario as we are using a newer ballerina version. Newer ballerina version tries to use the existing soap package downloaded in the home folder and throws an error. Instead we should fetch the newer version of soap package from the ballerina central.
The issue will be fixed in future releases. For the time being, you can pull the latest version of the connector (which is compatible with Ballerina 0.980.0) using the following command and resolve the issue.
ballerina pull wso2/soap
Ionic version:
[ ] 3.X
Current behavior:
In my Application I have three options for login AWS Cognito Identity Provider , Google , facebook.
After successful login authentication when user moves to the Drivesetup Page, I set the Drivesetup Page as a root page (setRoot) but I'm facing a problem that user can easily go back again on login screen using mobile back button.
Expected behavior:
I am expecting that user can't go back to the login page by pressing mobile back button when I'm using setRoot to navigate the screen from login to dashboard.
Steps to reproduce:
Code Included.
GitHub Repo:-
https://github.com/saurabhschauhan/demoApp
Related code:
constructor(
public nav: Nav,
public app: App,
public navCtrl: NavController,) {
}
this.awsCredentialsService.login(data)
.then((awsCredentialsServiceResponse) => {
if (awsCredentialsServiceResponse['status'] == 'success') {
//navigate page
this.navCtrl.setRoot('DrivesetupPage');
//OR
//this.app.getRootNav().setRoot('DrivesetupPage');
//or
//this.nav.setRoot('DrivesetupPage');
this.toasterService.showToaster(email + `Logged in successfully`);
} else {
console.log('any other error');
}
})
Other information:
I had tried two more options this.app.getRootNav().setRoot('DrivesetupPage') and this.nav.setRoot('DrivesetupPage'); but both are not working for me.
Ionic info:
#ionic/cli-utils : 1.13.0
ionic (Ionic CLI) : 3.13.0
global packages:
cordova (Cordova CLI) : 7.1.0
local packages:
#ionic/app-scripts : 3.0.0
Cordova Platforms : android 6.3.0
Ionic Framework : ionic-angular 3.7.1
System:
Android SDK Tools : 26.1.1
Node : v6.9.1
npm : 3.10.8
OS : Linux 3.16
Misc:
backend : pro
Thank you.
There are development, test and production environments in Ember CLI.
I have test and production server. And I need to make build on test server like on production but with another environment configs. But test env in Ember CLI used for automatic tests.
I tried to call ember build --environment development on test server with next options in ember-cli-build.js file:
var app = new EmberApp(defaults, {
// Add options here
fingerprint: {
prepend: 'https://s-test.mycdn.com/',
enabled: true
}
});
But I got error:
The Broccoli Plugin: [AssetRewrite] failed with:
TypeError: Cannot read property '2' of null
.....
The broccoli plugin was instantiated at:
.....
What is right way to build ember application on test server?
This might be confusing, but what you want is not environments. You want deploy targets. Here's a great blog post about difference between the two: Do not confuse environment for deploy target (that URL has been trashed in a reorg/takeover of deveo.com but a snapshot exists on archive.org).
In Ember, environments are about how your code is minified, your assets are fingerprinted, enabling/disabling certain debugging features, etc. They are not about where you want to deploy your code, which API URL you want to use, or anything like that.
You might happen to have servers called test or development, but when deploying to these servers, you should always set environment to production, not test or development.
In order to support multiple servers (deploy targets), I would use env vars to do that. Something like:
DEPLOY_TARGET=development ember build --environment=production
DEPLOY_TARGET=test ember build --environment=production
DEPLOY_TARGET=staging ember build --environment=production
DEPLOY_TARGET=production ember build --environment=production
And in your ember-cli-deploy.js, you simply access the value through process.env.DEPLOY_TARGET, like this:
const deployTarget = process.env.DEPLOY_TARGET;
if (deployTarget === 'development') {
// ...
} else if (deployTarget === 'test') {
// ...
} else if (deployTarget === 'staging') {
// ...
} else if (deployTarget === 'production') {
// ...
}
I recommend using ember-cli-deploy addon to automate this process, so that you could just type ember deploy staging to create a build for staging and deploy it.
Unfortunately, support of environmements in ember-cli is poor. You have only development and production and can't add new ones. On top of that, production build does additional things like minifying, fingerprinting, etc, which are not necessarily needed on test/staging server and time consuming.
The good news is we have an access to Node API inside environment.js. In fact, environment.js is a node module. This allows us to add additional parameters to ember build and parse them. I'm successfuly using this trick in ember-cli 2.7 and used in 2.8 too. You will need to:
Install minimist: npm install minimist --save-dev
Add this code to the beginning of environment.js:
var argv = require('minimist')(process.argv.slice(2));
console.log('Sub-environment is set to ' + argv.subenv);
Use argv.subenv in environment.js to recognize different "sub-environments". I suggest to do this after "environment" blocks:
if (argv.subenv === 'mirage') {
ENV['ember-cli-mirage'] = {
enabled: true
};
ENV.API.namespace = '';
ENV.API.host = '';
}
if (argv.subenv === 'staging') {
ENV['ember-cli-mirage'] = {
enabled: false
};
ENV.API.host = 'https://your-server.com/';
ENV.API.namespace = '';
}
You can combine environment and argv.subenv in your code as you need.
Use your argument when building: ember build --environment=development --subenv=staging. Ember-cli will output a warning about non-supported arguments, but everything will work just fine.
Using this method, you can have as many servers as you need and build development/production version of app on any of them.
As for your error, I'm not sure what causing it, probably you may find something here
Edit your config/environment.js to set your environment when the param equals staging. For example:
```
function(environment) {
var ENV = {
// SET ENV properties
APP: {
// Here you can pass flags/options to your application instance
// when it is created
},
contentSecurityPolicy: {
// Configure security
}
};
if (environment === 'production') {
// Set production values
}
if (environment === 'staging') {
// Set staging values
}
if (environment === 'development') {
// Set staging values
}
if (environment === 'test') {
// Set testing values
}
return ENV;
};
```
And then when trying to build the version use the following command:
ember build --environment="staging"
Can anyone help me with or provide any sources for creating the Aws Elastic beanstalk Environment using java program and depoly our application in it?
Thank you in advance.
You can download the AWS Java SDK here. It is also in the maven repository:
Maven:
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.9.7</version>
</dependency>
Gradle:
'com.amazonaws:aws-java-sdk:1.9.7'
Now, onto using the sdk. You might want to read up on getting started with the aws sdk.
Here is some very watered down code to get you started:
import com.amazonaws.services.elasticbeanstalk.AWSElasticBeanstalkClient;
import com.amazonaws.services.elasticbeanstalk.model.*;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.PutObjectRequest;
import java.io.File;
public class AwsTest {
public static void main(String[] args) {
AWSElasticBeanstalkClient eb = new AWSElasticBeanstalkClient();
// Create Application
CreateApplicationRequest request = new CreateApplicationRequest("myAppName");
eb.createApplication(request);
// Create Environment
CreateEnvironmentRequest envRequest = new CreateEnvironmentRequest("myAppName", "env-name");
envRequest.setSolutionStackName("64bit Amazon Linux 2014.09 v1.0.9 running Tomcat 7 Java 7");
envRequest.setVersionLabel("application Version");
eb.createEnvironment(envRequest);
// Deploy code
CreateStorageLocationResult location = eb.createStorageLocation();
String bucket = location.getS3Bucket();
File file = new File("myapp.zip");
PutObjectRequest object = new PutObjectRequest(bucket, "myapp.zip", file);
new AmazonS3Client().putObject(object);
CreateApplicationVersionRequest versionRequest = new CreateApplicationVersionRequest();
versionRequest.setVersionLabel("myversion");
versionRequest.setApplicationName("myAppName");
S3Location s3 = new S3Location(bucket, "myapp.zip");
versionRequest.setSourceBundle(s3);
UpdateEnvironmentRequest updateRequest = new UpdateEnvironmentRequest();
updateRequest.setVersionLabel("myversion");
eb.updateEnvironment(updateRequest);
}
}
There is a small piece of code missing in the above given code under this section,
CreateApplicationVersionRequest versionRequest = new CreateApplicationVersionRequest();
versionRequest.setVersionLabel("myversion");
versionRequest.setApplicationName("myAppName");
S3Location s3 = new S3Location(bucket, "myapp.zip");
versionRequest.setSourceBundle(s3);
You need to add eb.createApplicationVersion(versionRequest); in order to create new version with your own source files. Only then you can deploy the new version to the running instance of the environment.
A convenient method for deploying an AWS Elastic Beanstalk environment is to use the AWS Toolkit for Eclipse.
It allows you to write and test your code locally, then create an Elastic Beanstalk environment and deploy your code to the environment.
The Elastic Beanstalk management console can also be used to deploy a Java environment with a Sample Application, which you can then override with your own code.
See also:
Deploying an Application Using AWS Elastic Beanstalk
AWS Elastic Beanstalk Documentation
Here is the updated AWS SDK for Java V2 to create an Environment for Elastic Beanstalk
Region region = Region.US_WEST_2;
ElasticBeanstalkClient beanstalkClient = ElasticBeanstalkClient.builder()
.region(region)
.build();
ConfigurationOptionSetting setting1 = ConfigurationOptionSetting.builder()
.namespace("aws:autoscaling:launchconfiguration")
.optionName("IamInstanceProfile")
.resourceName("aws-elasticbeanstalk-ec2-role")
.build();
CreateEnvironmentRequest applicationRequest = CreateEnvironmentRequest.builder()
.description("An AWS Elastic Beanstalk environment created using the AWS Java API")
.environmentName("MyEnviron8")
.solutionStackName("64bit Amazon Linux 2 v3.2.12 running Corretto 11")
.applicationName("TestApp")
.cnamePrefix("CNAMEPrefix")
.optionSettings(setting1)
.build();
CreateEnvironmentResponse response = beanstalkClient.createEnvironment(applicationRequest);
To learn how to get up and running with the AWS SDK for Java V2, see https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html.