0

i have service which working on cron expresions

    public Task DoProcessAsync()
    {
        return transactionService.CommitAsync(() => DoProcess());
    }

    private async Task DoProcess()
    {
        try{...}

        catch{logger.logError("error");}
    }

But i know that block try catch in this place i not good, because Commit will accepted. Also i have

    public Task Start()
    {
        exportCron = CronExtensions
             .Cron(sheduleConfiguration.SetCitiesCronExpression)
             .Select(x => Observable.FromAsync(() => setCitiesToClientsService.DoProcessAsync()))
             .Concat()
             .Subscribe();

        return Task.FromResult(0);
    }

So maybe i can place method catch() to this extension? If it is yes, how can i do this?

I've found

.Subscribe(onNext => { }, onError => { logger.LogError("Error"); } );

But sequnce had stopped working after error, but must continue. There are some propositions?

Dima Grigoriev
  • 357
  • 5
  • 22

2 Answers2

0
public async Task DoProcess()
{
    try
    {
        await Start();
    }
    catch (Exception e)
    {
    }
}

public Task DoProcess()
{
    try
    {
        Start().Wait();
    }
    catch (Exception e)
    {
    }
} 
Nathan
  • 401
  • 7
  • 13
0

You can use on you Observable definition: Retry(5) it retries 5 times, or Retry() infinite.

Example:

         Observable testObservable =
            Observable
                .Interval(TimeSpan.FromMilliseconds(20000))
                .Select(x => WhatEver()).ObserveOn(SynchronizationContext.Current)
                .Retry(retry);
AngelBlueSky
  • 575
  • 4
  • 10