add-otel #3
							
								
								
									
										19
									
								
								feed.go
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								feed.go
									
									
									
									
									
								
							@ -32,7 +32,7 @@ type Feed struct {
 | 
				
			|||||||
	LastScanOn  TwtTime
 | 
						LastScanOn  TwtTime
 | 
				
			||||||
	RefreshRate int
 | 
						RefreshRate int
 | 
				
			||||||
	NextScanOn  TwtTime
 | 
						NextScanOn  TwtTime
 | 
				
			||||||
        LastTwtOn   TwtTime
 | 
						LastTwtOn   TwtTime
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	LastModified TwtTime
 | 
						LastModified TwtTime
 | 
				
			||||||
	LastError    sql.NullString
 | 
						LastError    sql.NullString
 | 
				
			||||||
@ -321,7 +321,7 @@ func storeFeed(ctx context.Context, db db, f types.TwtFile) error {
 | 
				
			|||||||
	if prev, ok := f.Info().GetN("prev", 0); ok {
 | 
						if prev, ok := f.Info().GetN("prev", 0); ok {
 | 
				
			||||||
		_, part, ok := strings.Cut(prev.Value(), " ")
 | 
							_, part, ok := strings.Cut(prev.Value(), " ")
 | 
				
			||||||
		if ok {
 | 
							if ok {
 | 
				
			||||||
			uri:= f.Twter().URI
 | 
								uri := f.Twter().URI
 | 
				
			||||||
			if u, ok := f.Info().GetN("url", 0); ok {
 | 
								if u, ok := f.Info().GetN("url", 0); ok {
 | 
				
			||||||
				uri = u.Value()
 | 
									uri = u.Value()
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
@ -333,13 +333,13 @@ func storeFeed(ctx context.Context, db db, f types.TwtFile) error {
 | 
				
			|||||||
			childID := urlNS.UUID5(part)
 | 
								childID := urlNS.UUID5(part)
 | 
				
			||||||
			fmt.Println("found prev", uri, part)
 | 
								fmt.Println("found prev", uri, part)
 | 
				
			||||||
			args = append(args,
 | 
								args = append(args,
 | 
				
			||||||
				childID,   // feed_id
 | 
									childID,                // feed_id
 | 
				
			||||||
				feedID, // parent_id
 | 
									feedID,                 // parent_id
 | 
				
			||||||
				f.Twter().DomainNick(), // nick
 | 
									f.Twter().DomainNick(), // nick
 | 
				
			||||||
				part, // uri
 | 
									part,                   // uri
 | 
				
			||||||
				 "once", // state
 | 
									"once",                 // state
 | 
				
			||||||
				nil, // last_scan_on
 | 
									nil,                    // last_scan_on
 | 
				
			||||||
				0, // refresh_rate
 | 
									0,                      // refresh_rate
 | 
				
			||||||
			)
 | 
								)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -373,6 +373,9 @@ func (feed *Feed) MakeHTTPRequest(ctx context.Context) (*http.Request, error) {
 | 
				
			|||||||
	if strings.Contains(feed.URI, "lublin.se") {
 | 
						if strings.Contains(feed.URI, "lublin.se") {
 | 
				
			||||||
		return nil, fmt.Errorf("%w: permaban: %s", ErrPermanentlyDead, feed.URI)
 | 
							return nil, fmt.Errorf("%w: permaban: %s", ErrPermanentlyDead, feed.URI)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if strings.Contains(feed.URI, "enotty.dk") {
 | 
				
			||||||
 | 
							return nil, fmt.Errorf("%w: permaban: %s", ErrPermanentlyDead, feed.URI)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	req, err := http.NewRequestWithContext(ctx, "GET", feed.URI, nil)
 | 
						req, err := http.NewRequestWithContext(ctx, "GET", feed.URI, nil)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										2
									
								
								http.go
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								http.go
									
									
									
									
									
								
							@ -106,7 +106,7 @@ func httpServer(c *console, app *appState) error {
 | 
				
			|||||||
	})
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	http.HandleFunc("/api/plain/twt", func(w http.ResponseWriter, r *http.Request) {
 | 
						http.HandleFunc("/api/plain/twt", func(w http.ResponseWriter, r *http.Request) {
 | 
				
			||||||
 		ctx, span := otel.Span(r.Context())
 | 
							ctx, span := otel.Span(r.Context())
 | 
				
			||||||
		defer span.End()
 | 
							defer span.End()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		args := make([]any, 0, 3)
 | 
							args := make([]any, 0, 3)
 | 
				
			||||||
 | 
				
			|||||||
@ -20,7 +20,7 @@ import (
 | 
				
			|||||||
	otelprom "go.opentelemetry.io/otel/exporters/prometheus"
 | 
						otelprom "go.opentelemetry.io/otel/exporters/prometheus"
 | 
				
			||||||
	"go.opentelemetry.io/otel/exporters/stdout/stdoutlog"
 | 
						"go.opentelemetry.io/otel/exporters/stdout/stdoutlog"
 | 
				
			||||||
	"go.opentelemetry.io/otel/exporters/stdout/stdouttrace"
 | 
						"go.opentelemetry.io/otel/exporters/stdout/stdouttrace"
 | 
				
			||||||
	"go.opentelemetry.io/otel/log/global"    
 | 
						"go.opentelemetry.io/otel/log/global"
 | 
				
			||||||
	"go.opentelemetry.io/otel/metric"
 | 
						"go.opentelemetry.io/otel/metric"
 | 
				
			||||||
	"go.opentelemetry.io/otel/propagation"
 | 
						"go.opentelemetry.io/otel/propagation"
 | 
				
			||||||
	"go.opentelemetry.io/otel/sdk/log"
 | 
						"go.opentelemetry.io/otel/sdk/log"
 | 
				
			||||||
 | 
				
			|||||||
@ -140,7 +140,7 @@ func processorLoop(ctx context.Context, db db, fetch *pool[*Feed, *Response]) {
 | 
				
			|||||||
			err := res.err
 | 
								err := res.err
 | 
				
			||||||
			if res.err != nil {
 | 
								if res.err != nil {
 | 
				
			||||||
				if errors.Is(err, ErrPermanentlyDead) {
 | 
									if errors.Is(err, ErrPermanentlyDead) {
 | 
				
			||||||
                                        f.State = "permanantly-dead"
 | 
										f.State = "permanantly-dead"
 | 
				
			||||||
					f.RefreshRate = TenYear
 | 
										f.RefreshRate = TenYear
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				if errors.Is(err, ErrTemporarilyDead) {
 | 
									if errors.Is(err, ErrTemporarilyDead) {
 | 
				
			||||||
@ -220,39 +220,39 @@ func processorLoop(ctx context.Context, db db, fetch *pool[*Feed, *Response]) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func checkTemp(twts types.Twts) (int, State) {
 | 
					func checkTemp(twts types.Twts) (int, State) {
 | 
				
			||||||
	if len(twts) < 5 {
 | 
						if len(twts) < 5 {
 | 
				
			||||||
		return 7*OneDay, "cold"
 | 
							return 7 * OneDay, "cold"
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	sort.Sort(twts)
 | 
						sort.Sort(twts)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	since_first := -time.Until(twts[0].Created())
 | 
						since_first := -time.Until(twts[0].Created())
 | 
				
			||||||
	since_fifth := -time.Until(twts[4].Created())
 | 
						since_fifth := -time.Until(twts[4].Created())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if since_first < 2 * time.Hour || since_fifth < 8 * time.Hour {
 | 
						if since_first < 2*time.Hour || since_fifth < 8*time.Hour {
 | 
				
			||||||
		return TwoMinutes, "hot"
 | 
							return TwoMinutes, "hot"
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if since_first < 4 * time.Hour || since_fifth < 16 * time.Hour{
 | 
						if since_first < 4*time.Hour || since_fifth < 16*time.Hour {
 | 
				
			||||||
		return TenMinutes, "hot"
 | 
							return TenMinutes, "hot"
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if since_first < 8 * time.Hour || since_fifth < 32 * time.Hour{
 | 
						if since_first < 8*time.Hour || since_fifth < 32*time.Hour {
 | 
				
			||||||
		return 2*TenMinutes, "warm"
 | 
							return 2 * TenMinutes, "warm"
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if since_first < 16 * time.Hour || since_fifth < 64 * time.Hour{
 | 
						if since_first < 16*time.Hour || since_fifth < 64*time.Hour {
 | 
				
			||||||
		return 4*TenMinutes, "warm"
 | 
							return 4 * TenMinutes, "warm"
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if since_first < 24 * time.Hour || since_fifth < 128 * time.Hour{
 | 
						if since_first < 24*time.Hour || since_fifth < 128*time.Hour {
 | 
				
			||||||
		return OneDay, "cold"
 | 
							return OneDay, "cold"
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if since_first < 48 * time.Hour || since_fifth < 256 * time.Hour{
 | 
						if since_first < 48*time.Hour || since_fifth < 256*time.Hour {
 | 
				
			||||||
		return 2*OneDay, "cold"
 | 
							return 2 * OneDay, "cold"
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if since_first < 96 * time.Hour || since_fifth < 512 * time.Hour{
 | 
						if since_first < 96*time.Hour || since_fifth < 512*time.Hour {
 | 
				
			||||||
		return 7*OneDay, "frozen"
 | 
							return 7 * OneDay, "frozen"
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return OneMonth, "frozen"
 | 
						return OneMonth, "frozen"
 | 
				
			||||||
@ -261,32 +261,32 @@ func checkTemp(twts types.Twts) (int, State) {
 | 
				
			|||||||
func tsTemp(ts time.Time) (int, State) {
 | 
					func tsTemp(ts time.Time) (int, State) {
 | 
				
			||||||
	since_first := -time.Until(ts)
 | 
						since_first := -time.Until(ts)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if since_first < 2 * time.Hour {
 | 
						if since_first < 2*time.Hour {
 | 
				
			||||||
		return TwoMinutes, "hot"
 | 
							return TwoMinutes, "hot"
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if since_first < 4 * time.Hour {
 | 
						if since_first < 4*time.Hour {
 | 
				
			||||||
		return TenMinutes, "hot"
 | 
							return TenMinutes, "hot"
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if since_first < 8 * time.Hour {
 | 
						if since_first < 8*time.Hour {
 | 
				
			||||||
		return 2*TenMinutes, "warm"
 | 
							return 2 * TenMinutes, "warm"
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if since_first < 16 * time.Hour {
 | 
						if since_first < 16*time.Hour {
 | 
				
			||||||
		return 4*TenMinutes, "warm"
 | 
							return 4 * TenMinutes, "warm"
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if since_first < 24 * time.Hour {
 | 
						if since_first < 24*time.Hour {
 | 
				
			||||||
		return OneDay, "cold"
 | 
							return OneDay, "cold"
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if since_first < 48 * time.Hour {
 | 
						if since_first < 48*time.Hour {
 | 
				
			||||||
		return 2*OneDay, "cold"
 | 
							return 2 * OneDay, "cold"
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if since_first < 96 * time.Hour {
 | 
						if since_first < 96*time.Hour {
 | 
				
			||||||
		return 7*OneDay, "frozen"
 | 
							return 7 * OneDay, "frozen"
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return OneMonth, "frozen"
 | 
						return OneMonth, "frozen"
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										6
									
								
								uuid.go
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								uuid.go
									
									
									
									
									
								
							@ -70,8 +70,8 @@ func (l *strList) Scan(value any) error {
 | 
				
			|||||||
func (l strList) Value() (driver.Value, error) {
 | 
					func (l strList) Value() (driver.Value, error) {
 | 
				
			||||||
	arr := make([]string, len(l))
 | 
						arr := make([]string, len(l))
 | 
				
			||||||
	for i, v := range l {
 | 
						for i, v := range l {
 | 
				
			||||||
		arr[i] = "\""+v+"\""
 | 
							arr[i] = "\"" + v + "\""
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return "["+strings.Join(arr, ",") +"]", nil
 | 
						return "[" + strings.Join(arr, ",") + "]", nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user