示例#1
0
        public override async Task ExecuteAsync()
        {
            if (await IsOffHoursAsync(ProcessedOnDateTime))
            {
                //Check for jobs which stopped unexpectedly on this agent thread
                RaiseAndLogDebugMessage($"Resetting records which failed. [Table = {QueueTable}]");
                await ResetUnfinishedJobsAsync(AgentHelper.GetDBContext(-1));

                //Retrieve the next record to work on
                RaiseAndLogDebugMessage($"Retrieving next record(s) in the queue. [Table = {QueueTable}]");
                var delimitedListOfResourceGroupIds = GetCommaDelimitedListOfResourceIds(AgentResourceGroupIds);
                if (delimitedListOfResourceGroupIds != String.Empty)
                {
                    DataTable batch = await RetrieveBatchAsync(delimitedListOfResourceGroupIds);

                    if (TableIsNotEmpty(batch))
                    {
                        ImportWorkerQueueRecord record = null;
                        var errors = new List <ImportJobError>();

                        foreach (DataRow row in batch.Rows)
                        {
                            try
                            {
                                record = new ImportWorkerQueueRecord(row);

                                SetJobProperties(record);

                                RaiseAndLogDebugMessage($"Retrieved record(s) in the queue. [Table = {QueueTable}, ID = {TableRowId}, Workspace Artifact ID = {WorkspaceArtifactId}]");

                                //Update Status
                                var status = await GetImportJobStatus(record.WorkspaceArtifactID, record.JobID);

                                if (status == Constant.Status.Job.COMPLETED_MANAGER)
                                {
                                    await UpdateJobStatus(record.WorkspaceArtifactID, record.JobID, Constant.Status.Job.IN_PROGRESS_WORKER);
                                }

                                //Process the record(s)
                                RaiseAndLogDebugMessage($"Processing record(s). [Table = {QueueTable}, ID = {TableRowId}, Workspace Artifact ID = {WorkspaceArtifactId}]");
                                await ProcessRecordsAsync(AgentHelper, AgentHelper.GetDBContext(-1), _repositoryGroup, SqlQueryHelper, record, errors);

                                RaiseAndLogDebugMessage($"Processed record(s). [Table = {QueueTable}, ID = {TableRowId}, Workspace Artifact ID = {WorkspaceArtifactId}]");
                            }
                            catch (Exception ex)
                            {
                                if (record != null)
                                {
                                    var exceptionError = new ImportJobError()
                                    {
                                        Message = String.Format(Constant.ErrorMessages.ImportWorkerLineNumberError, record.ImportRowID, ex.Message), Type = Constant.ImportUtilityJob.ErrorType.DataLevel, LineNumber = record.ImportRowID
                                    };
                                    errors.Add(exceptionError);
                                }
                                else
                                {
                                    throw;
                                }
                            }
                        }

                        if (record != null)
                        {
                            if (errors.Any())
                            {
                                RaiseAndLogDebugMessage($"Recording Error(s). [Table = {QueueTable}, ID = {TableRowId}, Workspace Artifact ID = {WorkspaceArtifactId}]");
                                await _artifactQueryHelper.CreateImportJobErrorRecordsAsync(_apiOptions, record.WorkspaceArtifactID, record.JobID, _repositoryGroup.RdoRepository, errors, record.ObjectType);
                            }

                            RaiseAndLogDebugMessage($"Deleting Batch. [Table = {QueueTable}, ID = {TableRowId}, Workspace Artifact ID = {WorkspaceArtifactId}]");
                            await SqlQueryHelper.DeleteRecordFromQueueAsync(AgentHelper.GetDBContext(-1), AgentId, record.WorkspaceArtifactID, record.JobID, Constant.Tables.ImportWorkerQueue);
                        }
                    }
                    else
                    {
                        RaiseAndLogDebugMessage("No records in the queue for this resource pool.");
                    }
                }
                else
                {
                    RaiseAndLogDebugMessage("This agent server is not part of any resource pools.  Agent execution skipped.");
                }
            }
            else
            {
                RaiseAndLogDebugMessage($"Current time is not between {OffHoursStartTime} and {OffHoursEndTime}. Agent execution skipped.");
            }
        }
示例#2
0
        private async Task ClearQueueRecords(Int32 workspaceArtifactID, Int32 jobArtifactID)
        {
            await SqlQueryHelper.DeleteRecordFromQueueAsync(AgentHelper.GetDBContext(-1), Constant.Sql.ColumnsNames.ImportWorkerQueue.WorkspaceArtifactID, workspaceArtifactID, Constant.Sql.ColumnsNames.ImportWorkerQueue.JobID, jobArtifactID, Constant.Tables.ImportWorkerQueue);

            await SqlQueryHelper.DeleteRecordFromQueueAsync(AgentHelper.GetDBContext(-1), Constant.Sql.ColumnsNames.ImportManagerQueue.WorkspaceArtifactID, workspaceArtifactID, Constant.Sql.ColumnsNames.ImportManagerQueue.JobID, jobArtifactID, Constant.Tables.ImportManagerQueue);
        }
        public async Task ClearRecordsFromQueueTables(ExportManagerQueueRecord exportManagerQueueRecord)
        {
            await SqlQueryHelper.DeleteRecordFromQueueAsync(AgentHelper.GetDBContext(-1), Constant.Sql.ColumnsNames.ExportWorkerQueue.WorkspaceArtifactId, exportManagerQueueRecord.WorkspaceArtifactId, Constant.Sql.ColumnsNames.ExportWorkerQueue.ExportJobArtifactId, exportManagerQueueRecord.ExportJobArtifactId, Constant.Tables.ExportWorkerQueue);

            await SqlQueryHelper.DeleteRecordFromQueueAsync(AgentHelper.GetDBContext(-1), Constant.Sql.ColumnsNames.ExportManagerQueue.WorkspaceArtifactId, exportManagerQueueRecord.WorkspaceArtifactId, Constant.Sql.ColumnsNames.ExportManagerQueue.ExportJobArtifactId, exportManagerQueueRecord.ExportJobArtifactId, Constant.Tables.ExportManagerQueue);
        }