Skip to content

RefreshBadge

Akumetsu edited this page Nov 14, 2022 · 1 revision

Description

The RefreshBadge operation is an asynchronous operation that refreshes the badge stored in the Supabase bucket with the latest value for the metric.
The operation is called from an AWS SQS queue.

Env Variables

Variable Required Description
PG_URI True Postgres Connection Uri: postgresql://<username>:<password>@<host>:<port>/<database>
SUPABASE_URL True Url to the Supabase instance (c.f. Supabase docs)
SUPABASE_KEY True Anon Private Key for the Supabase instance

Architecture

sequenceDiagram
	SQS ->> Entrypoint: {creator, name, metric, params}
	Entrypoint ->> RefreshBadgeOperation: {creator, name, metric}
	RefreshBadgeOperation ->> ActionRepo: getByCreatorAndName(creator, name)
	ActionRepo ->> RefreshBadgeOperation: action
 	RefreshBadgeOperation ->> BadgeRepo: badgeExists(action.id, metric)
	alt BadgeDoesNotExist
		rect rgba(150, 0, 0, 0.2)
			BadgeRepo ->> RefreshBadgeOperation: False
			RefreshBadgeOperation ->> RefreshBadgeOperation: badge = null
			RefreshBadgeOperation ->> RefreshBadgeOperation: path = getDefaultStoragePath({creator, name, metric})
		end
	end
	alt BadgeExists
		rect rgba(0,150,0,0.2)
			BadgeRepo ->> RefreshBadgeOperation: True
			RefreshBadgeOperation ->> BadgeRepo: getBadge(action.id, metric)
			BadgeRepo ->> RefreshBadgeOperation: badge
			RefreshBadgeOperation ->> RefreshBadgeOperation: path = badge.path
		end
	end
	RefreshBadgeOperation ->> MetricRepo: computeMetric(params, actionData)
	MetricRepo ->> RefreshBadgeOperation: value
	RefreshBadgeOperation ->> RefreshBadgeOperation: label = getBadgeLabel(metric)
	RefreshBadgeOperation ->> RefreshBadgeOperation: badgeSvg = generateBadge(label, value)
	RefreshBadgeOperation --) BadgeStorageRepo: put(path, badgeSvg)
	RefreshBadgeOperation ->> BadgeStorageRepo: getPublicUrl(path)
	BadgeStorageRepo ->> RefreshBadgeOperation: uri
	alt BadgeDoesNotExist
		rect rgba(150, 0, 0, 0.2)
			RefreshBadgeOperation --) BadgeRepo: createBadge(newBadgeInformation)
		end
	end
	alt BadgeExists
		rect rgba(0, 150, 0, 0.2)
			RefreshBadgeOperation --) BadgeRepo: updateBadge(newBadgeInformation)
		end
	end
Loading

Home

Contribution Docs

Developer Documentations

Clone this wiki locally