Exemple #1
0
        private void CheckSchedule(IAMDatabase db, Int64 scheduleId, Int64 resourcePluginId, Int64 resourceId, String jSonSchedule, DateTime next)
        {
            DateTime date = DateTime.Now;
            TimeSpan ts   = date - new DateTime(1970, 01, 01);

            Schedule schedule = new Schedule();

            try
            {
                schedule.FromJsonString(jSonSchedule);
                jSonSchedule = null;
            }
            catch
            {
                schedule.Dispose();
                schedule = null;
            }

            if (schedule == null)
            {
                return;
            }

            //Check Start date

            TimeSpan stDateTs = next - new DateTime(1970, 01, 01);

            TextLog.Log("Dispatcher", "[" + resourceId + "] CheckSchedule> next " + next.ToString("yyyy-MM-dd HH:mm:ss"));
            TextLog.Log("Dispatcher", "[" + resourceId + "] CheckSchedule> Executa agora? " + (ts.TotalSeconds >= stDateTs.TotalSeconds));
            if (ts.TotalSeconds >= stDateTs.TotalSeconds) //Data e hora atual maior ou igual a data que se deve iniciar
            {
                TextLog.Log("Dispatcher", "[" + resourceId + "] Starting execution");

                try
                {
                    using (IAMDeploy deploy = new IAMDeploy("Dispatcher", localConfig.SqlServer, localConfig.SqlDb, localConfig.SqlUsername, localConfig.SqlPassword))
                        deploy.DeployResourcePlugin(resourcePluginId);
                }
                catch (Exception ex)
                {
                    TextLog.Log("Dispatcher", "[" + resourceId + "] Error on execution " + ex.Message);
                }
                finally
                {
                    TextLog.Log("Dispatcher", "[" + resourceId + "] Execution completed");

                    //Agenda a próxima execução
                    DateTime nextExecute = schedule.CalcNext();

                    db.ExecuteNonQuery("update resource_plugin_schedule set [next] = '" + nextExecute.ToString("yyyy-MM-dd HH:mm:ss") + "' where id = " + scheduleId, CommandType.Text, null);
                }
            }

            schedule.Dispose();
            schedule = null;
        }
Exemple #2
0
        private void DeployNowTimer(Object state)
        {
            if (executing2)
            {
                return;
            }

            executing2 = true;


            try
            {
                IAMDatabase db = new IAMDatabase(localConfig.SqlServer, localConfig.SqlDb, localConfig.SqlUsername, localConfig.SqlPassword);
                db.openDB();

                DataTable dtS = db.Select("select entity_id, MAX(date) [date] from deploy_now with(nolock) where date < GETDATE() group by entity_id order by MAX(date)");

                if ((dtS == null) || (dtS.Rows.Count == 0))
                {
                    return;
                }

                TextLog.Log("Dispatcher", "Starting deploy now timer");

                //Processa um a um dos agendamentos
                foreach (DataRow dr in dtS.Rows)
                {
                    try
                    {
                        Int32 count = 0;
                        using (IAMDeploy deploy = new IAMDeploy("Dispatcher", localConfig.SqlServer, localConfig.SqlDb, localConfig.SqlUsername, localConfig.SqlPassword))
                        {
                            count = deploy.DeployOne((Int64)dr["entity_id"]);


                            if (count == 0)
                            {
                                db.AddUserLog(LogKey.User_Deploy, null, "Deploy", UserLogLevel.Error, 0, 0, 0, 0, 0, (Int64)dr["entity_id"], 0, "Erro on deploy now user: no package sent", deploy.ExecutionLog);
                            }
                        }


                        db.ExecuteNonQuery("delete from deploy_now where entity_id = " + dr["entity_id"], CommandType.Text, null);
                    }
                    catch (Exception ex2) {
                        db.AddUserLog(LogKey.User_Deploy, null, "Deploy", UserLogLevel.Error, 0, 0, 0, 0, 0, (Int64)dr["entity_id"], 0, "Erro on deploy now user: "******"Dispatcher", "\tError on deploy now timer " + ex.Message + ex.StackTrace);
            }
            finally
            {
                TextLog.Log("Dispatcher", "Finishing deploy now timer");
                executing2 = false;
            }
        }