-
Notifications
You must be signed in to change notification settings - Fork 166
LG-7470 | Very crude start of background job [WIP] #7085
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| class IrsAttemptEventsBatchJob < ApplicationJob | ||
|
|
||
| require 'tempfile' | ||
|
|
||
| # copypasta | ||
| include JobHelpers::StaleJobHelper | ||
| queue_as :default | ||
| discard_on JobHelpers::StaleJobHelper::StaleJobError | ||
|
|
||
| # Get this to run at the early part of the hour | ||
|
|
||
| def perform(subject_timestamp) | ||
| puts 'Howdy, partner' | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Obviously this should not be merged; just an easy way to see when this runs. |
||
|
|
||
| # Probably want something more durable | ||
| # mktmpdir won't auto-delete if it's not called with a block: | ||
| # https://ruby-doc.org/stdlib-2.5.1/libdoc/tmpdir/rdoc/Dir.html | ||
| dir = Dir.mktmpdir(subject_timestamp.to_s) | ||
| file = File.new("#{dir}/#{Time.now.to_fs(:number)}", 'w') | ||
|
|
||
| events = IrsAttemptsApi::RedisClient.new.read_events(timestamp: subject_timestamp) | ||
| events.each do |event| | ||
| file.write event | ||
| end | ||
| file.close | ||
| file.path | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Commenting in case someone else ends up picking this up. Right now, this reads all the events for a given hour out of Redis, writes them to a temp file, and then returns the file path (but nothing is looking at the return value, except me in the console). This is not very useful. We want to figure out where to store this. We've discussed either S3 or Redis. With multiple servers behind a load balancer, and instances periodically recycled, we can't rely on saving the file locally. We also want to apply encryption and gzip on this. See the The other bit of work on this is, once all that's working, change the endpoint to return that file, wherever it's stored, rather than generating it on the fly. |
||
| end | ||
|
|
||
| private | ||
|
|
||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,8 @@ def write_event(event_key:, jwe:, timestamp:) | |
| def read_events(timestamp:) | ||
| key = key(timestamp) | ||
| redis_pool.with do |client| | ||
| # see client.hscan which refs https://redis.io/commands/scan/ | ||
| # but it's... a lil' bit weird. | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Arguably, this change would be the big win, in allowing us to read and write in batches rather than fetching everything into memory. Will need to play around with this.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think a good task for tomorrow is to write something quick to bulk-generate events. We're going to want something like that for generating a large sample file for the IRS as well. My gut feeling is that It is occurring to me tonight that we've talked about doing this "background processing" to fetch all the events, put them in a flat file, and then store that in Redis rather than S3. Is that actually saving us anything over what we have now? All the more reason to generate a ton of events and bang on this. |
||
| client.hgetall(key) | ||
| end | ||
| end | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.