Ejemplo n.º 1
0
 public List_SendEmail_Handeler(IDapper <List_SendEmail> demoCustomer, ICacheService cache, IBackgroundJob backgroundJob, INotificationMsg notification)
 {
     _query         = demoCustomer;
     _cache         = cache;
     _backgroundJob = backgroundJob;
     _notification  = notification;
 }
Ejemplo n.º 2
0
 public QueuedJob(IBackgroundJob job, IBackgroundJobHandler handler)
 {
     if (job == null) throw new ArgumentNullException("job");
       if (handler == null) throw new ArgumentNullException("handler");
       _job = job;
       _handler = handler;
 }
        public static IBackgroundJob GetJob(JobModel model)
        {
            IBackgroundJob job = null;

            switch (model.Job.ToLower())
            {
            case "import":
            {
                job = new Thoughtpost.Background.Import.ImportCsvJob();
            }
            break;

            case "images":
            {
                job = new Thoughtpost.Background.Import.ImportImageSearchJob();
            }
            break;

            default:
            {
                job = new SleepJob();
            }
            break;
            }

            return(job);
        }
        private void OnExecuteJob(object state)
        {
            Task allTask = null;

            try
            {
                Parallel.ForEach(_syncJobTypes, jobType =>
                {
                    IBackgroundJob job = null;
                    try
                    {
                        using (var scope = _container.CreateScope())
                        {
                            try
                            {
                                job = (IBackgroundJob)scope.Resolve(jobType);
                                ScopeCreated(this, new ScopeCreatedEventArgs(scope));
                                job.Execute();
                                Signal.Reset("ApplicationServices[" + job.GetType() + "].Failed");
                                ScopeClosing(this, new ScopeClosingEventArgs(scope, true));
                            }
                            catch (Exception exception)
                            {
                                Signal.Raise("ApplicationServices[" + jobType.FullName + "].Failed", "Failed to execute job.", exception);
                                var args = new BackgroundJobFailedEventArgs(job ?? new NoJob(jobType, exception), exception);
                                JobFailed(this, args);
                                ScopeClosing(this, new ScopeClosingEventArgs(scope, false)
                                {
                                    Exception = exception
                                });
                            }
                        }
                    }
                    catch (Exception exception)
                    {
                        JobFailed(this, new BackgroundJobFailedEventArgs(new NoJob(jobType, exception), exception));
                        _logger.Error("Failed to execute job: " + job, exception);
                    }
                });

                var tasks = _asyncJobTypes.Select(ExecuteAsyncJob);
                allTask = Task.WhenAll(tasks);
                allTask.Wait();
            }
            catch (Exception exception)
            {
                _logger.Error("failed to execute jobs", exception);
                if (allTask != null)
                {
                    JobFailed(this, new BackgroundJobFailedEventArgs(new NoJob(GetType(), allTask.Exception), exception));
                }
                else
                {
                    JobFailed(this, new BackgroundJobFailedEventArgs(new NoJob(GetType(), exception), exception));
                }
            }
        }
Ejemplo n.º 5
0
 public Dapper(IConfiguration config, ILogger <Dapper <T> > logger, IGetQuery query, APP_DbContext dbContext, IBackgroundJob backgroundClient, ICacheService cache)
 {
     _config        = config;
     _logger        = logger;
     _query         = query;
     _dbContext     = dbContext;
     _backgroundJob = backgroundClient;
     _cache         = cache;
 }
Ejemplo n.º 6
0
 public void SpawnJob(IBackgroundJob job)
 {
     if (job.JobNumber == 0)
       {
     throw new ArgumentException("job");
       }
       IBackgroundJobHandler jobHandler = _jobHandlerLocator.LocateJobHandler(job.GetType());
       IThread thread = _threadManager.CreateThread(new QueuedJob(job, jobHandler));
       thread.Start();
 }
Ejemplo n.º 7
0
 public virtual void AddJob(IBackgroundJob job)
 {
     if (job.JobNumber > 0)
       {
     throw new InvalidOperationException();
       }
       using (RWLock.AsReader(_lock))
       {
     if (_jobs.Contains(job))
     {
       throw new InvalidOperationException();
     }
     job.JobNumber = _jobs.Count + 1;
     _jobs.Add(job);
       }
 }
        private void ExecuteSyncJob(Type jobType)
        {
            IBackgroundJob job = null;

            try
            {
                using (var scope = _container.CreateScope())
                {
                    try
                    {
                        job = (IBackgroundJob)scope.Resolve(jobType);
                        if (job == null)
                        {
                            throw new InvalidOperationException(string.Format("Failed to resolve job type '{0}'.", jobType.FullName));
                        }

                        ScopeCreated(this, new ScopeCreatedEventArgs(scope));
                        job.Execute();
                        ScopeClosing(this, new ScopeClosingEventArgs(scope, true));
                    }
                    catch (Exception exception)
                    {
                        var args = new BackgroundJobFailedEventArgs(job ?? new NoJob(jobType, exception), exception);
                        JobFailed(this, args);
                        ScopeClosing(this, new ScopeClosingEventArgs(scope, false)
                        {
                            Exception = exception
                        });
                    }
                }
            }
            catch (Exception exception)
            {
                JobFailed(this, new BackgroundJobFailedEventArgs(new NoJob(jobType, exception), exception));
                _logger.Error("Failed to execute job: " + job, exception);
            }
        }
        public async static Task <ResponseModel> InternalRun(JobModel model,
                                                             IBackgroundJob job,
                                                             ILogger logger,
                                                             ExecutionContext context)
        {
            logger.LogInformation($"Run of Job {model.Job} for ID = '{model.Id}'.");

            ResponseModel response = new ResponseModel()
            {
                Id = model.Id
            };

            try
            {
                var config = new ConfigurationBuilder()
                             .SetBasePath(context.FunctionAppDirectory)
                             .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
                             .AddEnvironmentVariables()
                             .Build();

                StatusRelay relay = new StatusRelay(config);
                await relay.Initialize();

                response = await job.Run(model, relay, logger, config);
            }
            catch (Exception ex)
            {
                logger.LogError(ex.Message, ex);
                logger.LogError(ex.StackTrace);

                response.Success = false;
                response.Message = ex.Message;
            }

            return(response);
        }
 public User_Lst_cmd_Handeler(IDapper <TblUsermaster> dapper, ICacheService cache, IBackgroundJob backgroundJob)
 {
     _dapper        = dapper;
     _cache         = cache;
     _backgroundJob = backgroundJob;
 }
Ejemplo n.º 11
0
 public virtual void SaveJob(IBackgroundJob job)
 {
     if (job.JobNumber == 0)
       {
     AddJob(job);
       }
 }
 public NotificationMsg(IDapper <NotficationCls> repository, IBackgroundJob backgroundJob)
 {
     _repository    = repository;
     _backgroundJob = backgroundJob;
 }
 public async Task Enqueue(IBackgroundJob request)
 {
     await _mediator.Publish(request);
 }
Ejemplo n.º 14
0
        private void Enqueue(IBackgroundJob request)
        {
            var client = new BackgroundJobClient();

            client.Enqueue <MediatorHangfireBridge>(bus => bus.Enqueue(request));
        }
Ejemplo n.º 15
0
        private void Schedule(IBackgroundJob request, TimeSpan timeSpan)
        {
            var client = new BackgroundJobClient();

            client.Schedule <MediatorHangfireBridge>(bus => bus.Enqueue(request), timeSpan);
        }
 public async Task Enqueue(string jobName, IBackgroundJob request)
 {
     await _mediator.Publish(request);
 }
Ejemplo n.º 17
0
 public IBackgroundJob QueueJob(IBackgroundJob job)
 {
     IJobRepository jobRepository = _jobRepositoryLocator.LocateJobRepository(job.GetType());
       jobRepository.SaveJob(job);
       return job;
 }