Base solution for your next web application
Open Closed

User / Tenant Based Background Jobs #1286


User avatar
0
andis created

I have background jobs which enqueued by user, how to let user to see all their jobs, and what are their statuses?


4 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    ABP framework has not such a feature since ABP's implementation is very simple. There are really good background job frameworks like HangFire. You can check them if they have such a feature. If not, you should implement your own solution for that.

  • User Avatar
    0
    andis created

    Since ABP have no such feature, I wish to implement it myself by creating an Entity[TenantId, UserId, Log, JobId] to log those processes. I wish to link the created object with the enqueued job(JobId property) but BackgroundJobManager.Enqueu() method was not returning enqueued job(return type is void), any advice to get the enqueued job?

  • User Avatar
    0
    andis created
    protected abstract void DoJob();
            [UnitOfWork]
            public override void Execute(T args)
            {
                UserEnqueuedJob userEnqueuedJob = UserEnqueuedJobRepository.Get(args.UserEnqueuedJobId);
                userEnqueuedJob.Status = Entity.Enum.JobStatus.Executing;
                try
                {
                    DoJob();
                }
                finally
                {
                    userEnqueuedJob.Status = Entity.Enum.JobStatus.Executed;
                }
            }
    

    Can I create a new UnitOfWork to set UserEnqueuedJob status to Executing?

  • User Avatar
    0
    hikalkan created
    Support Team

    Since UOW is transactional, setting status to executing will not be written to database until your method ends. so, it has no meaning. I haven't understand your goal, but as a formal review, you should set status to executing in a different uow.