Pass arguments to a sensor #24786
Answered
by
garethbrickman
petarzoric
asked this question in
Q&A
-
Hi Guys, I am building a sensor that connects to a GitLab repository and triggers whenever there is a new commit. @sensor(name="git_sensor", job=some_job)
def git_commit_sensor(context):
headers = {"PRIVATE-TOKEN": GITLAB_TOKEN}
response = requests.get(GITLAB_API_BASE, headers=headers)
if response.status_code == 200:
commits = response.json()
if not commits:
return SkipReason("No new commits found")
latest_commit = commits[0]
commit_id = latest_commit['id']
commit_message = latest_commit['message']
# Get the previous commit ID from the cursor
last_commit_id = context.cursor
if last_commit_id!= commit_id:
print(f"fetched new commit with message {commit_message}")
context.update_cursor(commit_id)
return RunRequest(run_key=commit_id)
else:
context.log.error(f"Failed to fetch commits: {response.status_code} - {response.text}")` I would like to pass in the git branch in a way like this: @sensor(name="git_sensor", job=some_job)
def git_commit_sensor(context, git_branch):` How can I achieve this? |
Beta Was this translation helpful? Give feedback.
Answered by
garethbrickman
Sep 26, 2024
Replies: 1 comment 2 replies
-
Check out using resources in sensors: https://docs.dagster.io/concepts/partitions-schedules-sensors/sensors#using-resources-in-sensors |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
petarzoric
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Check out using resources in sensors: https://docs.dagster.io/concepts/partitions-schedules-sensors/sensors#using-resources-in-sensors