github.com/songzhibin97/gkit@v1.2.13/distributed/task/option.go (about)

     1  package task
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/songzhibin97/gkit/options"
     7  )
     8  
     9  // SetGroupID 设置多群组中id
    10  func SetGroupID(id string) options.Option {
    11  	return func(t interface{}) {
    12  		t.(*Signature).GroupID = id
    13  	}
    14  }
    15  
    16  // SetPriority 设置任务优先级
    17  func SetPriority(priority uint8) options.Option {
    18  	return func(t interface{}) {
    19  		t.(*Signature).Priority = priority
    20  	}
    21  }
    22  
    23  // SetRetryCount 设置重试次数
    24  func SetRetryCount(count int) options.Option {
    25  	return func(t interface{}) {
    26  		t.(*Signature).RetryCount = count
    27  	}
    28  }
    29  
    30  // SetRetryInterval 设置间隔时间
    31  func SetRetryInterval(interval int) options.Option {
    32  	return func(t interface{}) {
    33  		t.(*Signature).RetryInterval = interval
    34  	}
    35  }
    36  
    37  // SetStopTaskDeletionOnError 设置任务出错后是否删除
    38  func SetStopTaskDeletionOnError(deleteOnErr bool) options.Option {
    39  	return func(t interface{}) {
    40  		t.(*Signature).StopTaskDeletionOnError = deleteOnErr
    41  	}
    42  }
    43  
    44  // SetIgnoreNotRegisteredTask 设置任务未注册是否忽略
    45  func SetIgnoreNotRegisteredTask(register bool) options.Option {
    46  	return func(t interface{}) {
    47  		t.(*Signature).IgnoreNotRegisteredTask = register
    48  	}
    49  }
    50  
    51  // SetRouter 设置路由
    52  func SetRouter(router string) options.Option {
    53  	return func(t interface{}) {
    54  		t.(*Signature).Router = router
    55  	}
    56  }
    57  
    58  // SetArgs 设置参数
    59  func SetArgs(args ...Arg) options.Option {
    60  	return func(t interface{}) {
    61  		t.(*Signature).Args = args
    62  	}
    63  }
    64  
    65  // AddArgs 追加参数
    66  func AddArgs(args ...Arg) options.Option {
    67  	return func(t interface{}) {
    68  		t.(*Signature).Args = append(t.(*Signature).Args, args...)
    69  	}
    70  }
    71  
    72  // SetMetaSafe 设置是否创建安全的meta
    73  func SetMetaSafe(safe bool) options.Option {
    74  	return func(t interface{}) {
    75  		t.(*Signature).MetaSafe = safe
    76  	}
    77  }
    78  
    79  // SetMeta 设置Meta
    80  func SetMeta(meta *Meta) options.Option {
    81  	return func(t interface{}) {
    82  		t.(*Signature).Meta = meta
    83  	}
    84  }
    85  
    86  // SetETATime 延时任务设置执行时间
    87  func SetETATime(after *time.Time) options.Option {
    88  	return func(t interface{}) {
    89  		t.(*Signature).ETA = after
    90  	}
    91  }
    92  
    93  // SetCallbackOnSuccess 设置成功后回调
    94  func SetCallbackOnSuccess(tasks ...*Signature) options.Option {
    95  	return func(t interface{}) {
    96  		t.(*Signature).CallbackOnSuccess = tasks
    97  	}
    98  }
    99  
   100  // AddCallbackOnError 追加失败后回调
   101  func AddCallbackOnError(tasks ...*Signature) options.Option {
   102  	return func(t interface{}) {
   103  		t.(*Signature).CallbackOnError = append(t.(*Signature).CallbackOnError, tasks...)
   104  	}
   105  }
   106  
   107  // SetCallbackOnError 设置失败后回调
   108  func SetCallbackOnError(tasks ...*Signature) options.Option {
   109  	return func(t interface{}) {
   110  		t.(*Signature).CallbackOnError = tasks
   111  	}
   112  }
   113  
   114  // AddCallbackOnSuccess 追加成功后回调
   115  func AddCallbackOnSuccess(tasks ...*Signature) options.Option {
   116  	return func(t interface{}) {
   117  		t.(*Signature).CallbackOnSuccess = append(t.(*Signature).CallbackOnSuccess, tasks...)
   118  	}
   119  }
   120  
   121  // SetTriggerChord .
   122  func SetTriggerChord(task *Signature) options.Option {
   123  	return func(t interface{}) {
   124  		t.(*Signature).CallbackChord = task
   125  	}
   126  }