Example #1
0
bool runTask(int task, int spot)
{
  if(task == 1)
  {
    tcpConnection();
    return true;
  }
  else if(task == 2)
  {
    blinkzOne();
    return true;
  }
  else if(task == 3)
  {
    blinkzTwo();
    return true;
  }
  else if(task == 4)
  {
    tone(SPK, taskList[spot][INTERVAL], taskList[spot][CYCLES]);
    return false;
  }

  return false;
}
Example #2
0
void schedSecondTest(ConnectionPtr connection, long idNo, int portNo, SC_TEST_TYPE testType, unsigned int shardNumber)
{
	Trace("schedSecondTest", "", idNo);

	std::string	strQuery;

	// find a server to send the test to
	try
	{
#ifdef SHARD_AWARE
		ConnectionPtr passportShardConnection(
			new Connection(
					CConfig::getPassportDbServer(),
					CConfig::getPassportDbDatabase(),
					CConfig::getPassportDbUser(),
					CConfig::getPassportDbPass(),
					CConfig::getDBRetryTime()));

		// get the group of this test server
		strQuery = Format(SQL_SCS_TEST_GROUP_CG3, CConfig::getServerID());
		TraceSQL("Issuing query", "", 0);

		int	testGroup = 0;
		if (ResultPtr result = passportShardConnection->Query(strQuery))
		{
			TraceSQL("Rows:","",result->GetRowCount());
			if (result->GetRowCount() > 0)
			{
				result->Next();
				RowPtr row = result->GetCurrentRow();

				testGroup = row->GetFieldInteger(1);
			}
		}

		// get the carrier to exclude
		if (portNo == TCP_PORT_WTTGD)
		{
			strQuery = Format(SQL_SCS_TEST_GROUP_EXCLUDE_SCRIPT, idNo);
		}
		else if (portNo == TCP_PORT_ETTD)
		{
			strQuery = Format(SQL_SCS_TEST_GROUP_EXCLUDE_ISP, idNo);
		}
		else
		{
			strQuery = Format(SQL_SCS_TEST_GROUP_EXCLUDE_WEBPAGE, idNo);
		}
		TraceSQL("Issuing query", "", 0);

		unsigned int carrierToExclude = 0;
		if (ResultPtr result = connection->Query(strQuery))
		{
			TraceSQL("Rows:","",result->GetRowCount());
			if (result->GetRowCount() > 0)
			{
				result->Next();
				RowPtr row = result->GetCurrentRow();

				// make it the customer one
				carrierToExclude = row->GetFieldInteger(1);

				// override with Script or WebPage one
				if (row->GetFieldInteger(2) != 0)
					carrierToExclude = row->GetFieldInteger(2);
			}
		}

#ifdef SC_NON_WEBKIT
		strQuery = Format(SQL_SCS_RETEST_SERVERS_GROUP_RAND_CG3, SC_SERVER_STATUS_LIVE, testGroup, carrierToExclude);
#else
#ifdef SC_WEBKIT_V89
		strQuery = Format(SQL_SCS_RETEST_SERVERS_GROUP_RAND_CG3, SC_SERVER_JACK_STATUS_LIVE_89, testGroup, carrierToExclude);
#else
		strQuery = Format(SQL_SCS_RETEST_SERVERS_GROUP_RAND_CG3, SC_SERVER_JACK_STATUS_LIVE, testGroup, carrierToExclude);
#endif	// SC_WEBKIT_V89
#endif	// SC_NON_WEBKIT
		TraceSQL("Issuing query", "", 0);

		if (ResultPtr result = passportShardConnection->Query(strQuery))
		{
			TraceSQL("Rows:","",result->GetRowCount());

#else
		// get the group of this test server
		strQuery = Format(SQL_SCS_TEST_GROUP, CConfig::getServerID());
		TraceSQL("Issuing query", "", 0);

		if (ResultPtr result = connection->Query(strQuery))
		{
			std::string site;
			std::string clusterGroup;

			TraceSQL("Rows:","",result->GetRowCount());
			if (result->GetRowCount() > 0)
			{
				result->Next();
				RowPtr row = result->GetCurrentRow();

				testGroup = row->GetFieldInteger(1);
				site = row->GetFieldString(2);
				clusterGroup = row->GetFieldString(3);
			}
		
			// first work out the minute
			//time_t timeNow = time(NULL);
			//struct tm* timeStruct;
			//timeStruct = localtime( &timeNow );
			strQuery = Format(SQL_SCS_RETEST_SERVERS_GROUP_RAND, SC_SERVER_STATUS_LIVE, testGroup, site.c_str(), clusterGroup.c_str());
		}
		TraceSQL("Issuing query", "", 0);

		if (ResultPtr result = connection->Query(strQuery))
		{
			TraceSQL("Rows:","",result->GetRowCount());
#endif
			if (result->GetRowCount() > 0)
			{
				std::string	testHost;

				while (result->Next())
				{
					RowPtr row = result->GetCurrentRow();

					testHost = row->GetFieldString(2);

					// try to send the job

					// send the test request
					CTcp tcpConnection(testHost, portNo);
					int fd = tcpConnection.tcp_connect(WTT_WTTD_TIMEOUT_SECS);
					if (fd > 0)
					{
#ifdef SHARD_AWARE
						// send the info to the testing tool
						if (testType == SC_TEST_TYPE_UNKNOWN)
						{
							strQuery = Format("%ld %d", idNo, shardNumber);
						}
						else
						{
							strQuery = Format("%ld %d %d", idNo, shardNumber, int(testType));
						}
#else
						// send the info to the testing tool
						if (testType == SC_TEST_TYPE_UNKNOWN)
						{
							strQuery = Format("%ld", idNo);
						}
						else
						{
							strQuery = Format("%ld %d", idNo, int(testType));
						}
#endif
						TraceLogic("tcpConnection.writen", strQuery.c_str(), strQuery.size())
						if (tcpConnection.writen(strQuery.c_str(), strQuery.size()) > 0)
						{
							Trace("Job sent to test server", strQuery.c_str(), fd);
							return;
						}
						else
						{
							LogError("Error sending job to test server", strQuery.c_str(), idNo);
						}
					}
					else
					{
						LogError("Timed out sending job to test server", "", idNo);
					}
				}
			}