Skip to content

Instantly share code, notes, and snippets.

@wattengard
Created April 22, 2014 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wattengard/11171563 to your computer and use it in GitHub Desktop.
Save wattengard/11171563 to your computer and use it in GitHub Desktop.
using MakeSense;
using NLog;
using System;
using System.Collections.Generic;
using System.Threading;
namespace PDFRunner
{
class Program
{
private static Timer t;
private static object Block;
private static int failureCounter;
static void Main(string[] args)
{
var l = LogManager.GetCurrentClassLogger();
var db = MakeSenseDB.GetInstance();
t = new Timer(TimerCallback, null, -1, 1000);
Block = new object();
var bestillingid = args.Length > 0 ? int.Parse(args[0]) : 0;
if (bestillingid == 0)
{
l.Info("Forbereder start.");
db.Execute("update tblrapportbestilling set status = 4 where status = 1 and left(navn, 1) = '_' ");
failureCounter = 0;
t.Change(0, 1000);
Console.ReadLine();
}
else
{
l.Debug("Kjører bestemt bestilling ({0})", bestillingid);
var r = new Runner(bestillingid);
}
}
private static void TimerCallback(object state)
{
if (!Monitor.TryEnter(Block)) return;
var l = LogManager.GetCurrentClassLogger();
var db = MakeSenseDB.GetInstance();
l.Debug("Finner åpne bestillinger");
List<RapportBestilling> bestillinger;
try
{
bestillinger =
db.Fetch<RapportBestilling>(
"select * from tblrapportbestilling where status = 0 and aktiv = 1 and left(navn, 1) = '_' order by bestilt, prioritet desc");
failureCounter = 0;
}
catch (Exception e)
{
l.ErrorException("Feilet ved henting av rapporter!", e);
failureCounter++;
if (failureCounter > 5)
{
l.Fatal("Feilet mer enn 5 ganger. Avslutter!");
return;
}
}
foreach (var b in bestillinger)
{
l.Debug("Laster bestilling {0} [{1}]", b.BestillingID, b.Navn);
var r = new Runner(b.BestillingID);
}
GC.Collect();
Monitor.Exit(Block);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment