-
- Notifications
You must be signed in to change notification settings - Fork 746
Expose timestamp and checksum to status #216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose timestamp and checksum to status #216
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @stephenprater,
Pretty good work, thanks for opening this pull request. 🙂
I did a couple of comments. The most challenging one is the suggestion to change .TIMESTAMP
from a string to a plain time.Time
struct, which may require changes on how Task handles variables (which are just strings currently) to accept interface{}
s.
Don't hesitate to ask if you need help or guidance help.
docs/usage.md Outdated
- test -f directory/file2.txt | ||
``` | ||
| ||
Normally, you would use either `status` or `sources` in combination with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the "Prevent unnecessary work" section is becaming big, perhaps we could separate it into subsections (using ###
for subtitles) for sources/generates vs. status vs. preconditions.
What do you think?
internal/status/checksum.go Outdated
return fmt.Sprintf("%x", h.Sum(nil)), nil | ||
} | ||
| ||
// Value implements the Chcker Interface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Value implements the Chcker Interface | |
// Value implements the Checker interface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, missing documentation comments for Kind()
functions.
variables.go Outdated
| ||
if len(origTask.Status) > 0 { | ||
| ||
e := &Executor{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we use the existing Executor
instance instead of instantiating another one?
variables.go Outdated
return nil, err | ||
} | ||
| ||
vars[strings.ToUpper(checker.Kind())] = taskfile.Var{Static: value} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should this whole if
block to the bottom of the function. Otherwise the TIMESTAMP
and CHECKSUM
variables will be available to the stuff parsed below, but not to those parse above, which would be a bit confusing. 🙂
Alternatively, we could clone the vars
map to prevent that.
variables.go Outdated
| ||
vars[strings.ToUpper(checker.Kind())] = taskfile.Var{Static: value} | ||
| ||
statusTemplater := templater.Templater{Vars: vars} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless the clone vars
, we don't need to instantiate another templater
since maps are pass-by-reference.
status.go Outdated
} | ||
| ||
func (e *Executor) getStatusChecker(t *taskfile.Task) (status.Checker, error) { | ||
func (e *Executor) GetStatusChecker(t *taskfile.Task) (status.Checker, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't necessarily need to make this function exported, since it's only called inside this package anyway.
internal/status/timestamp.go Outdated
return "0", nil | ||
} | ||
| ||
return fmt.Sprintf("%d", sourcesMaxTime.Unix()), nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... something to discuss here:
We could possibly pass the time.Time
struct to the template instead of converting it to string.
In that case, users would have to use {{.TIMESTAMP | unix}}
to get the user timestamp, or {{.TIMESTAMP | "2006-01-02"}}
to format it to the format they want to use.
This would need to be documented, and the return of Value()
would be changed to (interface{}, error)
.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am 100% on board with that.
[ "{{.TIMESTAMP}}" -gt "$({{.DATE_CMD}} --date $last_ami_date +"%s")" ]
Here's part of my actual invocation - where I have to parse a Date string from AWS into a unix timestamp while also templating in a system dependent invocation of date. Yeah - I'd rather do that in go templates for sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All great feedback. I'm definitely down for changing the type signature of Value.
internal/status/timestamp.go Outdated
return "0", nil | ||
} | ||
| ||
return fmt.Sprintf("%d", sourcesMaxTime.Unix()), nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am 100% on board with that.
[ "{{.TIMESTAMP}}" -gt "$({{.DATE_CMD}} --date $last_ami_date +"%s")" ]
Here's part of my actual invocation - where I have to parse a Date string from AWS into a unix timestamp while also templating in a system dependent invocation of date. Yeah - I'd rather do that in go templates for sure.
Hi @stephenprater, Sorry for asking, but just to make sure we're on the same page... Do you plan to do the necessary fixes or do you prefer me to work on it? If the latter, can you make sure this checkbox is checked? Thanks! |
Sorry Andrey, I’ve been kind of distracted the last week or so. I think I should be able to get to this tomorrow evening. …On Aug 11, 2019, 6:40 PM -0700, Andrey Nering ***@***.***>, wrote: Hi @stephenprater, Sorry for asking, but just to make sure we're on the same page... Do you plan to do the necessary fixes or do you prefer me to work on it? If the latter, can you make sure this checkbox is checked? Thanks! — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread. |
@stephenprater Don't hurry, take your time, we all have busy lives. I was just checking in. 😉 Thanks! |
Can you please move the target branch from |
Co-Authored-By: Andrey Nering <andrey.nering@gmail.com>
…tatus * upstream/v3: v3.0.0-preview1 Update v3 changelog Only have colored output on v3 Add --color=false flag to disable colored output Update documentation about sprig Update CHANGELOG Migrate from sprig to slim-sprig Fix build after merging master Use colors for some output messages
3951956
to 9aa9033
Compare @andreynering Sorry for the delay - the company I was doing this work for is doing some restructuring (notably, restructuring me and most of the employees out of a job). I made the changes you requested in terms of code review and took a stab at making the I had some trouble getting this to work without adding an additional "kind" of variable. Since the "static" variables are recursively replaced by their own values, I couldn't figure out how to allow the The |
* master: Update CHANGELOG Small improvements to go-task#228 Fix a typo Fix Checksum.IsUpToDate Remove directory check Update glob.go Separate error handlings for readability Re-run the task if generated files do not exist
9aa9033
to 6b0935d
Compare Hi @stephenprater, I'm really sorry to know that. All the luck on the search for a new job! Thanks for the updates, I'll review again once possible. |
…rpunkArmory/task into CypherpunkArmory-report-timestamp-to-status
Hi @stephenprater, This is now merged on the v3 branch. I did a few improvements here and here. Thanks a lot for the contribution and patience. It's much appreciated! ❤️ |
What changes does this PR introduce?
This introduces two special variables
{{.CHECKSUM}}
and{{.TIMESTAMP}}
tostatus
commands, to enable the checking of "up-to-dateness" of remote artifacts.Any background context you want to provide?
Generally, when you use
sources
- you also usegenerates
- if thegenerates
artifacts is newer than thesources
, then the your task is out of date and needs to be re-run. This works as long as you have direct access to the generated artifacts - but some tasks produce "remote artifacts" that don't live on the same file system as your sources (AMIs, Docker Images, Kubernetes Deploys) -status
already supportssh
based status checks - so we expanded this to evaluate remote artifacts.Which ever method you choose to fingerprint your sources will be exposed as a template variable to
status
shell commands.Currently, the expectation is that you would use
sources
andgenerates
together and thenstatus
separately. The expectation going forward would be thatsources
could be used with eitherstatus
orgenerates
to evaluate the status of the task.status
andgenerates
are still mutually exclusive.Where should the reviewer start?
The test is a little artificial in that it echos the value of the checksum rather than actually doing something with it - but it demonstrates how the feature could be used.
Has this been manually tested? How?
This is part of our private fork.