Ejemplo n.º 1
0
        public Function(IDBFacade leadsDB, IDBFacade skillsDB)
        {
            HttpClient client = new HttpClient();

            _utils         = new Utility(leadsDB, skillsDB, client);
            _healthChecker = new HealthChecks(leadsDB, client);
        }
Ejemplo n.º 2
0
 public HealthChecks(IDBFacade dbLeads, HttpClient client = null)
 {
     _dbLeads  = dbLeads;
     _client   = client ?? new HttpClient();
     _slackApi = new SlackPoster(_client);
     _closeApi = new ClosePoster(_client);
 }
Ejemplo n.º 3
0
 public Utility(IDBFacade dbLeads, IDBFacade dbSkills, HttpClient client = null)
 {
     _dbLeads  = dbLeads;
     _dbSkills = dbSkills;
     _client   = client ?? new HttpClient();
     _slackApi = new SlackPoster(_client);
     _closeApi = new ClosePoster(_client);
 }
Ejemplo n.º 4
0
        public DBFacadeTests()
        {
            var filePath = $"{Environment.CurrentDirectory}\\db.sqlite";

            _settings = new ApiSettings
            {
                ConnectionString = $"Data Source={filePath}"
            };
            _facade = new DBFacade(_settings);

            var isFirstRun = !File.Exists(filePath);

            if (isFirstRun)
            {
                _facade.CreateDatabase();
            }
        }
Ejemplo n.º 5
0
        public async Task <string> GetQueueForMessage(JObject jobPost, IDBFacade db, ILambdaContext context)
        {
            bool   isValid  = Utility.IsSchemaValid(jobPost);
            string queueUri = "";

            if (isValid)
            {
                string jobPostUrl  = jobPost.Value <string>("sourceId");
                string jobPostHash = jobPost.Value <string>("hash");

                bool urlPresent = await db.ItemExists(jobPostUrl, urlTable);

                if (urlPresent == false)
                {
                    db.PutItem(jobPostUrl, urlTable, "url");

                    bool bodyPresent = await db.ItemExists(jobPostHash, bodyTable);

                    if (bodyPresent == false)
                    {
                        db.PutItem(jobPostHash, bodyTable, "sourceHash");
                        queueUri = "https://sqs.eu-west-1.amazonaws.com/833191605868/" + GlobalVars.SUCESS_QUEUE;
                    }
                    else
                    {
                        queueUri = "https://sqs.eu-west-1.amazonaws.com/833191605868/" + GlobalVars.EXISTING_QUEUE;
                    }
                }
                else
                {
                    queueUri = "https://sqs.eu-west-1.amazonaws.com/833191605868/" + GlobalVars.EXISTING_QUEUE;
                }
            }
            else
            {
                queueUri = "https://sqs.eu-west-1.amazonaws.com/833191605868/" + GlobalVars.INVALID_QUEUE;
            }

            return(queueUri);
        }
Ejemplo n.º 6
0
 public DataHandler(IDataProcessor processor, string destination, IDBFacade db = null)
 {
     _processor  = processor;
     Destination = destination;
     _db         = db;
 }
Ejemplo n.º 7
0
        public async Task ProcessMessageAsync(SQSEvent.SQSMessage message, ILambdaContext context, IDBFacade db, IQueueFacade queue)
        {
            JObject jobPost  = JObject.Parse(message.Body);
            string  queueUri = await GetQueueForMessage(jobPost, db, context);

            // publish message to the corresponding SQS queue

            await queue.PublishToQueue(message.Body, queueUri);

            await Task.CompletedTask;
        }
 public CheckingDBFacade(IDBFacade component)
 {
     this.component = component;
 }
Ejemplo n.º 9
0
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
        public DBController(IDBFacade dBFacade)
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
        {
            _dBFacade = dBFacade;
        }
 public CachingDBFacade(IDBFacade component)
 {
     this.component = component;
 }
Ejemplo n.º 11
0
        private async Task ProcessMessageAsync(SQSEvent.SQSMessage message, Table skillsTable, IDBFacade db, ILambdaContext context)
        {
            Metrics.AddData(new MetricDatum
            {
                MetricName   = "IncomingJobPosts",
                Value        = 1,
                Unit         = StandardUnit.Count,
                TimestampUtc = DateTime.UtcNow,
                Dimensions   = new List <Dimension>
                {
                    new Dimension
                    {
                        Name  = "IncomingJobPosts",
                        Value = "1"
                    }
                }
            });

            SecretManager sm = new SecretManager();

            _webhook_url = sm.Get("SLACK_WEBHOOK");

            JObject       jobPost         = JObject.Parse(message.Body);
            string        jobPostHeader   = jobPost.Value <string>("header");
            string        jobPostUrl      = jobPost.Value <string>("sourceId");
            string        jobPostCustomer = jobPost.Value <string>("customer");
            List <string> jobPostKeywords = jobPost.Value <JArray>("keywords").ToObject <List <string> >();

            if (await SkillFilterExists(jobPostKeywords, skillsTable, db))
            {
                JObject jsonObject = await BuildSlackPayload(jobPostHeader, jobPostUrl, _closeApi, jobPostCustomer);

                await _client.PostAsJsonAsync(_webhook_url, jsonObject);

                Metrics.AddData(new MetricDatum
                {
                    MetricName   = "PostedJobPostsToSlack",
                    Value        = 1,
                    Unit         = StandardUnit.Count,
                    TimestampUtc = DateTime.UtcNow,
                    Dimensions   = new List <Dimension>
                    {
                        new Dimension
                        {
                            Name  = "PostedJobPostsToSlack",
                            Value = "1"
                        }
                    }
                });
            }

            await Task.CompletedTask;
        }
Ejemplo n.º 12
0
        public async Task <bool> SkillFilterExists(List <string> skills, Table skillsTable, IDBFacade db)
        {
            foreach (string skill in skills)
            {
                if (await db.ItemExists(skill.ToLower(), skillsTable))
                {
                    return(true);
                }
            }

            return(false);
        }