How to excute one hyperledger composer transaction in two hours timeInterval - hyperledger-composer

async function autoGrantStarCoin(){
setInterval(function() {
process.nextTick(function(){
grantStarCoin()
})
}, 10000);
}
this way is wrong

Not sure if you are asking a question or stating the answer, however to confirm you should not set up any sort of automated timer inside node.js chaincode or a composer business network. This will not work and is not a good idea in general anyway (even if you do find a way to make it work)
You need to set a timer up client side and make the request.

Related

Using something other than cy.request to seed data in Cypress

I'm using Cypress for end-to-end testing. In my beforeEach, I'm using an SDK I've been provided to seed data on a server (the SDK sends API calls to the server but does not use cy.request inside it). The method on the SDK returns a promise, therefore I figured I could return the promise like so:
beforeEach(() => {
return sdk.createProperty(...);
});
My test then does something like this:
it('displays a property', () => {
cy.visit(`/companies/${appTestData.companyId}/properties`);
...the rest is commented out currently...
}
This actually works as intended, that is, it waits until the server response is returned before running the tests, but I see the following warning in the console when the test actually runs:
Cypress Warning: Cypress detected that you returned a promise in a test, but also invoked one or more cy commands inside of that promise...
I noticed if I change my beforeEach to use cy.then, the warning goes away:
beforeEach(() => {
cy.then(() => sdk.createProperty(...));
});
It seems a bit unnecessary and was kind of a stab in the dark, so I'd like to know if there's a prescribed way of doing what I need to do. I can't change the SDK I'm using to use cy.request, which I assume would also prevent the warning. Thanks.
Probably not what you want to hear, but can I confirm you that using cy.then(...) is the most standard way of waiting for a Promise in Cypress I know of.
After reading your question, I have tried to use Cypress Network Requests features to wait for a fetch('my/url') in a before(), but it doesn't seem to be detecting the request at all.

Force upgrade after fallback to polling?

This may be a stupid question, but i am wondering if there is a way to force socket.io to periodically retry to use websocket as transport instead of polling?
I noticed that sometimes my application cannot establish a websocket connection (Handshake failed: ERR_CONNECTION_RESET). Socket.io correctly falls back to polling then, but it never seems to try to switch back to websockets again, even if it would work. Is my observation correct?
If so, what would you suggest?
Please let me know if you need any code. I couldn't really think of a relevant code example, since this is more like a theoretical question.
Socket.io correctly falls back to polling then, but it never seems to try to switch back to websockets again, even if it would work. Is my observation correct?
Yes, correct.
If so, what would you suggest?
I dont think its a job of a lib to try to reastablish connection. You can set your own listener, that checks server availability - some times servers crash and users wont notice that they dont have connection anymore...
Kinda example of what we have on client side, hope it helps digging.
//If sockets close
window.ws.onclose = function (e) {
ws.onclose = null;
ws.onerror = null;
ws.onopen = null;
// restart sockets in: 3000 ms
setTimeout(function () { ctx.createWS(); }, 3000);
};
window.ws.onerror = function (error) {
//On error we will try to restart sockets in function described before
ws.close();
};

How do I know when an Amazon EC2 operation is complete?

Besides polling, how can I tell when a long-running Amazon EC2 operation is complete? For example, using the CreateImage API function can take upwards of several minutes.
Right now I'm doing this:
// MAKE THE API CALL
var createRequest = new CreateImageRequest().WithInstanceId("i-123456").WithName("MyNewAMI");
var createResponse = myAmazonEC2Client.CreateImage(createRequest);
var imageId = createResponse.CreateImageResult.ImageId;
// ICKY POLLING CODE
bool isImaging = true;
while (isImaging)
{
var describeRequest = new DescribeImagesRequest().WithImageId(imageId);
var describeResponse = myAmazonEC2Client.DescribeImages(describeRequest);
isImaging = describeResponse.DescribeImagesResult.Image.Single().ImageState == "pending";
Thread.Sleep(10000); // sleep for 10 seconds
}
// CreateImage IS COMPLETE; MOVE ON WITH OUR WORK
I hate this. After calling CreateImage, I'd like to just get notified somehow that it's all done and move on. Is this possible? I'm using the AWS .NET SDK in this example, but I'm not looking specifically for a C# solution.
UPDATE: Cross-posted to the AWS Forums
Some events in amazon can be configured to send notifications to an SNS Topic. For example when using auto scaling you can have notifications when a server is launched and terminated. As far as I know there is no way to trigger these notifications for other services such as CreateImage. I've looked for this type of feature in the past with no luck. I was trying to do it to create a script that would launch servers in a specific order. I wound up just polling their API as I couldn't find any way to register to those events.
James Hunter Ross answered this question over on the AWS Forums as follows:
Polling is it. That said, since you have a C# program started, why not let it spawn a polling process that notifies you as you wish? It seems you are almost done, in some respects.
(Of course, it would be nice if such functionality was built-in at AWS.)
I wasn't able to find a StackOverflow profile for him, but if he shows up I'll edit this to give him credit.

socket.io - Catch all event

I'm working on a Node.js application where pretty much all the communication is taking place via sockets.io.
What I need to do is, before processing any request (other than the login request) ensure that the user is authenticated.
The obvious way to do this would be to have a catch-all listener which is called prior to the execution of any method.
I can't seem to find anything like this in Socket.io, though. How can I achieve is? Is there a better approach than the one I'm taking?
The best approach here would be to authenticate the user upon connection (handshake), by parsing the cookie and decoding the session.
Read more about this in the following links:
http://www.danielbaulig.de/socket-ioexpress/ (this contains a detailed tutorial of everything you need to do)
https://github.com/LearnBoost/socket.io/wiki/Authorizing
socket.io and session?
Checkout out socket.io-events on nom for "Catching all events"
var router = requrie('socket.io-events')();
router.on('*', function (sock, args, cb) {
//do something with the args!
cb();
});
var io = require('socket.io')(3000);
Checkout out socket.io-handshake on nom for "socket.io v1.x session support"

Monitor file change through AJAX, how?

I'm looking for a way through AJAX (not via a JS framework!) to real time monitor a file for changes. If changes where made to that file, I need it to give an alert message. I'm a total AJAX noob, so please be gentle. ;-)
Edit: let me explain the purpose a bit more in detail. I'm using a chat script I've written in PHP for a webhop, and what I want is from an admin module monitor the chat requests. The chats are stored in text files, and if someone starts a chat session a new file is created. If that's the case, in the admin module I want to see that in real time.
Makes sense?
To monitor a file for changes with AJAX you could do something like this.
var previous = "";
setInterval(function() {
var ajax = new XMLHttpRequest();
ajax.onreadystatechange = function() {
if (ajax.readyState == 4) {
if (ajax.responseText != previous) {
alert("file changed!");
previous = ajax.responseText;
}
}
};
ajax.open("POST", "foo.txt", true); //Use POST to avoid caching
ajax.send();
}, 1000);
I just tested it, and it works pretty well, but I still maintain that AJAX is not the way to go here. Comparing file contents will be slow for big files. Also, you mentionned no framework, but you should use one for AJAX, just to handle the cross-browser inconsistencies.
AJAX is just a javascript, so from its definition you do not have any tool to get access to file unless other service calls an js/AJAX to notify about the change.
I've done that from scratch recently.
I don't know how much of a noob you are with PHP (it's the only server script language I know), but I'll try to be as brief as possible, feel free to ask any doubt.
I'm using long polling, which consists in this (
Create a PHP script that checks the content of the file periodically and only responds when it sees any change (it could include a description of the change in the response)
Create your XHR object
Include your notification code as a callback function (it can use the description)
Make the request
The PHP script will start checking the file, but won't reply until there is a change
When it responds, the callback will be called and your notification code will launch
If you don't care about the content of the file, only that it has been changed, you can check the last-modified time instead of the content in the PHP script.
EDIT: from some comment I see there's something to monitor file changes called FAM, that seems to be the way to go for the PHP script

Resources