Ejemplo n.º 1
0
        public int GetCurrentInstanceId()
        {
            string ip       = GetCurrentExternalIP();
            var    instance = _instanceRepository.GetAll(n => n.IP == ip).FirstOrDefault();

            return(instance.Id);
        }
Ejemplo n.º 2
0
        public void StartJob(Guid jobId)
        {
            if (_taskSettings.Tasks.ContainsKey(jobId))
            {
                _logger.LogWarning($"Multiple attempts to start Job with Id: {jobId}");
                return;
            }

            int?instanceId = _intanceRepository.GetAll(n => !n.IsDown && n.IsAvailable).FirstOrDefault()?.Id;

            if (!instanceId.HasValue)
            {
                throw new Exception("No available instances.");
            }

            var job = _jobRepository.GetAll(n => !n.IsRunning && n.Id == jobId).FirstOrDefault();

            if (job == null)
            {
                _logger.LogWarning($"No available job found for Id: {jobId}");
                return;
            }

            string crawlPath = PluginHelper.GetLocalPluginPath(job.Name, job.PluginPath, job.DateModified);

            var tokenSource = new CancellationTokenSource();
            var token       = tokenSource.Token;

            Task.Factory.StartNew(async() =>
            {
                try
                {
                    using (var scope = _serviceScopeFactory.CreateScope())
                    {
                        var jobExecuterService = scope.ServiceProvider.GetRequiredService <IJobExecuter>();
                        //await jobExecuterService.RunJob(instanceId.Value, jobId, crawlPath, token);
                        await jobExecuterService.RunJobWithCsvProcessor(instanceId.Value, jobId, crawlPath, token);

                        tokenSource.Dispose();

                        _taskSettings.Tasks.TryRemove(jobId, out tokenSource);
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogError($"Failed to run job with id: {jobId}", ex);
                }
            }, token);

            _taskSettings.Tasks.TryAdd(jobId, tokenSource);
        }
Ejemplo n.º 3
0
 public static List <Instance> GetAll()
 {
     return(repository.GetAll());
 }
Ejemplo n.º 4
0
        public IEnumerable <Instance> GetAssignedInstances(int userId)
        {
            List <int> assignedInstanceId = GetAssignedInstanceId(userId);

            return(instanceRepository.GetAll().Where(g => assignedInstanceId.Any(i => i == g.Id)));
        }
Ejemplo n.º 5
0
 public IEnumerable <Instance> Get()
 {
     return(_instanceRepository.GetAll());
 }