コード例 #1
0
    public override string CreateExpiredJob(Job job, IDictionary <string, string?> parameters, DateTime createdAt, TimeSpan expireIn)
    {
        if (job == null)
        {
            throw new ArgumentNullException(nameof(job));
        }
        if (parameters == null)
        {
            throw new ArgumentNullException(nameof(parameters));
        }

        InvocationData invocationData = InvocationData.SerializeJob(job);

        Documents.Job entityJob = new()
        {
            InvocationData = invocationData,
            Arguments      = invocationData.Arguments,
            CreatedOn      = createdAt,
            ExpireOn       = createdAt.Add(expireIn),
            Parameters     = parameters.Select(p => new Parameter
            {
                Name  = p.Key,
                Value = p.Value
            }).ToArray()
        };

        Documents.Job result = Storage.Container.CreateItemWithRetries(entityJob, PartitionKeys.Job);
        return(result.Id);
    }
コード例 #2
0
    public override JobData?GetJobData(string?jobId)
    {
        if (jobId == null)
        {
            throw new ArgumentNullException(nameof(jobId));
        }
        if (Guid.TryParse(jobId, out Guid _) == false)
        {
            return(null);
        }

        try
        {
            Documents.Job data = Storage.Container.ReadItemWithRetries <Documents.Job>(jobId, PartitionKeys.Job);

            InvocationData invocationData = data.InvocationData;
            invocationData.Arguments = data.Arguments;

            Job?job = null;
            JobLoadException?loadException = null;

            try
            {
                job = invocationData.DeserializeJob();
            }
            catch (JobLoadException ex)
            {
                loadException = ex;
            }

            return(new JobData
            {
                Job = job,
                State = data.StateName,
                CreatedAt = data.CreatedOn,
                LoadException = loadException
            });
        }
        catch (CosmosException ex) when(ex.StatusCode == HttpStatusCode.NotFound)
        {
            /* ignored */
        }
        catch (AggregateException ex) when(ex.InnerException is CosmosException {
            StatusCode: HttpStatusCode.NotFound
        })