public async Task TestTransformerFileToLines() { #region arrange var dir = AppContext.BaseDirectory; var folderSql = Path.Combine(dir, "SqlToExecute"); var receiverFolder = new ReceiverFolderHierarchical(folderSql, "*.sql"); DirectoryInfo di = new DirectoryInfo(folderSql); Console.WriteLine($"start files in {folderSql}"); foreach (var item in di.EnumerateFiles("*.sql")) { Console.WriteLine($"File {item.FullName}"); } Console.WriteLine($"end files in {folderSql}"); #endregion #region act var transformer = new TransformerFileToLines(); var j = new SimpleJob(); j.Receivers.Add(0, receiverFolder); j.FiltersAndTransformers.Add(0, transformer); await j.Execute(); #endregion #region assert receiverFolder.valuesRead?.Length.ShouldBeGreaterThan(1); transformer.valuesTransformed.ShouldNotBeNull(); var files = transformer.valuesTransformed.GroupBy(it => it.Values["FullName"]).ToArray(); files.Length.ShouldBeGreaterThan(1); var file1Len = files.First().Count(); var file2Len = files.Last().Count(); file1Len.ShouldBeGreaterThan(0); file2Len.ShouldBeGreaterThan(0); (file1Len + file2Len).ShouldBeGreaterThan(2); #endregion }
public void SetItUp() { delayReset = new ManualResetEvent(false); UnderTest.MaximumThreads = 1; longRunningJob = new SimpleJob(dt => Task.Delay(2000).Wait()); waitingJob = new SimpleJob((dt) => Task.Run(() => delayReset.Set())); }
void Start() { theData = new NativeArray <float>(1, Allocator.TempJob); theData[0] = 2; // Initialize a Job SimpleJob simpleJob = new SimpleJob { number = numberToAdd, data = theData }; // Schedule the job for execution. simpleJobHandle = simpleJob.Schedule(); // Actually run the job. JobHandle.ScheduleBatchedJobs(); // Wait... simpleJobHandle.Complete(); // Check if completed or not and used data from the job result. if (simpleJobHandle.IsCompleted) { Debug.Log(simpleJob.data[0]); } theData.Dispose(); }
private void runDemo() { // Simpl job declaration with the data SimpleJob simpleJob = new SimpleJob { number = myNumber, data = myData }; //Schedule a simple job (added in the quee, not running) simpleJobHandle = simpleJob.Schedule(); // run the schedule job JobHandle.ScheduleBatchedJobs(); // wait for the job to be completed simpleJobHandle.Complete(); if (simpleJobHandle.IsCompleted) { Debug.Log(simpleJob.data[0]); } // Free memory freeMemoryData(); }
private void DoExample() { NativeArray <float> resultArray = new NativeArray <float>(1, Allocator.TempJob); // Instatiate and Initialize SimpleJob myJob = new SimpleJob() { a = 5f, result = resultArray }; DifferentJob myJob2 = new DifferentJob() { result = resultArray }; // Schedule JobHandle myHandle = myJob.Schedule(); JobHandle myHandle2 = myJob2.Schedule(myHandle); //myHandle is automatically completed within schedule // Other task to run in the Main thread //myHandle.Complete(); myHandle2.Complete(); float resultValue = resultArray[0]; Debug.Log(resultValue); resultArray.Dispose(); }
void ExtendedExample() { NativeArray <float> result = new NativeArray <float>(1, Allocator.Persistent); SimpleJob job = new SimpleJob() { result = result }; JobExecution execution = JobHelper.AddScheduledJob(job, job.Schedule(), (jobExecutor) => { /// OnJobComplete delegate returns 'jobExecutor' with usefull data. if (jobExecutor.FramesTaken == -1) { Debug.Log("Job has completed immediatelly!"); } else { Debug.LogFormat("Job has completed in {0}s and {1} frames!", jobExecutor.Duration, jobExecutor.FramesTaken); } // Result is available. LateUpdate() context. Debug.Log(result[0]); // You can dispose NativeContainers container within the jobexecution immediately after completion. // This is required if your set your container allocator as Temp or TempJob, dont Dispose if you use Persistent allocation. // Otherwise no need to call Dispose, the JobHelper will execute Dispose() on all completed jobs on OnDestroy() jobExecutor.Dispose(); }, // If you want to complete this job immediately in the LateUpdate() check this to true. // But make sure to schedule the job before, to leave some room for workers to do its work. completeImmediatelly: false); // There is also an option to complete the job whenever you want. Debug.Log(execution.Complete()); }
private void DoExample() { NativeArray <float> resultArray = new NativeArray <float>(1, Allocator.TempJob); // Instantiate and initialize SimpleJob firstJob = new SimpleJob { a = 5f, result = resultArray }; AnotherJob secondJob = new AnotherJob { result = resultArray }; // Schedule JobHandle firstHandle = firstJob.Schedule(); JobHandle secondHandle = firstJob.Schedule(firstHandle); // other tasks to run in Main Thread in parallel // Confirm that jobs are completed firstHandle.Complete(); secondHandle.Complete(); float resultingValue = resultArray[0]; Debug.LogError("Result = " + resultingValue); resultArray.Dispose(); }
public void ShouldNotReschedule() { UnderTest.MaximumThreads = 1; ManualResetEvent removedJobManual = new ManualResetEvent(false); var longRunningJob = new SimpleJob(async(dt) => await Task.Delay(5000)) { Name = "long running job" }; UnderTest.ScheduleJob(TestSchedule, longRunningJob, true); string state = "never run"; var jobToBeRemoved = new SimpleJob((dt) => Task.Run(() => state = "I ran")) { Name = "job to be removed" }; var scheduledJob = UnderTest.ScheduleJob(TestSchedule, jobToBeRemoved, true); UnderTest.Start(); UnderTest.StopScheduledJob(scheduledJob); Assert.AreEqual("never run", state); }
public async Task TestUnzip() { #region arrange var dir = AppContext.BaseDirectory; string existingZip = Path.Combine(dir, "a.zip"); dir = Path.Combine(dir, "TestUnzip"); if (Directory.Exists(dir)) { Directory.Delete(dir, true); } Directory.CreateDirectory(dir); File.Copy(existingZip, Path.Combine(dir, "a.zip")); var receive = new ReceiverFolderHierarchical(dir, "*.zip"); var sender = new SenderUnzipFile(dir); #endregion #region act var job = new SimpleJob(); job.Receivers.Add(0, receive); job.Senders.Add(0, sender); await job.Execute(); #endregion #region assert string file = Path.Combine(dir, "a.txt"); Assert.IsTrue(File.Exists(file), $"{file} should be unzipped"); #endregion }
public async Task <CreateContestResponse> CreateAsync(CreateContestRequest contest) { var exists = await _contestRepository.FindByTopicAsync(contest.Topic); if (exists != null) { throw new Exception("A contest with the same Topic already exists."); } var result = await _contestRepository.CreateAsync(ContestMapper.MapCreateContestRequestToContestStorage(contest)); if (contest.Current) { await _contestRepository.SetCurrentAsync(result); // Schedule contest closing job var job = new SimpleJob(async scheduledTime => { await UpdateAsync(result, new UpdateContestRequest { Closed = true }); }); _singularity.ScheduleJob(new RunOnceSchedule(TimeSpan.FromMinutes(1)), job, false); } return(new CreateContestResponse { Id = result }); }
/// <summary> /// Configure the background scheduler that updates the calendar in the background /// </summary> private static void SetUpBackgroundJob() { if (backgroundUpdateScheduler == null) { ISingularityFactory factory = new SingularityFactory(); backgroundUpdateScheduler = factory.GetSingularity(); } if (backgroundUpdateJob == null) { backgroundUpdateJob = new SimpleJob(scheduledTime => UpdateGoogleCalendar()); } if (scheduledUpdateJob != null) { backgroundUpdateScheduler.StopScheduledJob(scheduledUpdateJob); scheduledUpdateJob = null; backgroundUpdateScheduler.Stop(); } if (_runInMinutes > 0) { var schedule = new EveryXTimeSchedule(TimeSpan.FromMinutes(_runInMinutes)); scheduledUpdateJob = backgroundUpdateScheduler.ScheduleJob(schedule, backgroundUpdateJob, true); } backgroundUpdateScheduler.Start(); }
public void RunSimpleJob() { didDispose = 0; SimpleJob job = new SimpleJob() { a = 5, b = 10 }; NativeArray <int> jobResult = new NativeArray <int>(SimpleJob.N, Allocator.TempJob); job.result = jobResult; job.Run(); #if NET_DOTS // TODO: didDispose does not get called for reflection (big-ECS), but does for code-gen (Tiny-ECS) // The code-gen is finding the DoDeallocateOnJobCompletion at compile time, and my be using // a slightly different rule set for finding the attribute. Assert.AreEqual(1, didDispose); #endif for (int i = 0; i < SimpleJob.N; ++i) { Assert.AreEqual(15, jobResult[i]); } jobResult.Dispose(); }
private void DoExample() { NativeArray <float> resultArray = new NativeArray <float>(1, Allocator.TempJob); // 1. Instantiate Job SimpleJob myJob = new SimpleJob { // 2. Initialize Job a = 5.0f, result = resultArray }; AnotherJob secondJob = new AnotherJob { result = resultArray }; // 3. Shedule Job JobHandle handle = myJob.Schedule(); JobHandle secondHandle = secondJob.Schedule(handle); // !! передаем дескриптор во вторую работу // 4. Complete Job handle.Complete(); // работу следует завершить прежде, чем пользоваться результатами secondHandle.Complete(); float resultingValue = resultArray[0]; Debug.Log("result = " + resultingValue); resultArray.Dispose(); }
public async Task RunJobInterpreted() { #region arrange var dir = AppContext.BaseDirectory; foreach (var item in Directory.EnumerateFiles(dir, "*.csv")) { File.Delete(item); } StringBuilder sb = new StringBuilder(); sb.AppendLine("1,model,Track_number"); sb.AppendLine("2,Ford,B325ROS"); sb.AppendLine("3,Audi,PL654CSM"); sb.AppendLine("4,BMW,B325DFH"); sb.AppendLine("5,Ford,B325IYS"); File.WriteAllText(Path.Combine(dir, "cars.csv"), sb.ToString()); var textJob = File.ReadAllText(Path.Combine(dir, "InterpreterJobDateTime.txt")); //var j1 = new SimpleJob(); //j1.Senders.Add(0, new Sender_CSV(":ASDAS")); //File.WriteAllText("aaa.txt", j1.SerializeMe()); //Process.Start("notepad.exe", "aaa.txt"); #endregion #region act IJob j = new SimpleJob(); j.UnSerialize(textJob); await j.Execute(); #endregion #region assert Assert.IsTrue(File.Exists("SendTo" + DateTime.Now.ToString("yyyyMMdd") + ".csv")); #endregion }
static string SimpleJobFolders() { string fileName = DeleteFileIfExists("Demo1SimpleJobFolders.html"); //TODO: put current dir on interpret string , like env var folderSolution = new DirectoryInfo(Directory.GetCurrentDirectory()).Parent.FullName; var receiveFolder = new ReceiverFolderHierarchical(folderSolution, "*.csproj"); receiveFolder.ExcludeFolderNames = new string[] { "bin", "obj", "Properties", ".vs", ".git", "packages" }; var si = new SimpleJob(); si.Receivers.Add(0, receiveFolder); si.Senders.Add(0, new Sender_Text(fileName, "<html><body><h1>Find .csproj in solution folder</h1>")); si.Senders.Add(1, new Sender_HTMLRazor("Views/RazorHierarchical.cshtml", fileName)); si.Senders.Add(2, new Sender_HierarchicalVizFolder(fileName, "Name")); si.Senders.Add(3, new Sender_Text(fileName, "</body></html>")); //or you can add SyncSenderMultiple , but for now let's do it line by line //ISend sender = new SyncSenderMultiple( // new Sender_HTMLText(fileName, "<html><body>"), // new Sender_HTMLRazor("Views/RazorHierarchical.cshtml", fileName), // new Sender_HierarchicalVizFolder(fileName, "Name"), // new Sender_HTMLText(fileName, "</body></html>") // ); return(si.SerializeMe()); }
static string SimpleJobDllLoadTypes() { string dir = Environment.CurrentDirectory; IReceive folderWithDll = new ReceiverFolderHierarchical("#static:Directory.GetCurrentDirectory()#", "*.dll"); var filterFiles = new FilterForFilesHierarchical(); var recContentFile = new ReceiverFromDllRelational(); var loadDllromFiles = new TransformerApplyReceiver(recContentFile, "DllFileName", "FullName"); var fileRazor = Path.Combine(dir, "relationalGeneric.cshtml"); string filename = "#static:Directory.GetCurrentDirectory()#\\relationalDLL.html"; ISend senderHTML = new SyncSenderMultiple( new Sender_Text(filename, "<html><body>") { FileMode = FileMode.Create }, new Sender_HTMLRazor("Views/" + Path.GetFileName(fileRazor), filename), //new Sender_HTMLRelationViz("Name", filename), new Sender_Text(filename, "</body></html>") ) ; var job = new SimpleJob(); job.Receivers.Add(0, folderWithDll); job.FiltersAndTransformers.Add(0, filterFiles); job.FiltersAndTransformers.Add(1, loadDllromFiles); job.Senders.Add(0, senderHTML); return(job.SerializeMe()); }
public async Task Test_ReceiverBookmarkFileChrome() { var dir = AppContext.BaseDirectory; #region ARRANGE string pathFile = Path.Combine(dir, "bookmarks_7_25_17.html"); if (!File.Exists(pathFile)) { throw new ArgumentException($"not found {pathFile}"); } var receiver = new ReceiverBookmarkFileChrome(pathFile); string transformExpression = "var secs = double.Parse((oldValue??null).ToString());" + "var val=new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(secs);" + "val"; var transform = new TransformOneValueGeneral(transformExpression, "ADD_DATE", "realDate"); #endregion #region ACT ISimpleJob job = new SimpleJob(); job.Receivers.Add(0, receiver); job.FiltersAndTransformers.Add(0, transform); await job.Execute(); #endregion #region ASSERT Assert.AreEqual(5676, transform.valuesRead.Length); Assert.AreEqual(5676, transform.valuesTransformed.Length); Assert.AreEqual(new DateTime(2015, 5, 14, 19, 15, 50).ToString(), transform.valuesTransformed[0].Values["realDate"].ToString()); #endregion }
// hint: no lock deadlock, but why ? public void OnSharedRessource() { var obj1 = new object(); var obj2 = new object(); var haveBeenCompletedFirstLongTask = false; var haveBeenCompletedSecondLongTask = false; var jobFactory = new SimpleJob(); void RunLongTask(object locker1, object locker2, ref bool haveBeenCompleted) { lock (locker1) { jobFactory.DoCorseGrainedJob(1000); lock (locker2) { jobFactory.DoCorseGrainedJob(1000); haveBeenCompleted = true; } } } var thread1 = new Thread(() => RunLongTask(obj1, obj2, ref haveBeenCompletedFirstLongTask)); var thread2 = new Thread(() => RunLongTask(obj2, obj1, ref haveBeenCompletedSecondLongTask)); thread1.Start(); thread2.Start(); thread1.Join(); thread2.Join(); Assert.True(haveBeenCompletedFirstLongTask); Assert.True(haveBeenCompletedSecondLongTask); }
public void ScheduleSimpleJob() { didDispose = 0; SimpleJob job = new SimpleJob() { a = 5, b = 10 }; NativeArray <int> jobResult = new NativeArray <int>(SimpleJob.N, Allocator.TempJob); job.result = jobResult; JobHandle handle = job.Schedule(); handle.Complete(); #if !UNITY_DOTSPLAYER // TODO: Understand / fix why the editor tests don't run quite the same code path. job.mDisposable.Dispose(); #endif Assert.AreEqual(1, didDispose); for (int i = 0; i < SimpleJob.N; ++i) { Assert.AreEqual(15, jobResult[i]); } jobResult.Dispose(); }
public IHttpActionResult ScheduleJob() { var simpleJob = new SimpleJob(); RecurringJob.AddOrUpdate(() => simpleJob.Execute(), Cron.Minutely); return(Ok($"recurring job scheduled")); }
public void SetUpSchedule() { TestJob = new SimpleJob((dt) => { }); TestSchedule = new TestSchedule() { NextSchedule = NextScheduleType.Later }; }
static string ExecuteVisualizationDefinitionSimpleJob(string contents) { var si = new SimpleJob(); si.UnSerialize(SimpleJobView(contents, "jobDefinition.html")); si.Execute().GetAwaiter().GetResult(); return("jobDefinition.html"); }
public IHttpActionResult ScheduleOneTimeJob() { var simpleJob = new SimpleJob(); var jobId = BackgroundJob.Enqueue(() => simpleJob.Execute()); return(Ok($"fire and forget job {jobId} fired")); }
public void ShouldReportErrorInAsyncTask() { SimpleJob testJob = new SimpleJob(async(dt) => await Task.Run(() => { throw new DivideByZeroException(); })); UnderTest.ScheduleJob(MockSchedule.Object, exeptionJob.Object, true); UnderTest.Start(); Assert.True(errorManualReset.WaitOne()); Assert.IsInstanceOf <DivideByZeroException>(reportedException); }
public SchedulerOneJobTest(ITestOutputHelper testOutputHelper) { _simpleJobInstance = new SimpleJob(); var serviceProvider = new TestActivator(_simpleJobInstance); var jobManager = new JobManager(serviceProvider, new XUnitLogger <JobManager>(testOutputHelper), new InMemoryStorage()); _scheduler = new Scheduler(serviceProvider, new XUnitLogger <Scheduler>(testOutputHelper), new UtcSchedulerClock(), jobManager); }
public void ShouldExecute() { var job = new SimpleJob((dt) => { }); UnderTest.ScheduleJob(TestSchedule, job, true); UnderTest.Start(); Assert.True(successManualReset.WaitOne()); successManualReset.Reset(); Assert.True(successManualReset.WaitOne()); }
public void Start(string[] startupArguments, ServiceStoppedCallback serviceStoppedCallback) { ImportSettings(); singularity = Singularity.Instance; var job = new SimpleJob((scheduledTime) => GetAndCompareCommits()); var schedule = new EveryXTimeSchedule(TimeSpan.FromSeconds(12)); var scheduledJob = singularity.ScheduleJob(schedule, job, true); singularity.Start(); }
public void RunTestSystemCommandTasklet() { SimpleJobLauncher launcher = new SimpleJobLauncher(); IJobInstanceDao jobInstanceDao = new MapJobInstanceDao(); IJobExecutionDao jobExecutionDao = new MapJobExecutionDao(); IStepExecutionDao stepExecutionDao = new MapStepExecutionDao(); IExecutionContextDao executionContextDao = new MapExecutionContextDao(); IJobRepository jobRepository = new SimpleJobRepository(jobInstanceDao, jobExecutionDao, stepExecutionDao, executionContextDao); launcher.JobRepository = jobRepository; DefaultJobParametersConverter converter = new DefaultJobParametersConverter(); NameValueCollection props2 = new NameValueCollection { { "+dateDebut(date)", "1970/07/31" }, { "+everything(long)", "42" }, { "-balance(double)", "1000.0" }, { "+name(string)", "thierry" }, { "-default", "default" } }; JobParameters jobParameters = converter.GetJobParameters(props2); IJob job = new SimpleJob("myTestJob"); job.JobParametersValidator = new DummyValidator(); job.Restartable = false; TaskletStep step = new TaskletStep("simpleTS") { JobRepository = jobRepository }; SystemCommandTasklet tasklet = new SystemCommandTasklet { Command = "DEL MyDummyTasklet2_out_*.txt", WorkingDirectory = "C:/temp", Timeout = 10000000, SystemProcessExitCodeMapper = new SimpleSystemProcessExitCodeMapper() }; step.Tasklet = tasklet; step.RegisterStepExecutionListener(tasklet); ((SimpleJob)job).AddStep(step); ((SimpleJob)job).JobRepository = jobRepository; ITaskExecutor taskExecutor = new SimpleAsyncTaskExecutor(); launcher.TaskExecutor = taskExecutor; JobExecution jobExecution = launcher.Run(job, jobParameters); //wait for execution end (asynchronous) Assert.IsFalse(jobExecution.Status.IsUnsuccessful()); Assert.IsFalse(jobExecution.Status.IsRunning()); }
public void ShouldReportExceptionWhenExceptionSet() { var job = new SimpleJob((dt) => { }) { ScheduleMissedBehavior = ScheduleMissedBehavior.ThrowException }; UnderTest.ScheduleJob(TestSchedule, job, true); UnderTest.Start(); Assert.True(successManualReset.WaitOne()); successManualReset.Reset(); Assert.True(scheduleErrorManualReset.WaitOne()); }
public void SimpleJob_Assert_Output() { var job = new SimpleJob(); for (int i = 0; i < 100; i++) { Assert.That(job.Output.Count, Is.EqualTo(i)); job.InternalPerform(i); Assert.That(job.Output.Count, Is.EqualTo(i + 1)); } }
/// <summary> /// Builds the job. /// </summary> /// <returns></returns> public IJob Build() { if (_builder != null) { return _builder.End().Build(); } SimpleJob job = new SimpleJob(GetName()); Enhance(job); job.Steps = _steps; try { job.AfterPropertiesSet(); } catch (Exception e) { throw new JobBuilderException(e); } return job; }