2019-04-04 00:50:53 +02:00
|
|
|
|
// /**
|
|
|
|
|
// * File: CheckTask.cs
|
|
|
|
|
// * Author: haraldwolff
|
|
|
|
|
// *
|
|
|
|
|
// * This file and it's content is copyrighted by the Author and / or copyright holder.
|
|
|
|
|
// * Any use wihtout proper permission is illegal and may lead to legal actions.
|
|
|
|
|
// *
|
|
|
|
|
// *
|
|
|
|
|
// **/
|
|
|
|
|
using System;
|
|
|
|
|
using ln.types.threads;
|
|
|
|
|
using ln.skyscanner.entities;
|
|
|
|
|
using ln.logging;
|
|
|
|
|
using Newtonsoft.Json;
|
2019-04-05 00:59:04 +02:00
|
|
|
|
using ln.types.odb;
|
|
|
|
|
using System.Linq;
|
2019-04-06 09:36:43 +02:00
|
|
|
|
using System.Collections.Generic;
|
2019-04-04 00:50:53 +02:00
|
|
|
|
namespace ln.skyscanner.checks
|
|
|
|
|
{
|
|
|
|
|
public class CheckJob : PoolJob
|
|
|
|
|
{
|
|
|
|
|
[JsonIgnore]
|
|
|
|
|
public Node Node { get; }
|
|
|
|
|
|
2019-04-06 09:36:43 +02:00
|
|
|
|
Dictionary<string, SkyCheckState> checkStates = new Dictionary<string, SkyCheckState>();
|
|
|
|
|
|
2019-04-04 00:50:53 +02:00
|
|
|
|
public CheckJob(Node node)
|
|
|
|
|
{
|
|
|
|
|
Name = String.Format("Interval check: {0} [{1}]",node.UniqueIdentity,node.PrimaryIP.ToString());
|
|
|
|
|
Node = node;
|
2019-04-16 18:23:05 +02:00
|
|
|
|
}
|
2019-04-06 09:36:43 +02:00
|
|
|
|
|
2019-04-16 18:23:05 +02:00
|
|
|
|
public override void Prepare()
|
|
|
|
|
{
|
2019-04-12 00:52:55 +02:00
|
|
|
|
Query stateQuery = Query.Equals<SkyCheckState>("Node", Node.ID);
|
2019-04-11 08:30:13 +02:00
|
|
|
|
SkyCheckState[] skyCheckStates = SkyScanner.Instance.Entities.SkyCheckStates.Query(stateQuery).ToArray();
|
2019-04-06 09:36:43 +02:00
|
|
|
|
foreach (SkyCheckState checkState in skyCheckStates)
|
|
|
|
|
{
|
|
|
|
|
checkStates.Add(checkState.CheckName, checkState);
|
|
|
|
|
}
|
2019-04-16 18:23:05 +02:00
|
|
|
|
foreach (SkyCheck check in SkyCheck.SkyChecks)
|
|
|
|
|
if (!checkStates.ContainsKey(check.Name) && check.IsValid(Node))
|
|
|
|
|
{
|
|
|
|
|
checkStates.Add(check.Name, check.PrepareCheckState(SkyScanner.Instance.Checker, Node));
|
|
|
|
|
SkyScanner.Instance.Entities.SkyCheckStates.Insert(checkStates[check.Name]);
|
|
|
|
|
}
|
2019-04-15 09:18:41 +02:00
|
|
|
|
}
|
2019-04-04 00:50:53 +02:00
|
|
|
|
|
2019-04-15 09:18:41 +02:00
|
|
|
|
public override void RunJob()
|
|
|
|
|
{
|
2019-04-04 00:50:53 +02:00
|
|
|
|
SkyCheck[] checks = SkyCheck.SkyChecks;
|
|
|
|
|
|
|
|
|
|
for (int n=0;n<checks.Length;n++)
|
|
|
|
|
{
|
|
|
|
|
setState("current check: {0}", checks[n].Name);
|
|
|
|
|
Progress = (double)n / (double)checks.Length;
|
|
|
|
|
|
|
|
|
|
if (checks[n].IsValid(Node))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2019-04-06 09:36:43 +02:00
|
|
|
|
SkyCheckState checkState = checkStates.ContainsKey(checks[n].Name) ? checkStates[checks[n].Name] : null;
|
|
|
|
|
|
|
|
|
|
if (checkState != null)
|
|
|
|
|
{
|
|
|
|
|
checkState.LastCheckTime = DateTime.Now;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-05 00:59:04 +02:00
|
|
|
|
checks[n].Check(SkyScanner.Instance.Checker, ref checkState, Node);
|
|
|
|
|
if (checkState != null)
|
2019-04-12 14:19:30 +02:00
|
|
|
|
{
|
|
|
|
|
checkState.CheckHistory();
|
2019-04-06 09:36:43 +02:00
|
|
|
|
SkyScanner.Instance.Checker.Save(checkState);
|
2019-04-12 14:19:30 +02:00
|
|
|
|
}
|
2019-04-05 00:59:04 +02:00
|
|
|
|
|
2019-04-04 00:50:53 +02:00
|
|
|
|
} catch (Exception e)
|
|
|
|
|
{
|
2019-07-03 10:55:19 +02:00
|
|
|
|
Logging.Log(LogLevel.WARNING, "Exception caught by CheckJob {0} [{1} / {3}]: {2}", checks[n].Name,Node.Name,e,Node.UniqueIdentity);
|
2019-04-04 00:50:53 +02:00
|
|
|
|
Logging.Log(e);
|
|
|
|
|
if (checks[n].IsCritical)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (checks[n].IsCritical)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
|
{
|
|
|
|
|
return Node.UniqueIdentity.GetHashCode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool Equals(object obj)
|
|
|
|
|
{
|
|
|
|
|
if (obj is CheckJob)
|
|
|
|
|
{
|
|
|
|
|
return Node.UniqueIdentity.Equals((obj as CheckJob).Node.UniqueIdentity);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|