public static void Run([TimerTrigger("0 */50 * * * *", RunOnStartup = true)] TimerInfo myTimer, TraceWriter log, ExecutionContext context)
        {
            try
            {
                Logger.Init(log);
                log.Info($"Starting at {DateTime.Now} in {context.FunctionAppDirectory}");

                var azureContainerManager = new AzureContainerManager(context.FunctionAppDirectory);
                var containerStatus       = azureContainerManager.GetStatus();
                Logger.Info($"Status is {containerStatus}");
                switch (containerStatus)
                {
                case ContainerStatus.Missing:
                    Logger.Info("Starting container");
                    azureContainerManager.StartImageAnalyzer();
                    break;

                case ContainerStatus.ExceededDuration:
                    azureContainerManager.StopImageAnalyzer();
                    break;
                }

                log.Info($"Finished at {DateTime.Now}");
            }
            catch (Exception e)
            {
                log.Info(e.ToString());
            }
        }
Example #2
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            try
            {
                CryptoTrader.Timestamp = DateTime.Now.Ticks;
                Logger.Init(log);
                Logger.Log($"Started function at {DateTime.UtcNow}");
                AzureContainerManager azureContainerManager = new AzureContainerManager();
                var status = req.GetQueryNameValuePairs()
                             .FirstOrDefault(q => string.Compare(q.Key, "status", StringComparison.OrdinalIgnoreCase) == 0)
                             .Value;

                if (status == "loaded")
                {
                    foreach (var marketChart in MarketCharts)
                    {
                        Logger.Log($"Retrieving signal for {marketChart.Market}");
                        var cryptoTrader = new CryptoTrader();
                        await cryptoTrader.RetrieveAndProcessSignal(Environment.GetEnvironmentVariable("containerUrl"), marketChart);
                    }
                    azureContainerManager.StopImageAnalyzer();
                }
                Logger.Log($"Finished function at {DateTime.UtcNow}");
            }
            catch (Exception e)
            {
                Logger.Log(e.ToString());
                return(req.CreateResponse(HttpStatusCode.InternalServerError, e.ToString()));
            }
            return(req.CreateResponse(HttpStatusCode.OK, "invalid"));
        }