Azure RoleInstance Id when scaling out, RoleEnvironmentTopologyChange not fired - azure

Will the first instance deployed always end with a zero ? 0. like "xxxx_IN_0"
When scaling up to X instanses, will the next instanses always get 1 2 3 4 as the last number. ( I think so).
What happens when I scale down again? I read that it will take at random one of the instances. So when scaling down to 1 instance, I cant assume that I know what ID is the one that still are running?.
Anyone who have been playing with the IDs when scaling up and down and know those things?
The reason for me asking is that I have some extra logic that I want to run on only one, not less or more, of the instances. If I can assume that the "xxx_IN_0" is always present then i can just do it with a simple check that last of ID is zero. If not, I am considering to check all ids and if the current instance is the lowest, then it will do its magic.
If the last case, are there an event i can monitor for when scaling up or down is done?.
update
From Answer:
if (RoleEnvironment.IsAvailable)
{
RoleEnvironment.Changed += RoleEnvironment_Changed;
}
void RoleEnvironment_Changed(object sender, RoleEnvironmentChangedEventArgs e)
{
var change = e.Changes.OfType<RoleEnvironmentTopologyChange>().FirstOrDefault();
if (change != null)
{
Trace.TraceInformation("RoleEnvironmentTopologyChange at RoleName '{0}'", change.RoleName);
}
I do not get any information in my tracelog when i scale up and down.
There have to be set a internal endpoint to trigger the events:
<InternalEndpoint name="InternalEndpoint1" protocol="http" />
http://blogs.msdn.com/b/windowsazure/archive/2011/01/04/responding-to-role-topology-changes.aspx

You should listen to the RoleEnvironment.Changed event which occurs when the service configuration is changed.
When you receive this event, check the Changes property for an instance of RoleEnvironmentTopologyChange. This change will be reported when the number of instances are changed.
To determine on which server you should run that extra logic you could examine the list of roles and from there find all instances. Sort instances by id and select the first to be the special one.
However, if it is critical that only a single server run this special logic at any time, you will need a more stable solution.

Related

Terraform providers - how would you represent a resource that doesn't have clearly defined CRUD operations?

For work I'm learning Go and Terraform. I read in their tutorial how the different contexts are defined but I'm not clear on exactly when these different contexts are called and what triggers them.
From looking at the Hashicups example it looks like when you put this:
resource "hashicups_order" "new" {
items {
coffee {
id = 3
}
quantity = 2
}
items {
coffee {
id = 2
}
quantity = 2
}
}
in your Terraform file that is going to go look at hashicups_order remove the hashicups prefix and look for a resource called order. The order resource provides the following contexts:
func resourceOrder() *schema.Resource {
return &schema.Resource{
CreateContext: resourceOrderCreate,
ReadContext: resourceOrderRead,
UpdateContext: resourceOrderUpdate,
DeleteContext: resourceOrderDelete,
What isn't clear to me is what triggers each context . From that example it seems like since you are increasing the value of quantity it will trigger the update context. If this were the first run and no previous state existed it would trigger create etc.
However it my case the resource is a server and one API resource I want to present to the user is server power control. However you would never "create/destroy" this resource... or would you? You could read the current power state and you could update the power state but, at least intuitively, you wouldn't create or destroy it. I'm having trouble wrapping my head around how this would be modeled in Terraform/Go. I conceptually understand the coffee resource in the example but I'm having trouble making the leap to imagining what that looks like as something like a server power capability or other things without a clear matching to the different CRUD operations.

WooCommerce Subscriptions: how to determine the last correctly paid order for a given subscription

Is there any already-programmed method to get the last correctly-paid order for a given subscription?
$subscription->get_last_order() will return the last associated order, no matter if that order involved a correct-payment or not.
$subscription->get_related_orders() will return the whole list of orders, and the list can include pending-payment or failed orders.
I think if you wrap / trigger $subscription->get_last_order() with the woocommerce_subscription_payment_complete action (https://docs.woocommerce.com/document/subscriptions/develop/action-reference/) you would essentially achieve that objective. That hook fires both for initial subscription orders and renewal orders and will ensure the $last_order is paid for. Something like this:
add_action( 'woocommerce_subscription_payment_complete', 'set_last_order' );
function set_last_order( $subscription ) {
$last_order = $subscription->get_last_order( 'all', 'any' );
// If you want to be able to reference that $last_order at any time
// then you could just save/update that order ID to post meta so
// that you can grab it any time outside of the action.
}
}
I know that seems a little clunky, but it's the best way I can think of. The only other option that comes to mind would be to loop through $subscription->get_related_orders() checking is_paid() from high IDs to low IDs and grabbing the first one from there.

Gamemaker variable using porals

I am remaking portal in gamemaker for my semester final, I was wondering how you find an object, if I have one portal down, and go into it, the game crashes, as the 2nd portal isn't placed, and it can't get its .x,.y pos. How do I set a variable to fix this?
We don't know how you determine the destination teleporter, you should clarify that. But one variant could be to check whether the amount of portals is >= 2, so you have at least one place to go
if (instance_number(your_portal_name) >= 2)
{
// proceed the portal mechanics
}
I assume that in some event you have a piece of code that does the teleporting. You just have to place this piece of code in an "if" statement that verifies if the second portal exists. This way, you will attempt teleportation only if the needed exit instance exists. You can use the "instance_exists" function
for example :
if ( instance_exists( exit_portal_or_whatever_you_name_it ) )
{
your_teleportation_code;
}
I would say that based on the information you gave us, German Gorodnev's answer is correct. If you only have one portal and you try to get the position of a non-existent portal, then you will get an error. So you should include an if statement that makes sure the needed portals are there before retrieving the positions.

How do I identify specific entity within a FlxGroup from FlxG.collide?

How do I make it so that when a bullet from the bullet group collides with an enemy from the enemy group, only the two hitting eachother will get affected?
I tried doing (In playstate):
if (FlxG.collide(bullet, enemy)){
bullet.kill();
enemy.kill();
}
But the only thing this succeeded in doing is killing the entire group. How do I only kill the ones affected?
In the Haxeflixel API docs:
collide(?ObjectOrGroup1:FlxBasic, ?ObjectOrGroup2:FlxBasic, ?NotifyCallback:Dynamic‑>Dynamic‑>Void):Bool
so I think you can use something like:
FlxG.collide(
groupBullets,
groupEnemies,
function (bullet:FlxObject, enemy:FlxObject):Void {
enemy.kill();
bullet.kill();
}
);
You want to pass in a notification callback:
https://github.com/HaxeFlixel/flixel/blob/24529ac96d4ad49a5f0c7e64799d0197cee9049e/flixel/FlxG.hx#L395
So something like this is what you want:
FlxG.collide(bulletGroup, enemyGroup, collideBulletEnemy));
function collideBulletEnemy(bullet:FlxObject, enemy:FlxObject):Void
{
bullet.kill();
enemy.kill();
}
Some more explanation:
The collide() function in flixel lets you pass in either an object or a group to either parameter, and tells you if those two things collide. In the case of two objects, you can directly follow that test up with logic operating on those two objects. But if one of the objects is a group, you don't know based on the test alone which things collided, so you need to rely on a callback you supply yourself to get that specific information.

Turn Based Participant Timeout Date Always NULL

Have been working on a two-player turn based game that uses a custom UI for match management. Considering restricting the app to iOS 6+ in order to use player timeouts. I would like to show the user the remaining amount of time to move, but the participant.timeoutDate is always null? Per the WWDC 2012 video (that says the timeout won't apply to the last participant in nextParticipants), I pass an array with two entries (opponent at index 0 and local player at index 1) when calling endTurnWithNextParticipants:turnTimeout:matchData:completionHandler: to take a turn. I've tried both GKTurnTimeoutDefault and various integer literals ... no luck ... always seems to be null. The player's last turn date works fine.
On the subject of player timeouts ... after I get them working, how is this delivered? I see GKTurnBasedMatchOutcomeTimeExpired ... does this come in a turn event?
From Apple's developer forum
Elian Gidoni -
+1
The doc should be:
timeoutDate
The date and time when the participant’s turn timed out. (read-only)

Resources