add task for linting

This commit is contained in:
gabriel ruttner
2025-04-25 08:50:19 -04:00
parent cc491cb822
commit ee4a3f80dc
8 changed files with 30 additions and 27 deletions
+3
View File
@@ -53,6 +53,9 @@ tasks:
SERVER_INTERNAL_CLIENT_BASE_STRATEGY=none
SERVER_INTERNAL_CLIENT_BASE_INHERIT_BASE=false
EOF
pre:
cmds:
- pre-commit run --all-files
start-db:
cmds:
- docker compose up -d
+1 -1
View File
@@ -5,7 +5,7 @@ import (
"os"
"time"
v1_workflows "github.com/hatchet-dev/hatchet/examples/v1/workflows"
v1_workflows "github.com/hatchet-dev/hatchet/examples/go/workflows"
"github.com/hatchet-dev/hatchet/pkg/cmdutils"
v1 "github.com/hatchet-dev/hatchet/pkg/v1"
"github.com/hatchet-dev/hatchet/pkg/v1/worker"
@@ -314,7 +314,7 @@ print(result)
import (
"fmt"
v1_workflows "github.com/hatchet-dev/hatchet/examples/v1/workflows"
v1_workflows "github.com/hatchet-dev/hatchet/examples/go/workflows"
v1 "github.com/hatchet-dev/hatchet/pkg/v1"
"github.com/hatchet-dev/hatchet/pkg/v1/workflow"
"github.com/joho/godotenv"
@@ -314,7 +314,7 @@ print(result)
import (
"fmt"
v1_workflows "github.com/hatchet-dev/hatchet/examples/v1/tasks"
v1_workflows "github.com/hatchet-dev/hatchet/examples/go/tasks"
v1 "github.com/hatchet-dev/hatchet/pkg/v1"
"github.com/hatchet-dev/hatchet/pkg/v1/workflow"
"github.com/joho/godotenv"
+2 -2
View File
@@ -14,13 +14,13 @@ export const Snippet = ({ src }: GithubSnippetProps) => {
}
const [question, filePath] = src.split(":");
// Get the snippet content from the snippets object
const snippet = snippets[filePath];
if (!snippet) {
throw new Error(`Snippet content not found: ${filePath}`);
}
return (
<CodeBlock
source={{
+1 -1
View File
@@ -1064,7 +1064,7 @@ export const snippets: Snippets = {
"source": "examples/go/run/simple.go"
},
"L1VzZXJzL2dhYnJpZWxydXR0bmVyL2Rldi9oYXRjaGV0L2V4YW1wbGVzL2dvL3dvcmtlci9zdGFydC5nbw__": {
"content": "package main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"time\"\n\n\tv1_workflows \"github.com/hatchet-dev/hatchet/examples/v1/workflows\"\n\t\"github.com/hatchet-dev/hatchet/pkg/cmdutils\"\n\tv1 \"github.com/hatchet-dev/hatchet/pkg/v1\"\n\t\"github.com/hatchet-dev/hatchet/pkg/v1/worker\"\n\t\"github.com/hatchet-dev/hatchet/pkg/v1/workflow\"\n\t\"github.com/joho/godotenv\"\n)\n\nfunc main() {\n\terr := godotenv.Load()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\thatchet, err := v1.NewHatchetClient()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Get workflow name from command line arguments\n\tvar workflowName string\n\tif len(os.Args) > 1 {\n\t\tworkflowName = os.Args[1]\n\t\tfmt.Println(\"workflow name provided:\", workflowName)\n\t}\n\n\t// Define workflows map\n\tworkflowMap := map[string][]workflow.WorkflowBase{\n\t\t\"dag\": {v1_workflows.DagWorkflow(hatchet)},\n\t\t\"on-failure\": {v1_workflows.OnFailure(hatchet)},\n\t\t\"simple\": {v1_workflows.Simple(hatchet)},\n\t\t\"sleep\": {v1_workflows.DurableSleep(hatchet)},\n\t\t\"child\": {v1_workflows.Parent(hatchet), v1_workflows.Child(hatchet)},\n\t\t\"cancellation\": {v1_workflows.Cancellation(hatchet)},\n\t\t\"timeout\": {v1_workflows.Timeout(hatchet)},\n\t\t\"sticky\": {v1_workflows.Sticky(hatchet), v1_workflows.StickyDag(hatchet), v1_workflows.Child(hatchet)},\n\t\t\"retries\": {v1_workflows.Retries(hatchet), v1_workflows.RetriesWithCount(hatchet), v1_workflows.WithBackoff(hatchet)},\n\t\t\"on-cron\": {v1_workflows.OnCron(hatchet)},\n\t\t\"non-retryable\": {v1_workflows.NonRetryableError(hatchet)},\n\t\t\"priority\": {v1_workflows.Priority(hatchet)},\n\t}\n\n\t// Add an \"all\" option that registers all workflows\n\tallWorkflows := []workflow.WorkflowBase{}\n\tfor _, wfs := range workflowMap {\n\t\tallWorkflows = append(allWorkflows, wfs...)\n\t}\n\tworkflowMap[\"all\"] = allWorkflows\n\n\t// Lookup workflow from map\n\tworkflow, ok := workflowMap[workflowName]\n\tif !ok {\n\t\tfmt.Println(\"Invalid workflow name provided. Usage: go run examples/v1/worker/start.go [workflow-name]\")\n\t\tfmt.Println(\"Available workflows:\", getAvailableWorkflows(workflowMap))\n\t\tos.Exit(1)\n\t}\n\n\tvar slots int\n\tif workflowName == \"priority\" {\n\t\tslots = 1\n\t} else {\n\t\tslots = 100\n\t}\n\n\tworker, err := hatchet.Worker(\n\t\tworker.WorkerOpts{\n\t\t\tName: fmt.Sprintf(\"%s-worker\", workflowName),\n\t\t\tWorkflows: workflow,\n\t\t\tSlots: slots,\n\t\t},\n\t)\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tinterruptCtx, cancel := cmdutils.NewInterruptContext()\n\n\terr = worker.StartBlocking(interruptCtx)\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tgo func() {\n\t\ttime.Sleep(10 * time.Second)\n\t\tcancel()\n\t}()\n}\n\n// Helper function to get available workflows as a formatted string\nfunc getAvailableWorkflows(workflowMap map[string][]workflow.WorkflowBase) string {\n\tvar workflows string\n\tcount := 0\n\tfor name := range workflowMap {\n\t\tif count > 0 {\n\t\t\tworkflows += \", \"\n\t\t}\n\t\tworkflows += fmt.Sprintf(\"'%s'\", name)\n\t\tcount++\n\t}\n\treturn workflows\n}\n",
"content": "package main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"time\"\n\n\tv1_workflows \"github.com/hatchet-dev/hatchet/examples/go/workflows\"\n\t\"github.com/hatchet-dev/hatchet/pkg/cmdutils\"\n\tv1 \"github.com/hatchet-dev/hatchet/pkg/v1\"\n\t\"github.com/hatchet-dev/hatchet/pkg/v1/worker\"\n\t\"github.com/hatchet-dev/hatchet/pkg/v1/workflow\"\n\t\"github.com/joho/godotenv\"\n)\n\nfunc main() {\n\terr := godotenv.Load()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\thatchet, err := v1.NewHatchetClient()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Get workflow name from command line arguments\n\tvar workflowName string\n\tif len(os.Args) > 1 {\n\t\tworkflowName = os.Args[1]\n\t\tfmt.Println(\"workflow name provided:\", workflowName)\n\t}\n\n\t// Define workflows map\n\tworkflowMap := map[string][]workflow.WorkflowBase{\n\t\t\"dag\": {v1_workflows.DagWorkflow(hatchet)},\n\t\t\"on-failure\": {v1_workflows.OnFailure(hatchet)},\n\t\t\"simple\": {v1_workflows.Simple(hatchet)},\n\t\t\"sleep\": {v1_workflows.DurableSleep(hatchet)},\n\t\t\"child\": {v1_workflows.Parent(hatchet), v1_workflows.Child(hatchet)},\n\t\t\"cancellation\": {v1_workflows.Cancellation(hatchet)},\n\t\t\"timeout\": {v1_workflows.Timeout(hatchet)},\n\t\t\"sticky\": {v1_workflows.Sticky(hatchet), v1_workflows.StickyDag(hatchet), v1_workflows.Child(hatchet)},\n\t\t\"retries\": {v1_workflows.Retries(hatchet), v1_workflows.RetriesWithCount(hatchet), v1_workflows.WithBackoff(hatchet)},\n\t\t\"on-cron\": {v1_workflows.OnCron(hatchet)},\n\t\t\"non-retryable\": {v1_workflows.NonRetryableError(hatchet)},\n\t\t\"priority\": {v1_workflows.Priority(hatchet)},\n\t}\n\n\t// Add an \"all\" option that registers all workflows\n\tallWorkflows := []workflow.WorkflowBase{}\n\tfor _, wfs := range workflowMap {\n\t\tallWorkflows = append(allWorkflows, wfs...)\n\t}\n\tworkflowMap[\"all\"] = allWorkflows\n\n\t// Lookup workflow from map\n\tworkflow, ok := workflowMap[workflowName]\n\tif !ok {\n\t\tfmt.Println(\"Invalid workflow name provided. Usage: go run examples/v1/worker/start.go [workflow-name]\")\n\t\tfmt.Println(\"Available workflows:\", getAvailableWorkflows(workflowMap))\n\t\tos.Exit(1)\n\t}\n\n\tvar slots int\n\tif workflowName == \"priority\" {\n\t\tslots = 1\n\t} else {\n\t\tslots = 100\n\t}\n\n\tworker, err := hatchet.Worker(\n\t\tworker.WorkerOpts{\n\t\t\tName: fmt.Sprintf(\"%s-worker\", workflowName),\n\t\t\tWorkflows: workflow,\n\t\t\tSlots: slots,\n\t\t},\n\t)\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tinterruptCtx, cancel := cmdutils.NewInterruptContext()\n\n\terr = worker.StartBlocking(interruptCtx)\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tgo func() {\n\t\ttime.Sleep(10 * time.Second)\n\t\tcancel()\n\t}()\n}\n\n// Helper function to get available workflows as a formatted string\nfunc getAvailableWorkflows(workflowMap map[string][]workflow.WorkflowBase) string {\n\tvar workflows string\n\tcount := 0\n\tfor name := range workflowMap {\n\t\tif count > 0 {\n\t\t\tworkflows += \", \"\n\t\t}\n\t\tworkflows += fmt.Sprintf(\"'%s'\", name)\n\t\tcount++\n\t}\n\treturn workflows\n}\n",
"language": "go",
"source": "examples/go/worker/start.go"
},
+9 -9
View File
@@ -19,15 +19,15 @@ const IGNORE_LIST = [
'*.test.*',
'*.spec.*',
'*.test-d.*',
// Python specific
'__pycache__',
'.pytest_cache',
'*.pyc',
// System files
'.DS_Store',
// Development directories
'node_modules',
'.git',
@@ -93,7 +93,7 @@ async function restorePreservedFiles(dir, preserved) {
async function removeDirectoryContents(dir) {
try {
const entries = await fs.readdir(dir, { withFileTypes: true });
for (const entry of entries) {
const fullPath = path.join(dir, entry.name);
if (entry.isDirectory()) {
@@ -185,16 +185,16 @@ async function main() {
for (const { source, dest } of mappings) {
// Create destination if it doesn't exist
await fs.mkdir(dest, { recursive: true });
// Backup preserved files
const preserved = await backupPreservedFiles(dest);
console.log(`Cleaning ${dest}...`);
await removeDirectoryContents(dest);
console.log(`Copying ${source} to ${dest}...`);
await copyDirectory(source, dest);
// Restore preserved files
await restorePreservedFiles(dest, preserved);
}
@@ -202,4 +202,4 @@ async function main() {
console.log('Examples copied successfully!');
}
main().catch(console.error);
main().catch(console.error);
+12 -12
View File
@@ -20,17 +20,17 @@ function extractQuestions(filePath) {
const content = fs.readFileSync(filePath, 'utf8');
const lines = content.split('\n');
const questions = [];
// Match both Python (#) and JS/TS (//) style comments followed by ❓ or ?
const questionRegex = /^[\s]*(\/\/|#).*[❓?]/;
lines.forEach((line) => {
if (questionRegex.test(line)) {
const comment = line.trim().replace(/^[\s]*(\/\/|#)[\s]*/, '');
questions.push(cleanQuestionText(comment));
}
});
return questions;
}
@@ -74,36 +74,36 @@ function processDirectory(dirPath) {
// Process file
const fileName = normalizeKey(path.basename(item, path.extname(item)));
const ext = path.extname(fullPath).slice(1) || 'txt';
// Check if this is a root file (directly in language directory)
const isRootFile = path.dirname(fullPath) === dirPath &&
const isRootFile = path.dirname(fullPath) === dirPath &&
['ts', 'js', 'py', 'go'].includes(ext);
// Include if it's a root file or one of our specific file types
if (isRootFile || ['run', 'worker', 'workflow'].includes(fileName)) {
const content = fs.readFileSync(fullPath, 'utf8');
const snippetId = createSnippetId(fullPath);
// Store the snippet content and metadata
snippetsMap.set(snippetId, {
content,
language: ext,
source: path.relative(projectRoot, fullPath)
});
const questions = extractQuestions(fullPath);
// Create an object with "*" as the first key and empty question
const fileObj = {
"*": ":"+snippetId
};
// Add each question as a key pointing to the same snippetId
questions.forEach(question => {
const normalizedQuestion = normalizeKey(question);
fileObj[normalizedQuestion] = `${question}:${snippetId}`;
});
// For root files, store under a special key
if (isRootFile) {
result[fileName] = fileObj;
@@ -151,4 +151,4 @@ export default snips;
`;
fs.writeFileSync(outputPath, fileContent, 'utf8');
console.log('Successfully generated snips file at:', outputPath);
console.log('Successfully generated snips file at:', outputPath);