How to cancel a queue triggered Azure WebJob programatically
up vote
0
down vote
favorite
I have deployed a Continuous Azure WebJob containing a procedure that gets triggered from Queue messages.
public Task Automation([QueueTrigger("automqueue")] string message, TextWriter log, CancellationToken token)
{
....
}
The procedure contains a CancellationToken
that is used from the system for graceful shutdown.
Is there any programmatical way to trigger this CancellationToken
when the user wants to cancel the process?
My automation needs allot of resources to finish and sometimes it might take several hours to be completed. This is why the user might want to cancel the process and start another.
Can I use the CancellationToken
that i already have or I need to implement a custom solution?
azure azure-webjobs cancellation-token
add a comment |
up vote
0
down vote
favorite
I have deployed a Continuous Azure WebJob containing a procedure that gets triggered from Queue messages.
public Task Automation([QueueTrigger("automqueue")] string message, TextWriter log, CancellationToken token)
{
....
}
The procedure contains a CancellationToken
that is used from the system for graceful shutdown.
Is there any programmatical way to trigger this CancellationToken
when the user wants to cancel the process?
My automation needs allot of resources to finish and sometimes it might take several hours to be completed. This is why the user might want to cancel the process and start another.
Can I use the CancellationToken
that i already have or I need to implement a custom solution?
azure azure-webjobs cancellation-token
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have deployed a Continuous Azure WebJob containing a procedure that gets triggered from Queue messages.
public Task Automation([QueueTrigger("automqueue")] string message, TextWriter log, CancellationToken token)
{
....
}
The procedure contains a CancellationToken
that is used from the system for graceful shutdown.
Is there any programmatical way to trigger this CancellationToken
when the user wants to cancel the process?
My automation needs allot of resources to finish and sometimes it might take several hours to be completed. This is why the user might want to cancel the process and start another.
Can I use the CancellationToken
that i already have or I need to implement a custom solution?
azure azure-webjobs cancellation-token
I have deployed a Continuous Azure WebJob containing a procedure that gets triggered from Queue messages.
public Task Automation([QueueTrigger("automqueue")] string message, TextWriter log, CancellationToken token)
{
....
}
The procedure contains a CancellationToken
that is used from the system for graceful shutdown.
Is there any programmatical way to trigger this CancellationToken
when the user wants to cancel the process?
My automation needs allot of resources to finish and sometimes it might take several hours to be completed. This is why the user might want to cancel the process and start another.
Can I use the CancellationToken
that i already have or I need to implement a custom solution?
azure azure-webjobs cancellation-token
azure azure-webjobs cancellation-token
asked Nov 22 at 16:42
Menelaos Vergis
1,8221624
1,8221624
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
CancelationToken
is only for shutdown notification, it is shared among all Process instances and cannot be used for other reasons.
And it is only for read, you could not change it manually , so maybe you could create a new CancellationTokenSource
and combine the tokens into one token that will be cancelled if any of the tokens is cancelled.
Here is my code.
public static void ProcessQueueMessage(
[QueueTrigger("queue2")] string message,
ILogger logger, CancellationToken token
)
{
CancellationTokenSource tokenSource = new CancellationTokenSource();
string flag;
CancellationTokenSource compositeTokenSource =
CancellationTokenSource.CreateLinkedTokenSource(
tokenSource.Token, token);
if (message.Equals("shutdown"))
{
logger.LogInformation(message);
tokenSource.Cancel();
flag = compositeTokenSource.Token.IsCancellationRequested.ToString();
logger.LogInformation(flag);
}
else {
logger.LogInformation(message);
flag = compositeTokenSource.Token.IsCancellationRequested.ToString();
logger.LogInformation(flag);
}
}
If the message equals "shutdown", the method Cancel()
will be executed. Then the property IsCancellationRequested
of composite token will be true
.
Hope this will help you, if you still have questions, please let me know.
I want to send aCancellationToken
to a running process, this example uses the queue with a new message.
– Menelaos Vergis
Nov 23 at 8:20
@Menelaos Vergis I know what you mean , you want to change CancellationToken to true , but the Token can only be read. So i try to implement it with a compositeTokenSource. And you must want to run normally if you don't want it shutdown. That's why i use message,you also could implement it with other ways.
– George Chen
Nov 23 at 9:08
Thank you for your insights, I understand now that thisCancelationToken
is only for shutdown notification, is shared among all Process instances and cannot be used for other reasons. Please add this information at your answer so I can mark it as solution
– Menelaos Vergis
Nov 23 at 9:39
@Menelaos Vergis Thanks,i have edited it.
– George Chen
Nov 23 at 9:50
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53435254%2fhow-to-cancel-a-queue-triggered-azure-webjob-programatically%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
CancelationToken
is only for shutdown notification, it is shared among all Process instances and cannot be used for other reasons.
And it is only for read, you could not change it manually , so maybe you could create a new CancellationTokenSource
and combine the tokens into one token that will be cancelled if any of the tokens is cancelled.
Here is my code.
public static void ProcessQueueMessage(
[QueueTrigger("queue2")] string message,
ILogger logger, CancellationToken token
)
{
CancellationTokenSource tokenSource = new CancellationTokenSource();
string flag;
CancellationTokenSource compositeTokenSource =
CancellationTokenSource.CreateLinkedTokenSource(
tokenSource.Token, token);
if (message.Equals("shutdown"))
{
logger.LogInformation(message);
tokenSource.Cancel();
flag = compositeTokenSource.Token.IsCancellationRequested.ToString();
logger.LogInformation(flag);
}
else {
logger.LogInformation(message);
flag = compositeTokenSource.Token.IsCancellationRequested.ToString();
logger.LogInformation(flag);
}
}
If the message equals "shutdown", the method Cancel()
will be executed. Then the property IsCancellationRequested
of composite token will be true
.
Hope this will help you, if you still have questions, please let me know.
I want to send aCancellationToken
to a running process, this example uses the queue with a new message.
– Menelaos Vergis
Nov 23 at 8:20
@Menelaos Vergis I know what you mean , you want to change CancellationToken to true , but the Token can only be read. So i try to implement it with a compositeTokenSource. And you must want to run normally if you don't want it shutdown. That's why i use message,you also could implement it with other ways.
– George Chen
Nov 23 at 9:08
Thank you for your insights, I understand now that thisCancelationToken
is only for shutdown notification, is shared among all Process instances and cannot be used for other reasons. Please add this information at your answer so I can mark it as solution
– Menelaos Vergis
Nov 23 at 9:39
@Menelaos Vergis Thanks,i have edited it.
– George Chen
Nov 23 at 9:50
add a comment |
up vote
1
down vote
accepted
CancelationToken
is only for shutdown notification, it is shared among all Process instances and cannot be used for other reasons.
And it is only for read, you could not change it manually , so maybe you could create a new CancellationTokenSource
and combine the tokens into one token that will be cancelled if any of the tokens is cancelled.
Here is my code.
public static void ProcessQueueMessage(
[QueueTrigger("queue2")] string message,
ILogger logger, CancellationToken token
)
{
CancellationTokenSource tokenSource = new CancellationTokenSource();
string flag;
CancellationTokenSource compositeTokenSource =
CancellationTokenSource.CreateLinkedTokenSource(
tokenSource.Token, token);
if (message.Equals("shutdown"))
{
logger.LogInformation(message);
tokenSource.Cancel();
flag = compositeTokenSource.Token.IsCancellationRequested.ToString();
logger.LogInformation(flag);
}
else {
logger.LogInformation(message);
flag = compositeTokenSource.Token.IsCancellationRequested.ToString();
logger.LogInformation(flag);
}
}
If the message equals "shutdown", the method Cancel()
will be executed. Then the property IsCancellationRequested
of composite token will be true
.
Hope this will help you, if you still have questions, please let me know.
I want to send aCancellationToken
to a running process, this example uses the queue with a new message.
– Menelaos Vergis
Nov 23 at 8:20
@Menelaos Vergis I know what you mean , you want to change CancellationToken to true , but the Token can only be read. So i try to implement it with a compositeTokenSource. And you must want to run normally if you don't want it shutdown. That's why i use message,you also could implement it with other ways.
– George Chen
Nov 23 at 9:08
Thank you for your insights, I understand now that thisCancelationToken
is only for shutdown notification, is shared among all Process instances and cannot be used for other reasons. Please add this information at your answer so I can mark it as solution
– Menelaos Vergis
Nov 23 at 9:39
@Menelaos Vergis Thanks,i have edited it.
– George Chen
Nov 23 at 9:50
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
CancelationToken
is only for shutdown notification, it is shared among all Process instances and cannot be used for other reasons.
And it is only for read, you could not change it manually , so maybe you could create a new CancellationTokenSource
and combine the tokens into one token that will be cancelled if any of the tokens is cancelled.
Here is my code.
public static void ProcessQueueMessage(
[QueueTrigger("queue2")] string message,
ILogger logger, CancellationToken token
)
{
CancellationTokenSource tokenSource = new CancellationTokenSource();
string flag;
CancellationTokenSource compositeTokenSource =
CancellationTokenSource.CreateLinkedTokenSource(
tokenSource.Token, token);
if (message.Equals("shutdown"))
{
logger.LogInformation(message);
tokenSource.Cancel();
flag = compositeTokenSource.Token.IsCancellationRequested.ToString();
logger.LogInformation(flag);
}
else {
logger.LogInformation(message);
flag = compositeTokenSource.Token.IsCancellationRequested.ToString();
logger.LogInformation(flag);
}
}
If the message equals "shutdown", the method Cancel()
will be executed. Then the property IsCancellationRequested
of composite token will be true
.
Hope this will help you, if you still have questions, please let me know.
CancelationToken
is only for shutdown notification, it is shared among all Process instances and cannot be used for other reasons.
And it is only for read, you could not change it manually , so maybe you could create a new CancellationTokenSource
and combine the tokens into one token that will be cancelled if any of the tokens is cancelled.
Here is my code.
public static void ProcessQueueMessage(
[QueueTrigger("queue2")] string message,
ILogger logger, CancellationToken token
)
{
CancellationTokenSource tokenSource = new CancellationTokenSource();
string flag;
CancellationTokenSource compositeTokenSource =
CancellationTokenSource.CreateLinkedTokenSource(
tokenSource.Token, token);
if (message.Equals("shutdown"))
{
logger.LogInformation(message);
tokenSource.Cancel();
flag = compositeTokenSource.Token.IsCancellationRequested.ToString();
logger.LogInformation(flag);
}
else {
logger.LogInformation(message);
flag = compositeTokenSource.Token.IsCancellationRequested.ToString();
logger.LogInformation(flag);
}
}
If the message equals "shutdown", the method Cancel()
will be executed. Then the property IsCancellationRequested
of composite token will be true
.
Hope this will help you, if you still have questions, please let me know.
edited Nov 23 at 9:49
answered Nov 23 at 7:04
George Chen
2707
2707
I want to send aCancellationToken
to a running process, this example uses the queue with a new message.
– Menelaos Vergis
Nov 23 at 8:20
@Menelaos Vergis I know what you mean , you want to change CancellationToken to true , but the Token can only be read. So i try to implement it with a compositeTokenSource. And you must want to run normally if you don't want it shutdown. That's why i use message,you also could implement it with other ways.
– George Chen
Nov 23 at 9:08
Thank you for your insights, I understand now that thisCancelationToken
is only for shutdown notification, is shared among all Process instances and cannot be used for other reasons. Please add this information at your answer so I can mark it as solution
– Menelaos Vergis
Nov 23 at 9:39
@Menelaos Vergis Thanks,i have edited it.
– George Chen
Nov 23 at 9:50
add a comment |
I want to send aCancellationToken
to a running process, this example uses the queue with a new message.
– Menelaos Vergis
Nov 23 at 8:20
@Menelaos Vergis I know what you mean , you want to change CancellationToken to true , but the Token can only be read. So i try to implement it with a compositeTokenSource. And you must want to run normally if you don't want it shutdown. That's why i use message,you also could implement it with other ways.
– George Chen
Nov 23 at 9:08
Thank you for your insights, I understand now that thisCancelationToken
is only for shutdown notification, is shared among all Process instances and cannot be used for other reasons. Please add this information at your answer so I can mark it as solution
– Menelaos Vergis
Nov 23 at 9:39
@Menelaos Vergis Thanks,i have edited it.
– George Chen
Nov 23 at 9:50
I want to send a
CancellationToken
to a running process, this example uses the queue with a new message.– Menelaos Vergis
Nov 23 at 8:20
I want to send a
CancellationToken
to a running process, this example uses the queue with a new message.– Menelaos Vergis
Nov 23 at 8:20
@Menelaos Vergis I know what you mean , you want to change CancellationToken to true , but the Token can only be read. So i try to implement it with a compositeTokenSource. And you must want to run normally if you don't want it shutdown. That's why i use message,you also could implement it with other ways.
– George Chen
Nov 23 at 9:08
@Menelaos Vergis I know what you mean , you want to change CancellationToken to true , but the Token can only be read. So i try to implement it with a compositeTokenSource. And you must want to run normally if you don't want it shutdown. That's why i use message,you also could implement it with other ways.
– George Chen
Nov 23 at 9:08
Thank you for your insights, I understand now that this
CancelationToken
is only for shutdown notification, is shared among all Process instances and cannot be used for other reasons. Please add this information at your answer so I can mark it as solution– Menelaos Vergis
Nov 23 at 9:39
Thank you for your insights, I understand now that this
CancelationToken
is only for shutdown notification, is shared among all Process instances and cannot be used for other reasons. Please add this information at your answer so I can mark it as solution– Menelaos Vergis
Nov 23 at 9:39
@Menelaos Vergis Thanks,i have edited it.
– George Chen
Nov 23 at 9:50
@Menelaos Vergis Thanks,i have edited it.
– George Chen
Nov 23 at 9:50
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53435254%2fhow-to-cancel-a-queue-triggered-azure-webjob-programatically%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown