ar.secondround's People
ar.secondround's Issues
LambdaMessageHandler
- Inherit LambdaServiceWithAppStore
- Implement IMessageHandler
- protected IServiceBusClient SvcServiceBus => SingletonStore.Get(()...
- protected ISlackServiceClient SvcSlack = new SlackServiceClient(SlackServiceClientConfig.LoadConfigFromEnvVar());
-> Suggestion: Should inject in constructor to make this class testable - public async Task HandleAsync(object reqData, ILambdaContext context)
-> Suggestion:- Should inject ILogTrace in constructor, avoid creating instance of MessageHandlerLogTrace here
- Keep one try/catch/finally block, remove another one
- AlertErrorToSlack -> Task.WaitAll(SvcSlack.SendWithErrorHandler(slackMsg, logTrace));
-> Suggestion: Task.Run(() => SvcSlack.SendWithErrorHandler(slackMsg, logTrace)). Just fire and forget, create new task from Thread pool to avoid deadlock, no need to get result
ContactsSyncer/Handler
- This class should:
- Inherit from LambdaServiceWithAppStore
- Implement IMessageHandler
- ProcessAsync:
- Remove do/while -> Replace by while loop -> move logic of GetContacts out of do/while, move logic of GetContactsNextPage to while loop to avoid checking string.IsNullOrWhiteSpace(getContactsData.NextRecordsUrl) twice
- GetContacts
- Should have try/catch block to catch error when making the call to other methods
- Consider to lazy initialize getContactsFallbackLevel1Task, getContactsFallbackLevel2Task since if we have the data of the call to GetContactsWithOutOfSyncHandler, we don't need to call getContactsFallbackLevel1Task, getContactsFallbackLevel2Task
- Consider when throwing exception inside GetContactsNextPage and GetContacts since it will stop the flow -> Just need to log the failed contacts and continue to fetch contacts to the end of page
- static readonly object _lock = new object();
-> Remove unused variable
LambdaServiceWithAppStore
- Constructor:
protected LambdaServiceWithAppStore() => Init(LoadConfigFromEnvVar);
-> Suggestion:protected LambdaServiceWithAppStore() : base(LoadConfigFromEnvVar);
- Why do we need to InitAppStore via Activator.CreateInstance -> always creates a new instance (TAppStore : SingletonAppStore)
-> Suggestion: We can get instance of AppStore by calling SingletonAppStore.Instance or SingletonStore<typeof(TAppStore)>
SQSLambdaMessageHandler
-
IList ParseMessages(SQSEvent sqsEvent)
return sqsEvent.Records.Select(
record =>
{
// parse the json string to TMessage
var message = JsonConvert.DeserializeObject(record.Body);// validate message schema message.Validate(); return message; } ).ToList();
-> Suggestion: Should wrap in try/catch block to log the error during parsing and validating message -> return default message if needed
Coding standard, patterns
-
Should create a proxy classes (SalesForceContactProxy, SalesForceTopicProxy) to wrap and make some methods testable -> move logic of svcSalesforce, SalesforceUtil -> SalesForceContactProxy/SalesForceTopicProxy:
public interface ISalesForceContactProxy
{
// Contacts
GetAllContactsAsync
GetNextPageAsync
}
public interface ISalesForceTopicProxy
{
// Topics
GetAllSalesforceObjectsAsync...
GetAllCampaignInteractionsAsync...
GetAllCampaignsAsync...
GetAllTopicsAsync...
}
-> Implementation:
public class SalesForceContactProxy: ISalesForceContactProxy, IDisposable
{
ILogTrace _logger;
AppStore _store;
IConfig _config;ISalesforceServiceClientV2 _salesforceServiceClient;
SalesForceContactProxy(ILogTrace logTrace, IConfig config)
{
_salesforceServiceClient = SalesforceServiceClientV2Factory.Create(...)
}
.... // Implement intefaceprotected virtual void Dispose(bool disposing) { _salesforceServiceClient.Dispose....}
} -
We should consider to create SaleforceTopicServiceAdapter to map object and SalesforceTopicMapping
public class SalesForceServiceAdapter
{
ISalesForceProxy _proxy;
public SalesForceServiceAdapter(ISalesForceTopicProxy proxy) { _proxy = proxy; }protected async Task<IList> GetAllSalesforceCampaignsAsync()
....
}
MessageHandler
public abstract class MessageHandler<TMessage, TAppStore> : IMessageHandler<TMessage> where TMessage : IMessage
-> Why do we need AppStore here ?
-> Suggestion:
public abstract class MessageHandler<TMessage> : IMessageHandler<TMessage> where TMessage : IMessage
- public abstract Task<IEnumerable> ProcessAsync(TMessage message, ILogTrace logTrace);
-> Suggestion: Should inject ILogTrace in Constructor
TopicsSyncer/Handler
-
UpdateGroupNames
- foreach (var task in groupTasks)
{
await task;
} - foreach (var task in remoteTasks)
{
await task;
}
-> Suggestion: Consider to use await Task.WhenAll() to run async tasks
- foreach (var task in groupTasks)
-
All the calls to svcSalesforce(GetAllPractifiCampaignsAsync, GetAllSalesforceCampaignsAsync...) should be replaced with Proxies, adapter
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.