コード例 #1
0
ファイル: builtin_tasks.go プロジェクト: carriercomm/worker
func (c *ClearExpiredTokens) Run(job *shared.Job) error {
	args, ok := job.Args.(map[string]interface{})
	if !ok {
		return errors.New("Invalid args")
	}

	idb, ok := args["db"]
	if !ok {
		return errors.New("Invalid args")
	}

	sdb, ok := idb.(string)
	if !ok {
		return errors.New("Invalid args")
	}

	_, err := gorethink.Db(sdb).Table("tokens").Filter(gorethink.Le(gorethink.Row.Field("expiry_date"), gorethink.Now())).Delete().Run(session)
	return err
}
コード例 #2
0
ファイル: task_script_js.go プロジェクト: carriercomm/worker
func enrichFilter(input map[string]interface{}) {
	for k, v1 := range input {
		if v2, ok := v1.(string); ok {
			if strings.HasPrefix(v2, "not~") {
				if len(v2) > 4 {
					input[k] = gorethink.Not(gorethink.Expr(v2[5:]))
				}
			} else if strings.HasPrefix(v2, "lt~") && len(v2) > 3 {
				if v2[3:] == "now" {
					input[k] = gorethink.Lt(gorethink.Now())
				} else {
					t, err := time.Parse(time.RFC3339, v2[3:])
					if err == nil {
						input[k] = gorethink.Lt(gorethink.Expr(t))
					} else {
						i, err := strconv.Atoi(v2[3:])
						if err == nil {
							input[k] = gorethink.Lt(gorethink.Expr(i))
						}
					}
				}
			} else if strings.HasPrefix(v2, "le~") && len(v2) > 3 {
				if v2[3:] == "now" {
					input[k] = gorethink.Le(gorethink.Now())
				} else {
					t, err := time.Parse(time.RFC3339, v2[3:])
					if err == nil {
						input[k] = gorethink.Le(gorethink.Expr(t))
					} else {
						i, err := strconv.Atoi(v2[3:])
						if err == nil {
							input[k] = gorethink.Le(gorethink.Expr(i))
						}
					}
				}
			} else if strings.HasPrefix(v2, "gt~") && len(v2) > 3 {
				if v2[3:] == "now" {
					input[k] = gorethink.Gt(gorethink.Now())
				} else {
					t, err := time.Parse(time.RFC3339, v2[3:])
					if err == nil {
						input[k] = gorethink.Gt(gorethink.Expr(t))
					} else {
						i, err := strconv.Atoi(v2[3:])
						if err == nil {
							input[k] = gorethink.Gt(gorethink.Expr(i))
						}
					}
				}
			} else if strings.HasPrefix(v2, "ge~") && len(v2) > 3 {
				if v2[3:] == "now" {
					input[k] = gorethink.Ge(gorethink.Now())
				} else {
					t, err := time.Parse(time.RFC3339, v2[3:])
					if err == nil {
						input[k] = gorethink.Ge(gorethink.Expr(t))
					} else {
						i, err := strconv.Atoi(v2[3:])
						if err == nil {
							input[k] = gorethink.Ge(gorethink.Expr(i))
						}
					}
				}
			}
		}
	}
}