// == METHOD(S)
        // ======================================================================

        /// <summary>
        /// Method invoked when task starts the work.
        /// </summary>
        /// <returns>Object : Usually the return is NULL.</returns>
        private Object taskExecution()
        {
            Object retValue = null;

            try
            {
                if (this._state == ScheduledTaskState.ERROR)
                {
                    this._newTentative = true;
                }
                else
                {
                    this._newTentative = false;
                }

                this._state = ScheduledTaskState.RUNNING;

                // == TASK LIFE-CYCLE EXECUTION

                this._cancellationToken = new CancellationTokenSource();
                onStart();

                // PARAMETER TREATMENT

                JObject param = null;

                if (this.task.Param != null)
                {
                    try
                    {
                        param = JObject.Parse(this.task.Param);
                    }
                    catch (System.Exception e)
                    {
                        throw new AuctionMasterTaskException(ExceptionType.FATAL, "Invalid param formatting - Expected: Valid JSON.");
                    }
                }

                onExecute(param, this._cancellationToken.Token);

                onFinish();
                this._state = ScheduledTaskState.IDLE;
            }
            catch (System.Exception e)
            {
                if (!(e is AuctionMasterTaskException))
                {
                    e = new AuctionMasterTaskException(ExceptionType.FATAL, e.Message, e);
                }

                this._state = ScheduledTaskState.ERROR;

                this.onError((AuctionMasterTaskException)e);
                retValue = (AuctionMasterTaskException)e;
            }

            return(retValue);
        }
        /// <summary>
        /// Event called when an exception is thrown inside the execution.
        /// </summary>
        /// <param name="e">Exception structure</param>
        protected virtual void onError(AuctionMasterTaskException e)
        {
            // == WRITES LOG ABOUT THE ERROR AND UPDATE TASK DATA

            this._taskLog.Status  = 0;
            this._taskLog.EndTime = DateTime.Now;
            this._taskLog.Tentatives++;

            this._taskLog.Message = this._message.ToString();
            this._databaseContext.Entry(this._taskLog).State = EntityState.Modified;
            this._databaseContext.SaveChanges();

            this._scope.Dispose();

            this._logService.writeLine(LogType.ERROR, $"Scheduled task [{this._scheduledTask.Name}] has finished with errors (Tentative {this._taskLog.Tentatives}). Details: {this._message.ToString()}", true);
            this._logService.finish();
        }
示例#3
0
        protected override void onError(AuctionMasterTaskException e)
        {
            this._message.Add("error", e.Message);

            base.onError(e);
        }