You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.5 KiB
Go
51 lines
1.5 KiB
Go
9 months ago
|
package commands
|
||
|
|
||
|
import (
|
||
|
"log"
|
||
|
|
||
|
"git.cheetah.cat/archivinator-ng/workerclient/common"
|
||
|
"git.cheetah.cat/archivinator-ng/workerclient/db"
|
||
|
grabber "git.cheetah.cat/archivinator-ng/workerclient/downloader"
|
||
|
"go.temporal.io/sdk/client"
|
||
|
"go.temporal.io/sdk/worker"
|
||
|
)
|
||
|
|
||
|
type WorkerCommand struct {
|
||
|
//Token string `long:"token" description:"authenticate with this token"`
|
||
|
}
|
||
|
|
||
|
func (command *WorkerCommand) Execute(args []string) error {
|
||
|
db.Initialize()
|
||
|
|
||
|
// The client and worker are heavyweight objects that should be created once per process.
|
||
|
c, err := client.Dial(client.Options{
|
||
|
HostPort: common.WorkerSettings.TemporalHost,
|
||
|
Namespace: common.WorkerSettings.TemporalNS,
|
||
|
})
|
||
|
if err != nil {
|
||
|
log.Fatalln("Unable to create client", err)
|
||
|
}
|
||
|
defer c.Close()
|
||
|
|
||
|
w := worker.New(c, "request-grabber", worker.Options{
|
||
|
MaxConcurrentActivityExecutionSize: 3,
|
||
|
EnableSessionWorker: true, // Important for a worker to participate in the session
|
||
|
})
|
||
|
|
||
|
w.RegisterWorkflow(grabber.RequestProcessingWorkflow)
|
||
|
w.RegisterWorkflow(grabber.FetchRequestContentsWorkflow)
|
||
|
|
||
|
w.RegisterActivity(grabber.DBSelectOutdatedRequests)
|
||
|
w.RegisterActivity(grabber.DBLoadRequestEntry)
|
||
|
w.RegisterActivity(grabber.FetchRequestContents)
|
||
|
w.RegisterActivity(grabber.DBUpdateRequestLastChecked)
|
||
|
//w.RegisterWorkflow(grabber.SampleParentWorkflow)
|
||
|
//w.RegisterWorkflow(grabber.SampleChildWorkflow)
|
||
|
|
||
|
err = w.Run(worker.InterruptCh())
|
||
|
if err != nil {
|
||
|
log.Fatalln("Unable to start worker", err)
|
||
|
}
|
||
|
return nil
|
||
|
}
|