Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyash-b committed Dec 23, 2022
2 parents 1feba60 + a3ca754 commit b279476
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 0 deletions.
38 changes: 38 additions & 0 deletions bin/nask
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ ns {
do
]

Timeline # autoload TimelineItem
type PipelineExecution(HashLike)

F watch() {
log("Starting to watch AWS profile ${profile}")
while true {
Expand Down Expand Up @@ -68,6 +71,11 @@ ns {

}

F horizon() {
seconds = ENV.get('HORIZON', '3600').Int()
Time(Time().Int() - seconds)
}

F inspect() {
log("Looking up stacks")
stacks = AWS2::regions(%(aws cloudformation describe-stacks))
Expand All @@ -82,7 +90,37 @@ ns {
pipelines = AWS2::regions(%(aws codepipeline list-pipelines), pipelines_regions)
log("Pipelines found in regions: ${pipelines._Region.sort().Stats()}")

# pipelines.pmap(4, inspect_pipeline)
inspect_pipeline(pipelines[0])

# TODO: AMIs creation
}

global TimelineItem
F TimelineItem(pe:PipelineExecution) {
TimelineItem().set(time_start=pe.startTime, time_last_update=pe.lastUpdateTime, data=pe)
}

# TODO: AWS types such as CodePipeline
F inspect_pipeline(pipeline:Hash) {
assert(pipeline, {'name': Str, 'version': Int, 'created': Str, 'updated': Str, '_Region': Str})

pipelineExecutionSummaries = ``aws codepipeline list-pipeline-executions --pipeline-name ${pipeline.name} --region ${pipeline._Region}``
pipelineExecutionSummaries._Region = ConstIter(pipeline._Region)
pipelineExecutionSummaries .= map(PipelineExecution)

# lastUpdateTime pipelineExecutionId sourceRevisions startTime status trigger _Region
pipelineExecutionSummaries.each(F(s) {
s.startTime .= Time()
s.lastUpdateTime .= Time()
})
pipelineExecutionSummaries.map(F(s) {
TimelineItem(s)
}).filter(F(ti) ti.Time() > horizon()).Timeline().set(name="Pipeline ${pipeline.name} after ${horizon()}")
}

F inspect_pipeline(name:Str) {
``aws codepipeline list-pipelines``.the_one({'name': name}).set(_Region=`line: aws configure get region`).inspect_pipeline()
}

}
73 changes: 73 additions & 0 deletions lib/autoload/globals/Timeline.ngs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
ns {

global Timeline, TimelineItem, Time, Lines, init, each, map, sort, push, echo_cli
type Timeline

doc time_start - Time
doc time_last_update - Time
doc time_end - Null or Time
doc data - Any
type TimelineItem

F init(t:Timeline) {
t.id = "tl-${`line: uuidgen`}" # temporary
t.name = '(unnamed)'
# later # t.time_start = null
# later # t.time_last_update = null
# later # t.time_end = null
t.items = []
}

F init(t:Timeline, items:Arr) {
super(t)
t.items = items
t.sort()
}

F each(t:Timeline, cb:Fun) t::{A.items.each(cb)}
F map(t:Timeline, mapper:Fun) t.items.map(mapper)

F sort(t:Timeline) t::{
A.items .= sort(F(a, b) a.Time() <= b.Time())
}

F push(t:Timeline, ti:TimelineItem) t::{
A.items.push(ti)
A.sort() # TODO: insert in the correct place, keeping .items sorted by time
}

F init(ti:TimelineItem) {
ti.id = "tli-${`line: uuidgen`}" # temporary
ti.time_start = null
ti.time_last_update = null
ti.time_end = null
}

F Time(ti:TimelineItem) ti.time_end or ti.time_last_update or ti.time_start

section "Formatting" {

type _Ctx
F init(ctx:_Ctx) {
ctx.depth = 0
}

F _pfx(ctx:_Ctx) " " * ctx.depth
F _deeper(ctx:_Ctx) ctx.copy()::{ A.depth += 1 }

# not global
F inspect(t:Timeline, ctx:_Ctx) {
[
"${t.Type().name}: ${t.name}"
ctx._deeper()._pfx() + "id: ${t.id}"
ctx._deeper()._pfx() + "items (${t.items.len()}):"
]
}

F Lines(t:Timeline) Lines(inspect(t, _Ctx()))

F echo_cli(t:Timeline) {
t.Lines().echo()
}
}
}

0 comments on commit b279476

Please sign in to comment.