<commit_before>package jobs

import (
	"time"

	"github.com/cozy/cozy-stack/pkg/consts"
	"github.com/cozy/cozy-stack/web/jsonapi"
	"github.com/robfig/cron"
)

// CronTrigger implements the @cron trigger type. It schedules recurring jobs with
// the weird but very used Cron syntax.
type CronTrigger struct {
	sched cron.Schedule
	infos *TriggerInfos
	done  chan struct{}
}

// NewCronTrigger returns a new instance of CronTrigger given the specified options.
func NewCronTrigger(infos *TriggerInfos) (*CronTrigger, error) {
	schedule, err := cron.ParseStandard(infos.Arguments)
	if err != nil {
		return nil, jsonapi.BadRequest(err)
	}
	return &CronTrigger{
		sched: schedule,
		infos: infos,
		done:  make(chan struct{}),
	}, nil
}

// NewEveryTrigger returns an new instance of CronTrigger given the specified
// options as @every.
func NewEveryTrigger(infos *TriggerInfos) (*CronTrigger, error) {
	schedule, err := cron.Parse("@every " + infos.Arguments)
	if err != nil {
		return nil, jsonapi.BadRequest(err)
	}
	return &CronTrigger{
		sched: schedule,
		infos: infos,
		done:  make(chan struct{}),
	}, nil
}

// Type implements the Type method of the Trigger interface.<commit_msg>Accept seconds in @cron triggers<commit_after>package jobs

import (
	"time"

	"github.com/cozy/cozy-stack/pkg/consts"
	"github.com/cozy/cozy-stack/web/jsonapi"
	"github.com/robfig/cron"
)

// CronTrigger implements the @cron trigger type. It schedules recurring jobs with
// the weird but very used Cron syntax.
type CronTrigger struct {
	sched cron.Schedule
	infos *TriggerInfos
	done  chan struct{}
}

// NewCronTrigger returns a new instance of CronTrigger given the specified options.
func NewCronTrigger(infos *TriggerInfos) (*CronTrigger, error) {
	schedule, err := cron.Parse(infos.Arguments)
	if err != nil {
		return nil, jsonapi.BadRequest(err)
	}
	return &CronTrigger{
		sched: schedule,
		infos: infos,
		done:  make(chan struct{}),
	}, nil
}

// NewEveryTrigger returns an new instance of CronTrigger given the specified
// options as @every.
func NewEveryTrigger(infos *TriggerInfos) (*CronTrigger, error) {
	schedule, err := cron.Parse("@every " + infos.Arguments)
	if err != nil {
		return nil, jsonapi.BadRequest(err)
	}
	return &CronTrigger{
		sched: schedule,
		infos: infos,
		done:  make(chan struct{}),
	}, nil
}

// Type implements the Type method of the Trigger interface.
{'fraction_non_alphanumeric': 0.11204364246747797, 'fraction_numerical': 0.0, 'mean_word_length': 4.286031042128603, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2326103', 'n_tokens_mistral': 824, 'n_tokens_neox': 782, 'n_words': 237}