Is there a way the change the priority based on the agent?
Basically I have several agents across several data centers. I wanted queue the job with the least latency for the task it is about to perform. IE copying files from ServerA to ServerB, and I want Agent2 to perform this task since it has the least about of Network Latency and in the same datacenter.
I would keep a table of agents to network latency for all servers.
Ideally I would like the to change the query to a stored procedure, that determines what each agent decides to pick up. This way I can fine tune the logic without redeploying the code. I would pass in the server as part of parameters. Could this work?
Any suggestions?
Edit:
I can create Queues based on the type of Jobs or different user groups to give them priority
But what I am looking to do is change the logic, to choosing the next item in the queue.
In my scenario, I was creating queues based on the 3 regions to have the agents in closest to the resource to the Job. Turns out now I need to fine tune. So an agent in US could be broken down. I could create more queues, But it seems like it can keep changing and seems like it is not the queue I want to change.
Edit 2:
Is this where I can edit the logic?
private SqlServerTransactionJob DequeueUsingTransaction(string[] queues, CancellationToken cancellationToken)
{
FetchedJob fetchedJob = null;
DbTransaction transaction = null;
string fetchJobSqlTemplate =
$@"delete top (1) JQ
output DELETED.Id, DELETED.JobId, DELETED.Queue
from [{_storage.SchemaName}].JobQueue JQ with (readpast, updlock, rowlock, forceseek)
where Queue in @queues and (FetchedAt is null or FetchedAt < DATEADD(second, @timeout, GETUTCDATE()))";
do
{
cancellationToken.ThrowIfCancellationRequested();
var connection = _storage.CreateAndOpenConnection();
try
{
transaction = connection.BeginTransaction(IsolationLevel.ReadCommitted);
fetchedJob = connection.Query<FetchedJob>(
fetchJobSqlTemplate,
#pragma warning disable 618
new { queues = queues, timeout = _options.InvisibilityTimeout.Negate().TotalSeconds },
#pragma warning restore 618
transaction,
commandTimeout: _storage.CommandTimeout).SingleOrDefault();
if (fetchedJob != null)
{
return new SqlServerTransactionJob(
_storage,
connection,
transaction,
fetchedJob.JobId.ToString(CultureInfo.InvariantCulture),
fetchedJob.Queue);
}
}
finally
{
if (fetchedJob == null)
{
transaction?.Dispose();
transaction = null;
_storage.ReleaseConnection(connection);
}
}
WaitHandle.WaitAny(new[] { cancellationToken.WaitHandle, NewItemInQueueEvent }, _options.QueuePollInterval);
cancellationToken.ThrowIfCancellationRequested();
} while (true);
}
Thanks in advance