예제 #1
0
    public static void ProceedHourlyDistribution()
    {
        AppSettings.RevShare.Reload();

        if (AppSettings.RevShare.IsRevShareEnabled)
        {
            log = new StringBuilder();

            var Entry = new CronEntry();
            Entry.Date = DateTime.Now;

            try
            {
                stime = DateTime.Now;
                AppSettings.IsOffline = true;

                if (AppSettings.RevShare.DistributionTime != DistributionTimePolicy.EveryHour)
                {
                    Entry.Type = 2;
                    Entry.Text = "CRON has been triggered, but Hourly Distribution is turned off. No action has been made.";
                }
                else
                {
                    if (AppSettings.RevShare.HourlyDistributionsMadeToday < 23)
                    {
                        RevenueSharesDistributionManager.CRON_EVERY_HOUR();

                        AppSettings.RevShare.HourlyDistributionsMadeToday++;
                        AppSettings.RevShare.Save();

                        Entry.Type = 1;
                        Entry.Text = "Hourly distribution proceed successfully after " + GetTimeString(stime);
                    }
                    else
                    {
                        Entry.Type = 2;
                        Entry.Text = "Hourly distribution prevented from running more than 23 times a day";
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.Log(ex);
                Log("Fatal error (exception thrown)..");
                Entry.Type = 3;
                Entry.Text = "Fatal error during procedure execution. Check logs for more information";
                //Mailer.SendCRONFailureMessage();
            }
            finally
            {
                ErrorLogger.Log(log.ToString(), LogType.CRON);
                Entry.Save();
                AppSettings.IsOffline = false;
            }
        }
    }
예제 #2
0
파일: Cron.cs 프로젝트: h4570/armnas
        /// <summary>
        /// Get list of all cron jobs.
        /// </summary>
        /// <param name="user">Cron user</param>
        /// <exception cref="T:OSCommander.Repositories.CommandFailException">If there will be STDERR or other OS related exceptions occur.
        /// Detailed information can be checked in provided logger.</exception>
        /// <exception cref="T:OSCommander.Exceptions.CronParseException">Wrapper exception for Cron parsing fail.</exception>
        public IEnumerable <CronEntry> GetAll(string user = "******")
        {
            var crontab = _commandRepo.Execute($"crontab -u {user} -l | grep -v ^\\#.");

            try
            {
                var res   = new List <CronEntry>();
                var lines = crontab.Split('\n').Where(c => c.Trim() != string.Empty);
                foreach (var line in lines)
                {
                    string cron       = null;
                    var    splitIndex = line.Length;
                    for (; splitIndex > 0; splitIndex--)
                    {
                        var leftPart = line.Substring(0, splitIndex);
                        var cronObj  = CrontabSchedule.TryParse(leftPart);
                        if (cronObj != null)
                        {
                            cron = cronObj.ToString();
                            break;
                        }
                        if (!IsNonStandardCron(leftPart))
                        {
                            continue;
                        }
                        cron = leftPart;
                        break;
                    }
                    if (cron == null)
                    {
                        continue;
                    }
                    var item = new CronEntry
                    {
                        Command = line.Substring(splitIndex, line.Length - splitIndex).Trim(),
                        Cron    = cron.Trim()
                    };
                    res.Add(item);
                }
                return(res);
            }
            catch (Exception ex) { throw new CronParseException(ex); }
        }
예제 #3
0
    public static void ProceedDailyTasks()
    {
        log = new StringBuilder();

        var Entry = new CronEntry();

        Entry.Date = DateTime.Now;

        try
        {
            Log("Starting CRON procedure");

            //Make sure it runs only once
            if (CanRun())
            {
                AppSettings.IsOffline        = true;
                AppSettings.Misc.LastCRONRun = DateTime.Now;
                AppSettings.Misc.Save();
                stime = DateTime.Now;

                AntiCheatSystem.CRON();
                Log("OK [1] AntiCheatSystem. Elapsed time: " + GetTimeString(stime));

                RentReferralsSystem.CRON();
                Log("OK [2] RentedReferralsSystem. Elapsed time: " + GetTimeString(stime));

                StatisticsManager.CRON();
                Log("OK [3a] StatisticsManager. Elapsed time: " + GetTimeString(stime));

                //MUST BE RUN BEFORE MEMBERMANAGER.CRON() !!!
                CustomFeaturesManager.CRON();
                Log("OK [3b] CustomFeaturesManager. Elapsed time: " + GetTimeString(stime));

                MemberManager.CRON();
                Log("OK [4] Member. Elapsed time: " + GetTimeString(stime));

                SyncedNetworkFactory.SynchronizeAll();
                Log("OK [5] CPA Offers. Elapsed time: " + GetTimeString(stime));

                AppSettings.Payments.CRON();
                Log("OK [6] Payments. Elapsed time: " + GetTimeString(stime));

                ShoutboxManager.CRON();
                Log("OK [7] Shoutbox. Elapsed time: " + GetTimeString(stime));

                CLPManager.CRON();
                Log("OK [8] CLPManager. Elapsed time: " + GetTimeString(stime));

                BannerAuctionManager.CRON();
                Log("OK [10] BannerAuctionManager. Elapsed time: " + GetTimeString(stime));

                PointsLockingManager.CRON();
                Log("OK [11] PointsLockingManager. Elapsed time: " + GetTimeString(stime));

                DBArchiver.CRON();
                Log("OK [12] DBArchiver. Elapsed time: " + GetTimeString(stime));

                RevenueSharesDistributionManager.CRON();
                Log("OK [13] RevenueSharesDistributionManager. Elapsed time: " + GetTimeString(stime));

                CreditLineManager.CRON();
                Log("OK [14] CreditLineManager. Elapsed time: " + GetTimeString(stime));

                PoolRotatorManager.CRON();
                Log("OK [15] PoolRotatorManager. Elapsed time: " + GetTimeString(stime));

                JackpotManager.CRON();
                Log("OK [16] JackpotManager. Elapsed time: " + GetTimeString(stime));

                TrafficExchangeManager.CRON();
                Log("OK [17] TrafficExchangeManager. Elapsed time: " + GetTimeString(stime));

                DailyPoolManager.CRON();
                Log("OK [18] DailyPoolManager. Elapsed time: " + GetTimeString(stime));

                //Matrix
                MatrixBase matrix = MatrixFactory.GetMatrix();
                if (matrix != null)
                {
                    matrix.CRON();
                }
                Log("OK [19] MatrixBase. Elapsed time: " + GetTimeString(stime));

                ApiAccessToken.CRON();
                Log("OK [20] ApiAccessToken. Elapsed time: " + GetTimeString(stime));

                InvestmentPlatformManager.CRON();
                Log("OK [21] InvestmentPlatformManager. Elapsed time: " + GetTimeString(stime));

                MarketplaceBalanceLogManager.CRON();
                Log("OK [22] MarketplaceBalanceLogManager. Elapsed time: " + GetTimeString(stime));

                MiniVideoManager.CRON();
                Log("OK [23] MiniVideoManager. Elapsed time: " + GetTimeString(stime));

                PaidToPromoteManager.CRON();
                Log("OK [24] PaidToPromoteManager. Elapsed time: " + GetTimeString(stime));

                RollDiceLotteryManager.CRON();
                Log("OK [25] RollDiceLotteryManager. Elapsed time: " + GetTimeString(stime));

                WalletManager.CRON();
                Log("OK [26] WalletManager. Elapsed time: " + GetTimeString(stime));

                NewsManager.CRON();
                Log("OK [27] NewsManager. Elapsed time: " + GetTimeString(stime));


                Entry.Type = 1;
                Entry.Text = "Procedure completed successfully (27/27 100%) after " + GetTimeString(stime);
            }
            else
            {
                Entry.Type = 2;
                Entry.Text = "Procedure prevented from multiple run";
            }
        }
        catch (Exception ex)
        {
            ErrorLogger.Log(ex);
            Log("Fatal error (exception thrown)..");
            Entry.Type = 3;
            Entry.Text = "Fatal error during procedure execution. Check logs for more information";
            Mailer.SendCRONFailureMessage();
        }
        finally
        {
            ErrorLogger.Log(log.ToString(), LogType.CRON);
            AppSettings.IsOffline = false;
            Entry.Save();
            HttpContext.Current.Response.Write(Entry.Text);
        }
    }
예제 #4
0
 public ActionResult <CronEntry> Patch([FromBody] CronEntry cronEntry)
 {
     _cron.Remove(cronEntry.Command);
     return(Ok(cronEntry));
 }
예제 #5
0
 public ActionResult <CronEntry> Create([FromBody] CronEntry cronEntry)
 {
     _cron.Add(cronEntry.Cron, cronEntry.Command);
     return(Ok(cronEntry));
 }