Skip to content

Commit

Permalink
Fix when writing job execution status.
Browse files Browse the repository at this point in the history
  • Loading branch information
maps2002 committed Jul 13, 2016
1 parent 8bf207e commit f7a5baa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion DatabaseModel/App.Config
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
<connectionStrings>
<add name="CSPDatabaseModelEntities" connectionString="metadata=res://*/CSPDatabaseModelEntities.csdl|res://*/CSPDatabaseModelEntities.ssdl|res://*/CSPDatabaseModelEntities.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=maps-pc\sqlexpress;initial catalog=Create.CSP.Reporting;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
<add name="CSPDatabaseModelEntities" connectionString="metadata=res://*/CSPDatabaseModelEntities.csdl|res://*/CSPDatabaseModelEntities.ssdl|res://*/CSPDatabaseModelEntities.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=localhost\sqlexpress;initial catalog=Create.CSP.Reporting;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
Expand Down
40 changes: 20 additions & 20 deletions DatabaseModel/Managers/CorrelationIdsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@ public CorrelationIdsManager(DbContext dbContext = null)
}

#region Create

private async Task<CorrelationId> AddAsync(CorrelationId correlationId)
{
using (var dbContext = new CSPDatabaseModelEntities())
{
CorrelationId newCorrelationId = dbContext.CorrelationIds.Add(correlationId);
await dbContext.SaveChangesAsync();
CorrelationId newCorrelationId = _dbContext.CorrelationIds.Add(correlationId);
await _dbContext.SaveChangesAsync();

return newCorrelationId;
}
return newCorrelationId;
}

public Task<CorrelationId> AddNewRunAsync()
Expand All @@ -35,7 +32,7 @@ public Task<CorrelationId> AddNewRunAsync()
Id = Guid.NewGuid(),
StartDateTime = DateTime.UtcNow,
Status = "RUNNING",
EndDateTime = null
EndDateTime = null
});
}

Expand All @@ -45,25 +42,28 @@ public Task<CorrelationId> AddNewRunAsync()

private async Task<CorrelationId> UpdateAsync(CorrelationId correlationId)
{
using (var dbContext = new CSPDatabaseModelEntities())
{
dbContext.Entry(correlationId).State = EntityState.Modified;
await dbContext.SaveChangesAsync();

return correlationId;
}
_dbContext.Entry(correlationId).State = EntityState.Modified;
await _dbContext.SaveChangesAsync();
return correlationId;
}

public Task<CorrelationId> UpdateEndStatusAsync(Guid correlationId, string endStatus)
{
CorrelationId databaseCorrelationId = new CorrelationId()

// Get object to update
var existentCorrelation = _dbContext.CorrelationIds.FirstOrDefault(c => c.Id == correlationId);
if (existentCorrelation == null)
{
Id = correlationId,
EndDateTime = DateTime.UtcNow,
Status = endStatus
};
throw new ArgumentException("Could not find existent correlation id: " + correlationId);
}

// else. Update
existentCorrelation.EndDateTime = DateTime.UtcNow;
existentCorrelation.Status = endStatus;

return this.UpdateAsync(existentCorrelation);

return this.UpdateAsync(databaseCorrelationId);
}

#endregion
Expand Down
4 changes: 4 additions & 0 deletions Job/Processors/ActivationReportProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,10 @@ protected override async Task OutputToDatabaseBatchAsync(BlockingCollection<Repo
}
finally
{
//if (capturedException != null)
//{
// capturedException.Throw();
//}
}
}

Expand Down

0 comments on commit f7a5baa

Please sign in to comment.