Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NotificationHandler doesn't work fine with BackgroundTaskQueue #15532

Closed
jmc18 opened this issue Jan 5, 2024 · 4 comments
Closed

NotificationHandler doesn't work fine with BackgroundTaskQueue #15532

jmc18 opened this issue Jan 5, 2024 · 4 comments
Labels
state/needs-more-info We don't have enough information to give a good reply type/bug

Comments

@jmc18
Copy link

jmc18 commented Jan 5, 2024

Which Umbraco version are you using? (Please write the exact version, example: 10.1.0)

13.0.3

Bug summary

I created a NotificationHandler to process information of a CSV file but that file has thousands of records, then I thought of using a background task so that the notification does not wait until all the records have been processed.

If we don't use the background task we don't have the error, but we cannot upload files because Media Section keeps waiting and when we try to upload the files, the save button stays with the loading indicator.

We have this error in the notification:

Authorization error: Unauthorized access to URL: /umbraco/backoffice/umbracoapi/media/PostSave Contact your administrator for information.

Here is the code that we have:

public class MediaSavedNotificationHandler(IBackgroundTaskQueue queue, IServiceProvider serviceProvider) 
    : INotificationAsyncHandler<MediaSavedNotification>
{
    public async Task HandleAsync(MediaSavedNotification notification, CancellationToken cancellationToken)
    {
        var mediaItems = notification.SavedEntities;
        foreach (var mediaItem in mediaItems)
        {
            if (mediaItem.Key == MediaNodeIdIdentifiers.MaintenanceProvidersFileNodeId)
            {
                queue.QueueBackgroundWorkItem(async cancellationToken =>
                {
                    using IServiceScope scope = serviceProvider.CreateScope();
                    var maintenanceProviderService = scope.ServiceProvider.GetRequiredService<IMaintenanceProviderService>();
                    await maintenanceProviderService.ImportProviders(mediaItem.Id);
                });
                notification.Messages.Add(new EventMessage("Maintenance Provider Notification",
                    "The Maintenance Providers import process has started and is running in the background.",
                    EventMessageType.Info));
                return;
            }
        }
    }
}

Here is the error that we have:

image

The records are in the custom table:
image

Note: Everything is still working and running in the background.

Specifics

No response

Steps to reproduce

image

image

Expected result / actual result

No response

@jmc18 jmc18 added the type/bug label Jan 5, 2024
Copy link

github-actions bot commented Jan 5, 2024

Hi there @jmc18!

Firstly, a big thank you for raising this issue. Every piece of feedback we receive helps us to make Umbraco better.

We really appreciate your patience while we wait for our team to have a look at this but we wanted to let you know that we see this and share with you the plan for what comes next.

  • We'll assess whether this issue relates to something that has already been fixed in a later version of the release that it has been raised for.
  • If it's a bug, is it related to a release that we are actively supporting or is it related to a release that's in the end-of-life or security-only phase?
  • We'll replicate the issue to ensure that the problem is as described.
  • We'll decide whether the behavior is an issue or if the behavior is intended.

We wish we could work with everyone directly and assess your issue immediately but we're in the fortunate position of having lots of contributions to work with and only a few humans who are able to do it. We are making progress though and in the meantime, we will keep you in the loop and let you know when we have any questions.

Thanks, from your friendly Umbraco GitHub bot 🤖 🙂

@Zeegaan
Copy link
Member

Zeegaan commented Jan 9, 2024

Setting up your notification handler I'm getting errors 😁
image

Could you provide one that works and some steps to follow from a clean install, so I can reproduce this 🙏

@Zeegaan Zeegaan added the state/needs-more-info We don't have enough information to give a good reply label Jan 9, 2024
@jmc18
Copy link
Author

jmc18 commented Jan 9, 2024

Hi @Zeegaan ,

I found the issue and that was my fault, I did not add the file extension to the AllowedUploadedFileExtensions settings, so I will close it.

image

I apologize

@jmc18 jmc18 closed this as completed Jan 9, 2024
@Zeegaan
Copy link
Member

Zeegaan commented Jan 10, 2024

All good, just glad you resolved this 💪

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state/needs-more-info We don't have enough information to give a good reply type/bug
Projects
None yet
Development

No branches or pull requests

2 participants