Files
Alex ShtinandGitHub 8e8f1b0f7c Remove license header from every file (#7689)
## What changed?
<!-- Describe what has changed in this PR -->
Remove license header from every file. Because it is really hard to
follow in this PR here is the summary:
1. License header is removed from all `.go` and `.proto` files
:fireworks::fireworks:🎆.
2. `LICENSE` file in the root directory has only Temporal and Uber
copyrights.
3. 5 other `LICENSE` files added to the packages which have copyrights
different from Temporal and Uber: Datadog, Xargin, "Mat Ryer, Tyler
Bunnell and contributors".
4. `license_file` flag is removed from all code generation tools.
5. `copyright_file` flag is removed from `go:generate mockgen`
directive.
6. All copyright related targets are removed from `Makefile`.
7. Updated Temporal copyright year to 2025 everywhere.

## Why?
<!-- Tell your future self why have you made these changes -->
I double checked with legal department that it is not needed to have
license header in every file. One file per repo is enough. I put all
copyrights to the root `LICENSE` file and removed header from all other
files. Also updated tools and `Makefile`.
2025-05-01 18:50:21 -07:00

141 lines
3.1 KiB
Go

package taskqueue
import (
"encoding/binary"
"sync"
"time"
"github.com/pborman/uuid"
persistencespb "go.temporal.io/server/api/persistence/v1"
p "go.temporal.io/server/common/persistence"
"go.temporal.io/server/common/primitives/timestamp"
"google.golang.org/protobuf/types/known/timestamppb"
)
type (
mockTaskTable struct {
namespaceID string
workflowID string
runID string
nextTaskID int64
tasks []*persistencespb.AllocatedTaskInfo
}
mockTaskQueueTable struct {
sync.Mutex
info []*p.PersistedTaskQueueInfo
}
)
func newMockTaskTable() *mockTaskTable {
return &mockTaskTable{
namespaceID: uuid.New(),
workflowID: uuid.New(),
runID: uuid.New(),
}
}
func (tbl *mockTaskQueueTable) generate(name string, idle bool) {
tq := p.PersistedTaskQueueInfo{
Data: &persistencespb.TaskQueueInfo{
NamespaceId: uuid.New(),
Name: name,
LastUpdateTime: timestamp.TimeNowPtrUtc(),
},
RangeID: 22,
}
if idle {
tq.Data.LastUpdateTime = timestamppb.New(time.Unix(1000, 1000).UTC())
}
tbl.info = append(tbl.info, &tq)
}
func (tbl *mockTaskQueueTable) list(token []byte, count int) ([]*p.PersistedTaskQueueInfo, []byte) {
tbl.Lock()
defer tbl.Unlock()
if tbl.info == nil {
return nil, nil
}
var off int
if token != nil {
off = int(binary.BigEndian.Uint32(token))
}
rem := len(tbl.info) - count + 1
if rem < count {
return tbl.info[off:], nil
}
token = make([]byte, 4)
binary.BigEndian.PutUint32(token, uint32(off+count))
return tbl.info[off : off+count], token
}
func (tbl *mockTaskQueueTable) delete(name string) {
tbl.Lock()
defer tbl.Unlock()
var newInfo []*p.PersistedTaskQueueInfo
for _, tl := range tbl.info {
if tl.Data.Name != name {
newInfo = append(newInfo, tl)
}
}
tbl.info = newInfo
}
func (tbl *mockTaskQueueTable) get(name string) *p.PersistedTaskQueueInfo {
tbl.Lock()
defer tbl.Unlock()
for _, tl := range tbl.info {
if tl.Data.Name == name {
return tl
}
}
return nil
}
func (tbl *mockTaskTable) generate(count int, expired bool) {
for i := 0; i < count; i++ {
exp := time.Now().UTC().Add(time.Hour)
ti := &persistencespb.AllocatedTaskInfo{
Data: &persistencespb.TaskInfo{
NamespaceId: tbl.namespaceID,
WorkflowId: tbl.workflowID,
RunId: tbl.runID,
CreateTime: timestamp.TimePtr(time.Now().UTC()),
ScheduledEventId: 3,
ExpiryTime: timestamppb.New(exp),
},
TaskId: tbl.nextTaskID,
}
if expired {
ti.Data.ExpiryTime = timestamppb.New(time.Unix(0, time.Now().UTC().UnixNano()-int64(time.Second*33)).UTC())
}
tbl.tasks = append(tbl.tasks, ti)
tbl.nextTaskID++
}
}
func (tbl *mockTaskTable) get(count int) []*persistencespb.AllocatedTaskInfo {
if len(tbl.tasks) >= count {
return tbl.tasks[:count]
}
return tbl.tasks[:]
}
func (tbl *mockTaskTable) deleteLessThan(id int64, limit int) int {
count := 0
for _, t := range tbl.tasks {
if t.GetTaskId() < id && count < limit {
count++
continue
}
break
}
switch {
case count == 0:
case count == len(tbl.tasks):
tbl.tasks = nil
default:
tbl.tasks = tbl.tasks[count:]
}
return count
}